class Codebreaker::Console

Attributes

game[R]

Public Class Methods

new(name, complexity) click to toggle source
# File lib/entities/console.rb, line 10
def initialize(name, complexity)
  @game = Game.new(name, complexity)
end

Public Instance Methods

play() click to toggle source
# File lib/entities/console.rb, line 14
def play
  phrase_before_guess
  user_guess = user_input('guess')
  if user_guess == COMMANDS[:hint]
    show_hint
  else
    check_game_answer @game.guess user_guess
  end
end

Private Instance Methods

check_game_answer(answer) click to toggle source
# File lib/entities/console.rb, line 26
def check_game_answer(answer)
  case answer
  when :win then phrase_win
  when :lose then phrase_lose
  else
    show answer
    play
  end
end
show_hint() click to toggle source
# File lib/entities/console.rb, line 36
def show_hint
  hint = @game.hint
  hint ? puts_hint(hint) : zero_hint
  play
end