Sha256: 47b31b7513c95bc8c13573bebedab097890c8e45ec98b613fbe9a59696f0f454

Contents?: true

Size: 607 Bytes

Versions: 3

Compression:

Stored size: 607 Bytes

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 = { available: difficulty[:attempts], used: 0 }
    @hints = { available: difficulty[:hints], used: 0 }
    @name = user.name
  end

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
codebreaker_kirill-0.2.9 lib/codebreaker_kirill/game.rb
codebreaker_kirill-0.2.8 lib/codebreaker_kirill/game.rb
codebreaker_kirill-0.2.7 lib/codebreaker_kirill/game.rb