-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpet_simulator.py
More file actions
702 lines (580 loc) · 23.1 KB
/
Copy pathpet_simulator.py
File metadata and controls
702 lines (580 loc) · 23.1 KB
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
from colorama import Fore, Style, init
import random, time, pygame, json, os
leaderboard_file = "leaderboard.json"
init()
# Leaderboard function
def load_leaderboard():
if not os.path.exists(leaderboard_file):
return []
with open(leaderboard_file, "r") as file:
leaderboard = json.load(file)
return leaderboard
def save_leaderboard(leaderboard):
with open(leaderboard_file, "w") as file:
json.dump(leaderboard, file, indent=4)
def add_to_leaderboard(pet):
leaderboard = load_leaderboard()
player = {
"name": pet.name,
"level": pet.level,
"health": pet.health,
"doggy_coins": pet.doggy_coins
}
leaderboard.append(player)
save_leaderboard(leaderboard)
def show_leaderboard():
leaderboard = load_leaderboard()
leaderboard.sort(key=lambda player: player["level"], reverse=True)
print("\n========== LEADERBOARD ==========")
for position, player in enumerate(leaderboard, start=1):
print(
f"{position}. {player['name']} "
f"| Level: {player['level']} "
f"| Health: {player['health']} "
f"| Coins: {player['doggy_coins']}"
)
print("=================================\n")
class Pet():
def __init__(self):
self.name = input("Enter your pet's name: ")
self.hunger = 50
self.happiness = 50
self.energy = 50
self.state = "happy" # "Happy", "Neutral", "Tired"
self.energy_change = 0
self.hunger_change = 0 # goes up 5 every 5 seconds
self.happiness_change = 0
self.played = 0
self.fed = 0
self.named = 0
self.slept = 0
self.age = 0
self.health = 0 # increases during all actions
self.level = 0 # level goes up when two of each action is performed
self.health_change = 0
self.level_change = 0
self.start_time = 0
self.food = 15
self.doggy_coins = 0
self.doggy_coins_change = 0
self.food_choice = "" # "cheap", "moderate", "expensive"
self.can_feed = None
self.achievements = []
self.all_achievements = ["Mega Eater", "Play Master", "Top Dog", "New Name, Who Dis?", "First Play", "Rich Dog", "First Savings", "Starving Dog"]
self.dead = False
self.games = []
self.played = 0
def choices(self):
print("\n")
print("----- Choices -----")
print(Fore.RED + f"Feed: {self.fed}" + Style.RESET_ALL)
print(Fore.YELLOW + f"Play: {self.played}" + Style.RESET_ALL)
print(Fore.CYAN + f"Sleep: {self.slept}" + Style.RESET_ALL)
print(Fore.GREEN + f"Rename: {self.named}" + Style.RESET_ALL) # rename option
print(Fore.BLUE + f"Mini Games: {self.played}" + Style.RESET_ALL)
print(f"Total Commands: {self.fed + self.played + self.slept}")
print("-------------------")
def update_state(self):
# Critical conditions
if self.hunger >= 80:
self.state = "sad"
elif self.energy <= 20:
self.state = "sad"
elif self.happiness <= 20:
self.state = "sad"
elif self.named >= 2:
self.state = "sad"
# Really happy
elif self.happiness >= 70 and self.energy >= 50 and self.hunger <= 40:
self.state = "happy"
# Everything else
else:
self.state = "neutral"
elapsed = pygame.time.get_ticks() - self.start_time
duration_ms = 5000 # 5 seconds
if elapsed < duration_ms:
self.hunger += 5
self.hunger_change += 5
def update_level(self):
total_actions = self.fed + self.played + self.slept
new_level = total_actions // 6
if new_level > self.level:
self.level_change = new_level - self.level
self.level = new_level
print(f"{self.name} has leveled up to level {self.level}!")
else:
self.level_change = 0
def update_achievements(self):
if self.fed == 10 and "Mega Eater" not in self.achievements:
print("You unlocked the Mega Eater achievement!")
self.achievements.append("Mega Eater")
if self.hunger == 80 and "Starving Dog" not in self.achievements:
print("You unlocked the Starving Dog achievement!")
self.achievements.append("Starving Dog")
if self.doggy_coins == 10 and "First Savings" not in self.achievements:
print("You unlocked the First Savings achievement!")
self.achievements.append("First Savings")
if self.doggy_coins == 100 and "Rich Dog" not in self.achievements:
print("You unlocked the Rich Dog achievement!")
self.achievements.append("Rich Dog")
if self.played == 1 and "First Play" not in self.achievements:
print("You unlocked the First Play achievement!")
self.achievements.append("First Play")
if self.played == 10 and "Play Master" not in self.achievements:
print("You unlocked the Play Master achievement!")
self.achievements.append("Play Master")
if self.level == 5 and "Top Dog" not in self.achievements:
print("You unlocked the Top Dog achievement!")
self.achievements.append("Top Dog")
if self.named == 1 and "New Name" not in self.achievements:
print("You unlocked the 'New Name, Who Dis?' achievement!")
self.achievements.append("New Name, Who Dis?")
def view_achievements(self):
print("=======================")
print("Achievements:")
for achievement in self.all_achievements:
if achievement in self.achievements:
print(f"- {achievement}")
else:
print("- ???")
print("=======================")
def status(self):
self.update_state()
print(f"---- {self.name} ----")
if self.state == "happy":
print(" / \\__")
print("( ^\\___")
print(" / O")
print("/ (_____/")
print("/_____/ U")
if self.state == "neutral":
print(" / \\__")
print("( -\\___")
print(" / O")
print("/ (_____/")
print("/_____/ U")
if self.state == "sad":
print(" / \\__")
print("( v\\___")
print(" / o")
print("/ (_____/")
print("/_____/ U")
# health status
print(Fore.GREEN + f"Health: {self.health} (+{self.health_change})" + Style.RESET_ALL)
print(Fore.BLUE + f"Level: {self.level} (+{self.level_change})" + Style.RESET_ALL)
print(Fore.LIGHTBLUE_EX + f"Doggy Coins: {self.doggy_coins} (+{self.doggy_coins_change})" + Style.RESET_ALL)
if self.hunger_change < 0:
print(Fore.RED + f"Hunger: {self.hunger} ({self.hunger_change})" + Style.RESET_ALL)
else:
print(Fore.RED + f"Hunger: {self.hunger} (+{self.hunger_change})" + Style.RESET_ALL)
if self.happiness_change < 0:
print(Fore.YELLOW + f"Happiness: {self.happiness} ({self.happiness_change})" + Style.RESET_ALL)
else:
print(Fore.YELLOW + f"Happiness: {self.happiness} (+{self.happiness_change})" + Style.RESET_ALL)
if self.energy_change < 0:
print(Fore.CYAN + f"Energy: {self.energy} ({self.energy_change})" + Style.RESET_ALL)
else:
print(Fore.CYAN + f"Energy: {self.energy} (+{self.energy_change})" + Style.RESET_ALL)
print("-----------------")
def mini_games(self):
self.played += 1
print("Welcome to the Mini Games Menu!")
time.sleep(0.5)
print("You can win rewards for your pet!")
games = ["Number Guesser", "Memory Match", "Pet Trivia", "Reaction Test"]
game = input(f"Which game do you want to play? \n 1. {games[0]} \n 2. {games[1]} \n 3. {games[2]} \n 4. {games[3]} \n< ")
if game == "1":
self.number_guesser()
elif game == "2":
self.memory_match()
elif game == "3":
self.pet_trivia()
elif game == "4":
self.reaction_test()
def number_guesser(self):
print("Welcome to the Number Guesser game!")
time.sleep(0.5)
print("You have 5 attempts to guess the number between 1 and 25.")
number = random.randint(1, 25)
#print(f"number: {number}")
attempts = 0
while True:
if attempts == 5:
print("You've run out of attempts!")
time.sleep(0.5)
print(f"The number was {number}")
break
else:
choice = int(input("Guess a number\n < "))
if choice == number:
attempts += 1
print("Correct!")
time.sleep(0.5)
print(f"You guessed the number in {attempts} attempts!")
time.sleep(0.5)
print("You win 10 doggy coins!")
self.doggy_coins += 10
print(f"Total Doggy Coins: {self.doggy_coins}")
break
else:
if choice < number:
attempts += 1
print("Too low!")
elif choice > number:
attempts += 1
print("Too high!")
def reaction_test(self):
print("Welcome to the Reaction Test game!")
time.sleep(0.5)
print("When you see 'GO!', press Enter as fast as possible.")
time.sleep(1)
print("Press Enter when you are ready...")
time.sleep(1)
wait_time = random.uniform(2, 6)
time.sleep(wait_time)
print("\n GO!")
start_time = time.time()
input()
end_time = time.time()
reaction_time = end_time - start_time
print(f"Your reaction time: {reaction_time:.2f} seconds")
if reaction_time < 0.25:
coins = 30
print("INCREDIBLE REACTION TIME!")
elif reaction_time < 0.4:
coins = 20
print("Great reaction time!")
elif reaction_time < 0.6:
coins = 10
print("Good reaction time!")
else:
coins = 5
print("Keep practicing!")
self.doggy_coins += coins
self.doggy_coins_change = coins
print(f"You won {coins} Doggy Coins!")
print(f"Total Doggy Coins: {self.doggy_coins}")
def clear_screen(self):
print("\n" * 200)
def memory_match(self):
attempts = 0
round = 1
time_limit = 5
points = 0
points_gained = 0
def check_score():
nonlocal points, points_gained
if round == 1:
for word in words_found:
if word == "dog" or word == "cat" or word == "bone":
points += 1
points_gained += 1
if round == 2:
for word in words_found:
if word == "puppy" or word == "fetch" or word == "play":
points += 1
points_gained += 1
if round == 3:
for word in words_found:
if word == "meow" or word == "purr" or word == "collar":
points += 1
points_gained += 1
time.sleep(0.5)
if points_gained == 1:
print(f"You got {points_gained} point!")
else:
print(f"You got {points_gained} points!")
points_gained = 0
if round == 1:
print("Find three words related to pets in 5 seconds.")
time.sleep(2)
print("Type Enter to start")
ready = input("< ")
if ready == "":
print("D O G X B")
print("Q W E R O")
print("A C A T ")
print("E B O N E")
print("U R Y E")
timer = time.time()
while True:
time.sleep(0.01)
time_elapsed = time.time() - timer
if time_elapsed >= time_limit:
self.clear_screen()
print("Time's up!")
words_found = input("Enter the words you spotted (word1 word2 word3) : \n < ").lower().split()
check_score()
round = 2
break
if round == 2:
time_limit = 3
print("Round 2: Find three words related to pets in 3 seconds.")
time.sleep(1)
print("Type Enter to start")
ready = input("< ")
if ready == "":
print("R U E X B D V")
print("H P U P P Y I")
print("U H F P L A Y")
print("G B F E T C H")
timer = time.time()
while True:
time.sleep(0.01)
time_elapsed = time.time() - timer
if time_elapsed >= time_limit:
self.clear_screen()
print("Time is up!")
words_found = input("Enter the words you spotted (word1 word2 word3) : \n < ").lower().split()
check_score()
round = 3
break
if round == 3:
time_limit = 2
print("Round 3: Find three words related to pets in 2 seconds.")
time.sleep(1)
print("Type Enter to start")
ready = input("< ")
if ready == "":
print("Y E M E O W R T")
print("A V P U R R V B")
print("Y X C O L L A R")
print("H Y V E B L L O")
timer = time.time()
while True:
time.sleep(0.01)
time_elapsed = time.time() - timer
if time_elapsed >= time_limit:
self.clear_screen()
print("Time is up!")
words_found = input("Enter the words you spotted (word1 word2 word3) : \n < ").lower().split()
check_score()
round = "end"
break
if round == "end":
time.sleep(1)
print("Game Over!")
time.sleep(0.5)
print(f"You won {points * 10} doggy coins!")
def pet_trivia(self):
question_amount = 3
points = 0
print("Welcome to Pet Trivia!")
time.sleep(0.5)
print(f"You have {question_amount} questions.")
time.sleep(0.5)
print("Answer questions correctly to win doggy coins!")
while True:
question = input("Which animal is known as man's best friend? \n < ")
answer = "Dog"
if question == "dog" or question == "Dog":
time.sleep(0.5)
print("Correct!")
points += 1
else:
time.sleep(0.5)
print(f"Wrong answer. The correct answer was {answer}")
question2 = input("Which pet is owned by more U.S. households: dogs or cats? \n < ")
answer = "Dog"
if question2 == "dogs" or question2 == "Dogs":
time.sleep(0.5)
print("Correct!")
points += 1
else:
time.sleep(0.5)
print(f"Wrong answer. The correct answer was {answer}")
question3 = input("According to a 2023 Pew survey, what percentage of U.S. adults owned a pet? \n A. 62% \n B. 49% \n C. 81% \n < ")
answer = "A, or 62%"
if question3 == "a" or question3 == "A" or question3 == "62%":
time.sleep(0.5)
print("Correct!")
points += 1
break
else:
time.sleep(0.5)
print(f"Wrong answer. The correct answer was {answer}")
break
print(f"You got {points} points!")
time.sleep(0.5)
print(f"You win {points * 10} doggy coins!")
time.sleep(0.5)
self.doggy_coins += points * 10
print(f"Total Doggy Coins: {self.doggy_coins}")
def shop(self):
print("Select an item to buy (1/2/3):")
time.sleep(0.5)
print("1. Happy Pup Chow - 5 doggy coins")
print("2. Nature's Bowl - 10 doggy coins")
print("3. Heritage Hound Reserve - 15 doggy coins")
choice = input("\n < ")
if choice == "1":
if self.doggy_coins < 5:
print("You don't have enough doggy coins!")
else:
self.doggy_coins -= 5
self.food += 10
print(f"You bought Happy Pup Chow for {self.name}!")
self.food_choice = "cheap"
self.can_feed = True
elif choice == "2":
if self.doggy_coins < 10:
print("You don't have enough doggy coins!")
else:
self.doggy_coins -= 10
self.food += 10
print(f"You bought Nature's Bowl for {self.name}!")
self.food_choice = "moderate"
self.can_feed = True
elif choice == "3":
if self.doggy_coins < 15:
print("You don't have enough doggy coins!")
else:
self.doggy_coins -= 15
self.food += 10
print(f"You bought Heritage Hound Reserve for {self.name}!")
self.food_choice = "expensive"
self.can_feed = True
def feed(self):
self.doggy_coins += 5
self.doggy_coins_change = 5
time.sleep(1)
if self.food < 5:
print("You don't have enough food!")
choice = input("Do you want to buy more food at the shop? (yes/no) \n < ")
if choice == "yes" or choice == "Yes":
self.shop()
else:
print(f"Sorry, you cannot feed {self.name}...")
self.can_feed = False
else:
self.can_feed = True
if self.can_feed == True:
self.food -= 5
self.fed += 1
print(Fore.GREEN + f"You fed {self.name}!" + Style.RESET_ALL)
time.sleep(1)
if self.food_choice == "cheap":
chance = random.randint(1, 3)
elif self.food_choice == "moderate":
chance = random.randint(1, 6)
elif self.food_choice == "expensive":
chance = random.randint(1, 10)
else:
chance = random.randint(1, 8)
if chance == 2:
print("Your pet has stomach pain!")
self.hunger += 10
self.energy -= 20
self.happiness -= 20
self.health += 10
self.hunger_change = 10
self.happiness_change = -20
self.energy_change = -20
self.health_change = 10
else:
print(Fore.GREEN + f"{self.name} is more happy and healthy!" + Style.RESET_ALL)
self.hunger -= 20
self.energy += 10
self.happiness += 10
self.health += 10
self.hunger_change = -10
self.health_change = 10
self.energy_change = 10
self.happiness_change = 10
def sleep(self):
self.doggy_coins += 5
self.doggy_coins_change = 5
time.sleep(1)
self.slept += 1
print(Fore.GREEN + f"You let {self.name} sleep!" + Style.RESET_ALL)
self.hunger += 20
self.energy += 20
self.happiness += 10
self.health += 10
self.hunger_change = 20
self.health_change = 10
self.happiness_change = 10
self.energy_change = 20
def play(self):
self.doggy_coins += 5
self.doggy_coins_change = 5
time.sleep(1)
self.played += 1
print(f"You played with {self.name}!")
time.sleep(1)
chance = random.randint(1, 4)
if chance == 3:
time.sleep(1)
print(f"{self.name} got hurt when playing!")
self.hunger += 10
self.happiness -= 10
self.energy -= 10
self.hunger_change = 10
self.happiness_change = -10
self.energy_change = -10
else:
time.sleep(1)
print(f"{self.name} is happy!")
self.hunger += 10
self.happiness += 10
self.energy -= 10
self.hunger_change = 10
self.happiness_change = 10
self.energy_change = -10
def rename(self):
self.doggy_coins += 5
self.doggy_coins_change = 5
self.named += 1
self.name = input("Enter your pet's new name: ")
print(f"You renamed {self.name}!")
time.sleep(1)
def game():
global choice
print(Fore.BLUE + "Welcome to the Pet Simulator Game!" + Style.RESET_ALL)
time.sleep(1) # Wait for 1 second
print("Your new pet awaits you...")
print("Be careful, being a pet owner is not an easy job...")
time.sleep(1)
pet = Pet()
pet.status()
while True:
print("What would you like to do for your pet? (feed, sleep, play, rename, view achievements, mini games)")
print("Enter your choice (f, s, p, r, v, m)")
choice = input("< ")
if choice == "feed" or choice == "Feed" or choice == "f":
pet.feed()
elif choice == "sleep" or choice == "Sleep" or choice == "s":
pet.sleep()
elif choice == "play" or choice == "Play" or choice == "p":
pet.play()
elif choice == "rename" or choice == "Rename" or choice == "r":
pet.rename()
elif choice == "view achievements" or choice == "View Achievements" or choice == "v":
pet.update_achievements()
pet.view_achievements()
elif choice == "mini games" or choice == "Mini Games" or choice == "m":
pet.mini_games()
else:
choice = input("Invalid choice. Please press enter. \n < ")
continue
# check if pet is dead
if pet.hunger >= 100 or pet.energy <= 20 or pet.happiness <= 20:
print(f"{pet.name} has passed away.")
pet.dead = True
time.sleep(1)
print("Game Over.")
add_to_leaderboard(pet)
print("Your score has been added to the leaderboard!")
show_leaderboard()
break
if choice == "view achievements" or choice == "View Achievements" or choice == "v":
pass
elif choice == "mini games" or choice == "Mini Games" or choice == "m":
pass
else:
pet.status()
pet.update_level()
pet.choices() # Show choices
pet.update_achievements() # Add new achievements
time.sleep(1)
game()