Class: SvatokCodebreaker::GameMessage
- Inherits:
-
Object
- Object
- SvatokCodebreaker::GameMessage
- Defined in:
- lib/svatok_codebreaker/game_message.rb
Instance Method Summary collapse
- #about ⇒ Object
- #commands ⇒ Object
- #exit_game ⇒ Object
- #login ⇒ Object
- #lose(game_data) ⇒ Object
- #message_guess(guess) ⇒ Object
- #next_step(game_data) ⇒ Object
- #no_hint ⇒ Object
- #no_match ⇒ Object
- #not_available ⇒ Object
- #not_valid_answer ⇒ Object
- #restart_game ⇒ Object
- #saved ⇒ Object
- #show(method, game_data = nil) ⇒ Object
- #start ⇒ Object
- #win ⇒ Object
Instance Method Details
#about ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/svatok_codebreaker/game_message.rb', line 8 def about "\n--------------------CODEBREAKER--------------------\n" + "\nCodebreaker is a logic game in which a player" + "\ntries to break a secret code created by a computer. The" + "\ncode-maker, which will be played by the application were" + "\ngoing to write, creates a secret code of four numbers" + "\nbetween 1 and 6.\n" + "\nComputer creates a secret code of four numbers between 1" + "\nand 6. You get " + ATTEMPTS.to_s + " chances to break the code." + "\nIn each turn, you make a guess of four numbers. Computer" + "\nthen marks the guess with up to four + and - signs." + "\n A + indicates an exact match: one of the numbers in the guess" + "\nis the same as one of the numbers in the secret code and" + "\nin the same position." + "\n A - indicates a number match: one of the numbers in the guess" + "\nis the same as one of the numbers in the secret code but in a" + "\ndifferent position." + "\n At any time during a game, you can request a hint, at which" + "\npoint the system reveals one of the numbers in the" + "\nsecret code. After the game is won or lost, you can opt" + "\nto save information about the game.\n" + "\nDuring the game you can use the commands Exit, Restart," + "\nHint, Save." end |
#commands ⇒ Object
65 66 67 |
# File 'lib/svatok_codebreaker/game_message.rb', line 65 def commands 'You can Exit/Restart/Save. Enter the desired command:' end |
#exit_game ⇒ Object
69 70 71 |
# File 'lib/svatok_codebreaker/game_message.rb', line 69 def exit_game "\n----------Bye!----------" end |
#login ⇒ Object
33 34 35 |
# File 'lib/svatok_codebreaker/game_message.rb', line 33 def login "\nPlease, enter your name:" end |
#lose(game_data) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/svatok_codebreaker/game_message.rb', line 58 def lose(game_data) "\n" + (game_data[:marking_guess]) + "\n" + "----------Sorry, but you lose :(----------\n" + 'Secret code is ' + game_data[:secret_code] + "\n" + commands end |
#message_guess(guess) ⇒ Object
93 94 95 96 |
# File 'lib/svatok_codebreaker/game_message.rb', line 93 def (guess) return 'Sorry, but there is no match...' if guess == '' guess end |
#next_step(game_data) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/svatok_codebreaker/game_message.rb', line 45 def next_step(game_data) = "\n" + (game_data[:marking_guess]) + "\n" + 'You have ' + game_data[:attempts].to_s + " attempts.\n" + 'Enter a guess:' += '(You can use Hint)' if game_data[:hint] == 'not used' end |
#no_hint ⇒ Object
89 90 91 |
# File 'lib/svatok_codebreaker/game_message.rb', line 89 def no_hint "\nSorry, but you have used a hint." end |
#no_match ⇒ Object
85 86 87 |
# File 'lib/svatok_codebreaker/game_message.rb', line 85 def no_match "\nSorry, but there is no match..." end |
#not_available ⇒ Object
77 78 79 |
# File 'lib/svatok_codebreaker/game_message.rb', line 77 def not_available "\nSorry, but command is not available at the moment." end |
#not_valid_answer ⇒ Object
41 42 43 |
# File 'lib/svatok_codebreaker/game_message.rb', line 41 def not_valid_answer "\nYou entered is not valid answer. Enter the correct answer." end |
#restart_game ⇒ Object
73 74 75 |
# File 'lib/svatok_codebreaker/game_message.rb', line 73 def restart_game "\n----------Game restarted. Enter guess:----------" end |
#saved ⇒ Object
81 82 83 |
# File 'lib/svatok_codebreaker/game_message.rb', line 81 def saved "\n----------Score saved!---------" end |
#show(method, game_data = nil) ⇒ Object
3 4 5 6 |
# File 'lib/svatok_codebreaker/game_message.rb', line 3 def show(method, game_data = nil) return send(method) if game_data.nil? send(method, game_data) end |
#start ⇒ Object
37 38 39 |
# File 'lib/svatok_codebreaker/game_message.rb', line 37 def start "\n----------Game started. Enter guess:----------" end |
#win ⇒ Object
53 54 55 56 |
# File 'lib/svatok_codebreaker/game_message.rb', line 53 def win "\n" + "----------Congratulations! You win!----------\n" + commands end |