Class: Codebreaker::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/codebreaker/console.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConsole

Returns a new instance of Console.



5
6
7
# File 'lib/codebreaker/console.rb', line 5

def initialize
  @game = Game.new
end

Instance Attribute Details

#gameObject

Returns the value of attribute game.



3
4
5
# File 'lib/codebreaker/console.rb', line 3

def game
  @game
end

Instance Method Details

#playObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/codebreaker/console.rb', line 9

def play
  intro
  until game.completed?
    case answ = get_answer
      when /^[1-6]{4}/ then game.mark_user_code(answ)
      when /^[Hh]{1}/ then game.show_hint
      else puts 'You entered wrong value, pal. Try again'
    end
  end
  puts game.won? ? 'Great job! You guessed secret code!' : 'Oh, you exceed the number of available attempts'
  save_result_request
  play_again_request
end