Class: Codebreaker::Console
- Inherits:
-
Object
- Object
- Codebreaker::Console
- Defined in:
- lib/codebreaker/console.rb
Instance Attribute Summary collapse
-
#game ⇒ Object
Returns the value of attribute game.
Instance Method Summary collapse
-
#initialize ⇒ Console
constructor
A new instance of Console.
- #play ⇒ Object
Constructor Details
#initialize ⇒ Console
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
#game ⇒ Object
Returns the value of attribute game.
3 4 5 |
# File 'lib/codebreaker/console.rb', line 3 def game @game end |
Instance Method Details
#play ⇒ Object
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 |