Sha256: 3dc2bc414be20b00174cd7e9f390cb7c8cb6e12944d17c55b5ba54bc780ad09d

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 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 = { 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

# game = Game.new(User.new("kirill"), { attempts: 5, hints: 1 })
# print game.respond_to_guess(game, "2211", [1,2,3,4])
# print game.respond_to_guess(game, "2222", [2,2,2,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])
# print game.respond_to_guess(game, "2222", [1,2,3,4])

Version data entries

1 entries across 1 versions & 1 rubygems

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