Sha256: 5b57dac1589a341de38f5b75eea0d4175a168883cb44a084bfc135767fe29459

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require_relative 'guess_handler'
require_relative 'user'

class Game
  include GuessHandler

  attr_reader :secret_code, :hint_counter, :attempts, :hints, :name

  def initialize(user, difficulty)
    @secret_code = (1..4).to_a.map { |_num| rand(1..6) }
    @hint_counter = 0
    @attempts = { all: difficulty[:attempts], used: 0 }
    @hints = { all: difficulty[:hints], used: 0 }
    @name = user.name
  end

  def give_a_hint
    return 0 if @hints[:available].zero?

    @hints[:all] -= 1
    @hints[:used] += 1
    @secret_code[@hints[:used]]
  end
end

game = Game.new(User.new("kirill"), { attempts: 10, hints: 2 })
print game.respond_to_guess(game, "2222", [1,2,3,4]) # +
print game.respond_to_guess(game, "2222", [2,2,2,4]) # +++
print game.respond_to_guess(game, "2211", [1,2,3,4]) # +-
print game.respond_to_guess(game, "2221", [1,2,3,2]) # +--
print game.respond_to_guess(game, "1212", [2,1,2,1]) # ----
print game.respond_to_guess(game, "6666", [1,1,1,1]) # []
print game.respond_to_guess(game, "6666", [6,6,6,6]) # win
print game.respond_to_guess(game, "1234", [5,3,6,3]) # -
print game.respond_to_guess(game, "5363", [1,2,3,4]) # -

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codebreaker_kirill-0.2.12 lib/codebreaker_kirill/game.rb