Sha256: 7a0463561fd7a5841b61e2867e947c775ae29587ce252b7f945e1639f50b59b7

Contents?: true

Size: 609 Bytes

Versions: 2

Compression:

Stored size: 609 Bytes

Contents

# frozen_string_literal: true

require_relative "guess_handler"
require_relative "user"

class Game
  include GuessHandler

  attr_reader :secret_code

  def initialize(user, difficulty)
    @secret_code = (1..4).to_a.map { |_num| rand(1..6) }
    @hint_array = @secret_code.map(&:clone)
    @attempts = difficulty[:attempts]
    @hints = {
      hints_available: difficulty[:hints],
      hints_used: 0
    }
    @name = user.name
  end

  def give_a_hint
    return @hints[:hints_available].zero ? 0 : @hint_array[0]
    @hint_array.shift
    @hints[:hints_available] -= 1
    @hints[:hints_used]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
codebreaker_kirill-0.2.3 lib/codebreaker_kirill/game.rb
codebreaker_kirill-0.2.2 lib/codebreaker_kirill/game.rb