Class: DsaCodebreakerGame::Console
- Inherits:
-
Object
- Object
- DsaCodebreakerGame::Console
- Defined in:
- lib/dsa_codebreaker_game/console.rb
Instance Method Summary collapse
- #duplicatepatches ⇒ Object
- #exitmessage ⇒ Object
- #input(q = '') ⇒ Object
- #lost(code) ⇒ Object
- #printer(figured_out, clues, gamer) ⇒ Object
- #want_to_play_again? ⇒ Boolean
- #welcome(gamer) ⇒ Object
- #win ⇒ Object
Instance Method Details
#duplicatepatches ⇒ Object
35 36 37 |
# File 'lib/dsa_codebreaker_game/console.rb', line 35 def duplicatepatches puts "Hey, duplicate patches are not allowed and please re enter a new code patch." end |
#exitmessage ⇒ Object
31 32 33 |
# File 'lib/dsa_codebreaker_game/console.rb', line 31 def puts "Thanks for your game. See you soon!" end |
#input(q = '') ⇒ Object
20 21 22 23 24 |
# File 'lib/dsa_codebreaker_game/console.rb', line 20 def input(q='') str = 'Enter a sequence a 4 character sequence from ROYGBIV or 0 to exit > ' str = '> ' if q == "exit" Readline::readline str, true end |
#lost(code) ⇒ Object
39 40 41 |
# File 'lib/dsa_codebreaker_game/console.rb', line 39 def lost(code) puts "YOU LOOSE! The code was: #{code}" end |
#printer(figured_out, clues, gamer) ⇒ Object
26 27 28 29 |
# File 'lib/dsa_codebreaker_game/console.rb', line 26 def printer(figured_out, clues, gamer) puts "Lives: #{gamer.lives}" puts "Code: #{figured_out.join(' ')}, Guessed: #{gamer.guess.join(' ')}, Clue: #{clues}" end |
#want_to_play_again? ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dsa_codebreaker_game/console.rb', line 47 def want_to_play_again? print "Do you want to play again (Y/N)?" loop do i = input("exit") case i when "Y" return true when "N" return false else print "Sorry? (Y/N)" end end end |
#welcome(gamer) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/dsa_codebreaker_game/console.rb', line 6 def welcome(gamer) puts '' puts '***** Welcome in the Amazing DSA Codebreaker Game ****' puts '' puts 'This is a variation on the MasterMind game. You have to figure out all four colours in right sort for winning.' puts 'Colours: R, O, Y, G, B, I, V ---- Exit from the game if your input contains 0 (zero).' puts 'Only the first 4 characters will be analyzed.' puts 'Example guess: OYGB' puts "Let's start!" puts '' puts '-----------------------------------------------------------------------------' puts '' end |
#win ⇒ Object
43 44 45 |
# File 'lib/dsa_codebreaker_game/console.rb', line 43 def win puts "**** CONGRATULATION! YOU WIN! ****" end |