-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuessGame.py
345 lines (271 loc) · 11.8 KB
/
GuessGame.py
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#Guess Game - Krystler Cataniag
import os #for Clearing Windows CMD
import time #Add delays
import random #random value of hidden object during gameplay
global_difficulty = 0 #Game Difficulty. DO NOT MODIFY.
global_emoji = "0" #hidden item emoji based on difficulty. DO NOT MODIFY.
global_hdn_item = 0 #Value of hidden item to be accesible to other functions(def) DO NOT MODIFY
global_HP = 0 #Value of player Health will base on chosen difficulty. DO NOT MODIFY
global_score = 0 #Value of player Score for correct answers. DO NOT MODIFY
#declare and initialize the game pov or the answer key
global_game_pov = ""
global_game_pov_num = ""
#this function calculates and generates the difficulty and emojis
def game_engine():
#declaring the global to be access here in this function
global global_difficulty, global_emoji, global_hdn_item, global_HP, global_score, global_game_pov, global_game_pov_num
#Continiously run the guess game until no Health left
while global_HP != 0:
#Clear TERMINAL for WINDOWS
os.system("cls")
#declare and initialize seperate difficulty for easy understanding.
game_difficulty = global_difficulty
player_difficulty = global_difficulty
#Calculate player HP and generate heart Emoji
player_HP = global_HP
player_HP_emoji = "\U0001F496"
player_HP_pov = " "
z_loop = 1
while z_loop <= player_HP:
player_HP_pov = player_HP_pov + player_HP_emoji
z_loop+=1
#Generate the value of hidden emoji and prefixes
whitespace = " "
box = "\U0001F381"
global_hdn_item = random.randint(1, global_difficulty)
#Player point of view
#Item is hidden
#Generate the guess game boxes.
player_pov = " "
player_pov_boxnum = " "
x_loop = 1
while x_loop <= player_difficulty:
player_pov = player_pov + box + whitespace
player_pov_boxnum = player_pov_boxnum + " "+str(x_loop) + whitespace
x_loop+=1
#Game point of view
#item is visible
#Generate the guess game boxes with showned hidden emoji.
global_game_pov = " "
global_game_pov_num = " "
itemCheck = ""
y_loop = 1
while y_loop <= game_difficulty:
#match the loop with the current random value of hidden object.
#this is to match the number of emoji when displayed.
if y_loop == global_hdn_item:
itemCheck = global_emoji #the hidden emoji
else:
itemCheck = "\U0001F381" #box emoji
global_game_pov = global_game_pov + itemCheck + whitespace
global_game_pov_num = global_game_pov_num + " "+str(y_loop) + whitespace
y_loop+=1
#Display the SCORE, HEALTH
print("")
print(" Score: "+str(global_score))
print(player_HP_pov +" | "+ str(player_HP) +" Health Left")
#Display the player's point of view(the emoji is hiding)
print("")
print(player_pov)
print(player_pov_boxnum)
print("")
#THIS IS FOR DEBUG PURPOSE
#Allows you to see the answer/emoji during the guess process
#print("")
#print(global_game_pov)
#print(global_game_pov_num)
#print("")
#Ask for user input
user_answer()
#this function tells the result of the user's guessed number
def result(asnwered):
#declaring the global to be access here in this function
global global_difficulty, global_hdn_item, global_HP, global_score, global_game_pov, global_game_pov_num
#Clear TERMINAL for WINDOWS
os.system("cls")
#Check if user answer is correct
if global_hdn_item == asnwered:
#add the score
global_score+=1
#display the answer or show the hidden emoji
print("")
print("")
print("")
print("")
print(global_game_pov)
print(global_game_pov_num)
print("")
#add HEALTH when correctly gueesing the emoji 2 times.
if global_score % 2 == 0:
global_HP+=1
print(" +1 \U0001F496 | Correct \U00002705 | Score: "+str(global_score))
print("")
#display to user that the answer is correct
else:
print(" Correct \U00002705 | Score: "+str(global_score))
print("")
#wait for 3 seconds to loop again. back to guessing new boxes.
time.sleep(3)
#check if user answer is incorrect
elif global_hdn_item != asnwered:
#deduct player HEALTH
global_HP-=1
#display answer or emoji and the result of user answer
print("")
print("")
print("")
print("")
print(global_game_pov)
print(global_game_pov_num)
print("")
print(" -1 \U0001F494 | Incorrect \U0000274C | Score: "+str(global_score))
print("")
#display end game if player HP is ZERO(0)
if global_HP == 0:
print(" Guess what?")
print(" You're out of \U0001F494 Health")
print("")
#wait for 3 seconds to loop again. back to guessing new boxes.
time.sleep(3)
#this function ask for user's answer
def user_answer():
#get the global value
global global_difficulty
#loop value to loop it again untill correct user input
u_answercheck = 0
#start of looping for correct input only.
while u_answercheck == 0:
#ask for user input
print("Select box from 1 to "+str(global_difficulty))
guess_Answer = input("Which box you want to guess? Select: ")
#catch error when inputed answer is not valid or out of range.
try:
#convert to int, because we onl accept number for user input.
guess_AnswerCheck = int(guess_Answer)
#if user answer is a number and within the given box range.
if guess_AnswerCheck <= global_difficulty:
u_answercheck = 1 #this hould stop the loop
result(guess_AnswerCheck) #Go to result function with parameter of the users answer
else:
#continue to loop if given boxes is out of range
u_answercheck = 0
except:
#if there is an error converting to int or other error, this should catch it and continue the game.
u_answercheck = 0
print("")
print("Plese enter numbers only based boxes.")
time.sleep(2)
def game_start():
global global_emoji, global_HP
#Clear TERMINAL for WINDOWS
os.system("cls")
print("")
print(" Find and Guess where this emoji hides "+global_emoji)
print(" you only have "+str(global_HP)+ "\U0001F496 (Health) to try.")
print(" +1 \U0001F496 after 2x correctly guessing the emoji.")
time.sleep(3)
countdown = 3
while countdown <= 4:
#Clear TERMINAL for WINDOWS
os.system("cls")
print("")
print(" Find and Guess where this emoji hides "+global_emoji)
print(" you only have "+str(global_HP)+ "\U0001F496 (Health) to try.")
print(" +1 \U0001F496 after 2x correctly guessing the emoji.")
print(" Game Start in ",countdown,"...")
time.sleep(1)
countdown-=1
#Clear TERMINAL for WINDOWS
os.system("cls")
if countdown == 0:
game_engine()
break
#this function is for main menu, ask for difficulty selection
def menu():
#declare and initialize the loop value.
menuCheck = 0
#global variable to be use based b all functions(difficulty, emoji , HP)
global global_difficulty, global_emoji, global_HP
#start looping until the user input is correct and valid
while menuCheck == 0:
#Clear TERMINAL for WINDOWS
os.system("cls")
#display difficulty selection
print("")
print(" \U0001F381 GUESS GAME \U0001F381 ")
print(" Krystler Cataniag ")
print("")
print(" (1) \U0001F476 Easy")
print(" (2) \U0001F468 Average")
print(" (3) \U0001F9B8 Hard")
print("")
menu_Select = input("Select Difficulty: ")
#This will catch user's incorrect input or invalid input
try:
#convert to int, the game expect a number
menuSelectCheck = int(menu_Select)
#if user inputed number is 1 or easy
if menuSelectCheck == 1:
menuCheck = 1 #this should stop the loop
#Clear TERMINAL for WINDOWS
os.system("cls")
#remind what the user selected
print("")
print(" You've Selected")
print(" \U0001F476 Easy")
print("")
time.sleep(2) #wait for 2 secs
#add value to global variables
global_difficulty = 2 #2 boxes
global_emoji = "\U0001F476" #the hidden emoji
global_HP = 10 #player Health
#start initializing the game
game_start()
#if user inputed number is 2 or average
elif menuSelectCheck == 2:
menuCheck = 1 #this should stop the loop
#Clear TERMINAL for WINDOWS
os.system("cls")
#remind what the user selected
print("")
print(" You've Selected")
print(" \U0001F468 Average")
print("")
time.sleep(2) #wait for 2 secs
#add value to global variables
global_difficulty = 3 #3 boxes
global_emoji = "\U0001F468" #the hidden emoji
global_HP = 5 #player HP
#start initializing the game
game_start()
#if user inputed number is 3 or hard
elif menuSelectCheck == 3:
menuCheck = 1 #this should stop the loop
#Clear TERMINAL for WINDOWS
os.system("cls")
#remind what the user selected
print("")
print(" You've Selected")
print(" \U0001F9B8 Hard")
print("")
time.sleep(2) #wait for 2 secs
#add value to global variables
global_difficulty = 4 #3 boxes
global_emoji = "\U0001F9B8" #the hidden emoji
global_HP = 3 #player HP
#start initializing the game
game_start()
else:
#continue to run the loop until the inputed number when out of range
menuCheck = 0
print("")
print("Plese enter numbers only based on difficulty.")
time.sleep(2)
except:
#continue to ask difficulty until the user enter correct value.
menuCheck = 0
print("")
print("Plese enter numbers only based on difficulty.")
time.sleep(2)
#run the whole code or this project
menu()