Module: Display

Defined in:
lib/display.rb

Overview

Module to display all in game text.

Class Method Summary collapse

Class Method Details

.beginning_of_guess_round(guess_logic) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/display.rb', line 61

def self.beginning_of_guess_round(guess_logic)
  puts <<~MSG
    #{gallows(guess_logic)}
    #{word_to_guess(guess_logic)}
    Wrong letters: #{guess_logic.incorrect_letters.join(', ')}
    Incorrect guesses: #{guess_logic.incorrect_guesses}\n\n
    Make your guess:
  MSG
end

.defeat(word_to_guess) ⇒ Object



80
81
82
83
84
# File 'lib/display.rb', line 80

def self.defeat(word_to_guess)
  puts Gallows.finish
  puts "\n Sorry, you lose!"
  puts "\n The word was #{word_to_guess.word.upcase}\n\n"
end

.end_of_guess_round(guess_logic) ⇒ Object



71
72
73
# File 'lib/display.rb', line 71

def self.end_of_guess_round(guess_logic)
  puts guess_logic.messages.pop.to_s
end

.enter_nameObject



33
34
35
# File 'lib/display.rb', line 33

def self.enter_name
  puts 'Enter your name: '
end

.gallows(guess_logic) ⇒ Object



57
58
59
# File 'lib/display.rb', line 57

def self.gallows(guess_logic)
  puts Gallows::GALLOWS[guess_logic.incorrect_guesses]
end

.instruction_introObject



11
12
13
14
# File 'lib/display.rb', line 11

def self.instruction_intro
  puts "If you'd like instructions enter 'i'."
  puts 'Otherwise press return to continue.'
end

.instructionsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/display.rb', line 16

def self.instructions
  puts <<-MSG
Reveal the hidden word before your man is hung.

You may guess a single letter at a time. 
A correct guess will result in that letter being filled in.
Incorrect guesses will result in a part of the stick man being drawn.
You have 6 incorrect guesses to play with to save your man.
You may also guess the whole word at any time. But be careful; an incorrect guess is game over.

The game is auto saved after each round. 
Use the load function at game start to load a previously saved game.
Enter 'quit game' at any time to end session.

  MSG
end

.leaveObject



41
42
43
# File 'lib/display.rb', line 41

def self.leave
  puts 'Okay, bye.'
end

.load_gameObject



86
87
88
89
# File 'lib/display.rb', line 86

def self.load_game
  puts "Enter 'load' to load previously saved game."
  puts 'Or press return to start a new game.'
end

.play_againObject



37
38
39
# File 'lib/display.rb', line 37

def self.play_again
  puts "Would you like to play again? Enter 'yes' or 'no': "
end

.thank_player(player) ⇒ Object



49
50
51
# File 'lib/display.rb', line 49

def self.thank_player(player)
  puts "Thanks #{player.name}"
end

.validation_errors(errors) ⇒ Object



45
46
47
# File 'lib/display.rb', line 45

def self.validation_errors(errors)
  puts errors.join(', ') unless errors.empty?
end

.victory(word_to_guess) ⇒ Object



75
76
77
78
# File 'lib/display.rb', line 75

def self.victory(word_to_guess)
  puts "\n Yes! The word was #{word_to_guess.word.upcase}."
  puts "\n  You win!\n\n"
end

.welcome_messageObject



7
8
9
# File 'lib/display.rb', line 7

def self.welcome_message
  puts "Welcome to Hangman.\n\n"
end

.word_to_guess(guess_logic) ⇒ Object



53
54
55
# File 'lib/display.rb', line 53

def self.word_to_guess(guess_logic)
  puts " Word to guess: #{guess_logic.guessed_word}"
end