Class: RubyTerminalGames::Hangman::Game
- Inherits:
-
Object
- Object
- RubyTerminalGames::Hangman::Game
- Defined in:
- lib/ruby_terminal_games/hangman/game.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#guess_total ⇒ Object
readonly
Returns the value of attribute guess_total.
-
#input_index ⇒ Object
readonly
Returns the value of attribute input_index.
-
#word ⇒ Object
readonly
Returns the value of attribute word.
-
#wrong_guesses ⇒ Object
readonly
Returns the value of attribute wrong_guesses.
Instance Method Summary collapse
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #play! ⇒ Object
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
10 11 12 13 14 |
# File 'lib/ruby_terminal_games/hangman/game.rb', line 10 def initialize @word = Word.new @board = Board.new @wrong_guesses = [] end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
7 8 9 |
# File 'lib/ruby_terminal_games/hangman/game.rb', line 7 def board @board end |
#guess_total ⇒ Object (readonly)
Returns the value of attribute guess_total.
7 8 9 |
# File 'lib/ruby_terminal_games/hangman/game.rb', line 7 def guess_total @guess_total end |
#input_index ⇒ Object (readonly)
Returns the value of attribute input_index.
7 8 9 |
# File 'lib/ruby_terminal_games/hangman/game.rb', line 7 def input_index @input_index end |
#word ⇒ Object (readonly)
Returns the value of attribute word.
7 8 9 |
# File 'lib/ruby_terminal_games/hangman/game.rb', line 7 def word @word end |
#wrong_guesses ⇒ Object (readonly)
Returns the value of attribute wrong_guesses.
7 8 9 |
# File 'lib/ruby_terminal_games/hangman/game.rb', line 7 def wrong_guesses @wrong_guesses end |
Instance Method Details
#play! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_terminal_games/hangman/game.rb', line 16 def play! = true Keyboard.capture(detect_direction: true) do |key| begin = false if key =~ /Q/ next unless allowed_key?(key) guess(key) rescue = false Keyboard.stop_capture! end end while board.print_world!(self) game_interval! end end |