-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrains.py
99 lines (80 loc) · 2.93 KB
/
trains.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
'''
The Training Functionality
'''
def intro():
print("Larry: I'm Larry. I'll be your hunting instructor.")
def travel_to_camp():
print("Larry: Let's go to the Meadow to begin your training!")
user = input("Press Enter to travel to the Meadow...")
# Use try/except block to prevent program from crashing
try:
if ord(user) == 27: # this ensures ESC+Enter meets the condition
return ord(user)
except:
pass
print("Travelling to the Meadow...")
print("Larry: This is your camp. Here you'll set up your mouse trap.")
def setup_trap() -> tuple:
print("Larry: Let's get your first trap...")
user = input("Press Enter to view traps that Larry is holding...")
# Use try/except block to prevent program from crashing
try:
if ord(user) == 27: # this ensures ESC+Enter meets the condition
return ord(user)
except:
pass
print("Larry is holding...")
print("Left: High Strain Steel Trap")
print("Right: Hot Tub Trap")
user = input('Select a trap by typing "left" or "right": ').lower().strip()
if user == "left":
print("Larry: Excellent choice.")
print('Your "High Strain Steel Trap" is now set!')
print("Larry: You need cheese to attract a mouse.")
print("Larry places one cheddar on the trap!")
return ("High Strain Steel Trap", 1)
elif user == "right":
print("Larry: Excellent choice.")
print('Your "Hot Tub Trap" is now set!')
print("Larry: You need cheese to attract a mouse.")
print("Larry places one cheddar on the trap!")
return ("Hot Tub Trap", 1)
else:
try:
if ord(user) == 27: # this ensures ESC+Enter meets the condition
return ord(user)
except:
pass
print("Invalid command! No trap selected.")
print("Larry: Odds are slim with no trap!")
return ("Cardboard and Hook Trap", 0)
# PASSED THIS POINT THEY HAVE OFFICIALLY SELECTED A TRAP
def sound_horn() -> str:
print("Sound the horn to call for the mouse...")
user = input('Sound the horn by typing "yes": ').lower().strip()
try:
if ord(user) == 27: # this ensures ESC+Enter meets the condition
return ord(user)
except:
pass
return user
def basic_hunt(cheddar: int, horn_input: str) -> bool:
if cheddar and horn_input == "yes":
print("Caught a Brown mouse!")
print("Congratulations. Ye have completed the training.")
end(1)
else:
print("Nothing happens.")
if cheddar or horn_input == "yes":
print("To catch a mouse, you need both trap and cheese!")
def end(hunt_status: bool):
if hunt_status:
print("Good luck~")
def main():
intro()
travel_to_camp()
has_trap = setup_trap()
horn_input = sound_horn()
basic_hunt(has_trap[1], horn_input)
if __name__ == '__main__':
main()