class Codebreaker::Entities::Game
Constants
- DIFFICULTIES
- DIGITS_COUNT
- RANGE
Attributes
attempts[R]
code[R]
hints[R]
Public Class Methods
new()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 25 def initialize @process = Processor.new end
Public Instance Methods
decrease_attempts!()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 44 def decrease_attempts! @attempts -= 1 end
generate(difficulty)
click to toggle source
# File lib/codebreaker/entities/game.rb, line 29 def generate(difficulty) @difficulty = difficulty @code = generate_secret_code @hints = @code.sample(difficulty[:hints]) @attempts = difficulty[:attempts] end
hints_spent?()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 60 def hints_spent? hints.empty? end
start_process(command)
click to toggle source
# File lib/codebreaker/entities/game.rb, line 36 def start_process(command) @process.secret_code_proc(code.join, command) end
take_a_hint!()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 64 def take_a_hint! hints.pop end
to_h(name)
click to toggle source
# File lib/codebreaker/entities/game.rb, line 48 def to_h(name) { name: name, difficulty: DIFFICULTIES.key(@difficulty), all_attempts: @difficulty[:attempts], all_hints: @difficulty[:hints], attempts_used: @difficulty[:attempts] - @attempts, hints_used: @difficulty[:hints] - @hints.length, date: Time.now } end
win?(guess)
click to toggle source
# File lib/codebreaker/entities/game.rb, line 40 def win?(guess) code.join == guess end
Private Instance Methods
generate_secret_code()
click to toggle source
# File lib/codebreaker/entities/game.rb, line 70 def generate_secret_code Array.new(DIGITS_COUNT) { rand(RANGE) } end