class RubyTerminalGames::Hangman::Board
Constants
- PLACEHOLDER
Public Class Methods
new(width: nil, height: nil)
click to toggle source
Calls superclass method
RubyTerminalGames::Board::new
# File lib/ruby_terminal_games/hangman/board.rb, line 6 def initialize(width: nil, height: nil) super @height = 10 end
Public Instance Methods
print_world!(game)
click to toggle source
# File lib/ruby_terminal_games/hangman/board.rb, line 11 def print_world!(game) print_placeholders(game.word) print_wrong_guesses(game.wrong_guesses) print_exit_instruction end
Private Instance Methods
print_exit_instruction()
click to toggle source
# File lib/ruby_terminal_games/hangman/board.rb, line 33 def print_exit_instruction draw_border! text = "Press SHIFT+Q to exit" write(text, row: height + 1, col: cols - text.length) end
print_placeholders(word)
click to toggle source
# File lib/ruby_terminal_games/hangman/board.rb, line 19 def print_placeholders(word) word.guess_letters.each_with_index do |letter, index| output = letter ? letter.upcase : '' output = output.green if word.won? placeholder = PLACEHOLDER write(output, row: 4, col: (index * 2) + 4) write(placeholder, row: 5, col: (index * 2) + 4) end end
print_wrong_guesses(guesses)
click to toggle source
# File lib/ruby_terminal_games/hangman/board.rb, line 29 def print_wrong_guesses(guesses) write(guesses.join(', '), row: height - 2, col: 4) end