generated from DPI-WE/ruby-cli-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.rb
295 lines (262 loc) · 11.5 KB
/
game.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
class Game
attr_accessor :name, :answer, :over, :yes, :no
def initialize
@player_name = name
@player_answer = answer
@over = false
@yes_answer = yes
@no_answer = no
end
def rules
puts "Before we get started, shall I explain to you the rules of the game? (y = yes/n = no)"
@player_answer = gets.chomp
@yes_answer = ["y", "yes", "Yes", "yes!", "Yes!", "YES", "sure", "Sure"]
@no_answer = ["n", "no", "No", "no!", "No!", "NO"]
if @yes_answer.include?(@player_answer)
puts "Here are the rules:
Rule 1: Guess a word or name based on the question or randomly outputted string.
Rule 2: As you progress through the game the questions will get increasingly difficult and you will have less chances to try again.
Rule 3: If you exhaust your chances you lose the game.
Rule 4: If you complete all the levels you win the game.
Bonus rule: Have fun and enjoy! ;D"
elsif @no_answer.include?(@player_answer)
puts "Lets get started!"
else
puts "Let's get started; I guess..."
end
end
def game_over
puts "Sorry, #{@player_name} you lost the game."
puts "
_/_/_/ _/_/ _/ _/ _/_/_/_/ _/_/ _/ _/ _/_/_/_/ _/_/_/
_/ _/ _/ _/_/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/_/ _/_/_/_/ _/ _/ _/ _/_/_/ _/ _/ _/ _/ _/_/_/ _/_/_/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/_/_/ _/ _/ _/ _/ _/_/_/_/ _/_/ _/ _/_/_/_/ _/ _/
"
end
def play_again
puts "Would you like to play again?"
@player_answer = gets.chomp
@yes_answer
@no_answer
end
def winner
puts "#{@player_name} is a winner!"
puts "
▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄ ▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄
▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░░▌ ▐░▌▐░░▌ ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌
▐░▌ ▐░▌ ▀▀▀▀█░█▀▀▀▀ ▐░▌░▌ ▐░▌▐░▌░▌ ▐░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░▌
▐░▌ ▄ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌▐░▌
▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌
▐░▌ ▐░▌░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀█░█▀▀ ▐░▌
▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌ ▐░▌ ▀
▐░▌░▌ ▐░▐░▌ ▄▄▄▄█░█▄▄▄▄ ▐░▌ ▐░▐░▌▐░▌ ▐░▐░▌▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▐░▌ ▄
▐░░▌ ▐░░▌▐░░░░░░░░░░░▌▐░▌ ▐░░▌▐░▌ ▐░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌▐░▌
▀▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀ ▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀ "
end
def correct_lvl_one
puts "
_ _ _ _ _ __ _
| | | | ___ | || | ___ | | / /(_) _ _
| |_| | / _ | || | / _ | | |/ / _ _| |_ _| |_ _ _
| _ |/ /_| || || |/ /| | | / | |_ _|_ _|| |/ /
| | | || ,___/| || || |_/ / | || | | | | |_ | |_ | / /
|_| |_| |___/ |_||_| |___/ |_| |_||_| |___| |___|| /
/ /
.. .''.
c '. _,, .' '
, , ___ 7###. .' '
. `-' ''|####;#'. .##, .
, '####.##,######.
. ' ' '' ,####.
' '##'.
' .
__,,--.-- '
' '
.--|- && -'-'''-.._
| '& && '
__,- '& -'---.
'' , ;
. kk. -.-,_
-_ ''KK ;
''--,_ ,
''--,__ __,,--'
''--..,--'' Pr59"
puts "Correct! Nice work!"
end
def correct_lvl_two
puts "
/| .-. .;
_ / | .' ;' (_) .-. .;'
( / | . .-..' .-. .:' .-. _.; : .-. .; .-. .-. .-.
`/.__|_.': ; ; : .:' ; ;'; ;.;.-' :: ; : ; .;.-'
.:' / | `:::'`.`:::'-' .-:. .-.`;;' `._.' `:::'_;;_.-`:::'-'`;;;;'`:::'
(__.' `-' (_/ `;._.
#{@player_answer} is correct! "
end
def play
puts "Hello! Welcome to Alana's guessing game. What's your name?"
@player_name = gets.chomp.capitalize
puts "Hello #{@player_name}! It's very nice to meet you!"
rules
practice_question
end
def practice_question
puts "Question 1: Multiple Choice"
puts first_question = "What's my favorite color?"
puts "
a. pink
b. baby blue
c. off white
d. navy blue
"
word_one = ["a", "pink"]
@player_answer = gets.chomp
while @player_answer != word_one[0] && @player_answer != word_one[1]
puts "Incorrect! Try again."
@player_answer = gets.chomp
end
if @player_answer == word_one[0] || word_one[1]
puts "Correct!"
end
puts "On to the next question..."
puts "\n"
practice_question_two
end
def practice_question_two
puts second_question = "I'm thinking of a number between 1 and 10. Tell me, what number is that?"
number = rand(1..10)
while true
@player_answer = gets.chomp.to_i
if @player_answer < number
puts "Hmm... #{@player_answer} is too low. Try a bigger number."
elsif @player_answer > number
puts "Hmm... #{@player_answer} is too high. Try a smaller number."
else @player_answer == number
puts "Correct!"
break end
end
message
end
def message
puts "Doing good so far! That was just a warm up!"
puts "Let's play a game!"
puts "Let's play a game!"
# sleep(2)
puts "Let's play a game!"
# sleep(2)
puts "Level: 1 (multiple choice)"
level_one
end
def level_one
puts "What character's birthday is November 1st, 1974, wears a bow, and was born in London, England?"
puts "
a. Spongebob
b. Mickey Mouse
c. Hello Kitty
d. Minnie Mouse"
chance_count = 0
chances = 3
while chance_count != chances
@player_answer = gets.chomp
level_one_answer = ["c", "Hello Kitty", "hello kitty"]
if @player_answer != level_one_answer[0] && @player_answer != level_one_answer[1] && @player_answer != level_one_answer[2]
puts "Incorrect! Try again!"
chance_count += 1
if chance_count == chances
game_over
play_again
if @yes_answer.include?(@player_answer)
break
else
exit
end
end
elsif @player_answer == level_one_answer[0] || @player_answer == level_one_answer[1] || @player_answer == level_one_answer[2]
correct_lvl_one
message_two
break
end
end
end
def message_two
puts "\n"
puts "Are you ready for the next level?"
@yes_answer
@no_answer
@player_answer = gets.chomp
if @yes_answer.include?(@player_answer)
puts "Awesome! Let's get started!"
elsif @no_answer.include?(@player_answer)
puts "Are you sure?"
@player_answer = gets.chomp
if @yes_answer.include?(@player_answer)
exit
end
else
puts "Let's get started then..."
end
level_two
end
def level_two
puts "Level 2: Type the best answer!"
chance_count = 0
chances = 2
while chances != chance_count
puts "Who wrote the first computer program?"
@player_answer = gets.chomp
level_two_answer = "Ada Lovelace"
chance_count += 1
if @player_answer != level_two_answer
puts "Incorrect! Try again!"
if chance_count == chances
game_over
play_again
if @yes_answer.include?(@player_answer)
break
else
exit
end
end
elsif @player_answer == level_two_answer
correct_lvl_two
message_three
break
end
end
end
def message_three
puts "If you have made it this far, you've done quite well!"
puts "\n"
puts "Here is the last and final challenge..."
puts "\n"
level_three
end
def level_three
puts "Level 3: Advanced Guess the Word or Number"
puts "You only get one try this round! Good luck #{@player_name} ヾ(๑❛ ▿ ◠๑ )!"
puts "\n"
random_words = ["lovely", "pink", "ruby", "code"]
random_numbers = rand(1..10).to_s
words_and_numbers = "#{random_words.sample} #{random_numbers}"
puts "Random words and numbers:"
puts "The random words are #{random_words[0..2].join(", ")}, and #{random_words[3]}."
puts "The random numbers are from 1-10."
puts "\n"
puts "What word and number combination do you think will appear?"
@player_answer = gets.chomp
if @player_answer != words_and_numbers
puts "#{@player_answer} is incorrect! The word and number combination was #{words_and_numbers}"
game_over
else @player_answer == words_and_numbers
winner
puts "#{words_and_numbers}"
puts "#{@player_answer} is the correct word and number combination!" end
play_again
if @no_answer.include?(@player_answer)
exit
end
end
end