class Game

Constants

DIFFICULTIES
DIGITS_COUNT
RANGE

Attributes

attempts[R]
code[R]
hints[R]

Public Class Methods

new() click to toggle source
# File lib/app/entities/game.rb, line 23
def initialize
  @process = Processor.new
end

Public Instance Methods

decrease_attempts!() click to toggle source
# File lib/app/entities/game.rb, line 42
def decrease_attempts!
  @attempts -= 1
end
generate(difficulty) click to toggle source
# File lib/app/entities/game.rb, line 27
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/app/entities/game.rb, line 57
def hints_spent?
  hints.empty?
end
start_process(command) click to toggle source
# File lib/app/entities/game.rb, line 34
def start_process(command)
  @process.secret_code_proc(code.join, command)
end
take_a_hint!() click to toggle source
# File lib/app/entities/game.rb, line 61
def take_a_hint!
  hints.pop
end
to_h(name) click to toggle source
# File lib/app/entities/game.rb, line 46
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
  }
end
win?(guess) click to toggle source
# File lib/app/entities/game.rb, line 38
def win?(guess)
  code.join == guess
end

Private Instance Methods

generate_secret_code() click to toggle source
# File lib/app/entities/game.rb, line 67
def generate_secret_code
  Array.new(DIGITS_COUNT) { rand(RANGE) }
end