-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menagerie.py
134 lines (110 loc) · 3.45 KB
/
Menagerie.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
"""
Menagerie - an alternative to Tamagotchi.
Author: Pedro Cruz
April, 2022
"""
from critter import *
def main():
my_critters = []
menu()
choice = get_choice()
print()
while (choice != 0):
run_program(choice, my_critters)
print()
menu()
choice = get_choice()
print()
print("Goodbye!")
def menu():
print("--------------------")
print("Main Menu:")
print("1. Check on critters")
print("2. Add new critter")
print("3. Feed critter")
print("4. Pet critter")
print("5. Play with critter")
print("6. Go to bed")
print("0. Quit")
print()
def get_choice():
"""
Purpose: Gets valid option number from user.
Parameter: None.
Return: userChoice (type: int)
"""
valid = ["0", "1", "2", "3", "4", "5", "6"]
user_choice = input("Choice? ")
while user_choice not in valid:
print()
print("Invalid choice, try again.")
print()
menu()
user_choice = input("Choice? ")
return int(user_choice)
def run_program(choice, critters_list):
if (choice == 1):
check_critters(critters_list)
elif (choice == 2):
create_critter(critters_list)
elif (choice == 3):
feed_critter(critters_list)
elif (choice == 4):
pet_critter(critters_list)
elif (choice == 5):
play_critter(critters_list)
else:
sleep_critter(critters_list)
def sleep_critter(critters_list):
if critters_list != []:
critter = get_critter(critters_list)
critters_list[critter-1].sleep()
else:
print("No critters here yet; try adding one!")
def play_critter(critters_list):
if critters_list != []:
critter = get_critter(critters_list)
critters_list[critter-1].play()
else:
print("No critters here yet; try adding one!")
def pet_critter(critters_list):
if critters_list != []:
critter = get_critter(critters_list)
critters_list[critter-1].pet()
else:
print("No critters here yet; try adding one!")
def feed_critter(critters_list):
if critters_list != []:
critter = get_critter(critters_list)
critters_list[critter-1].feed()
else:
print("No critters here yet; try adding one!")
def get_critter(critters_list):
valid = []
print("Available critters:")
for i in range(1, len(critters_list)+1):
print("%d. %s" %(i, critters_list[i-1].get_name()))
valid.append(i)
critter = input("Please select a critter (number): ")
while (critter.isalpha()) or int(critter) not in valid:
print("That's not a valid choice. try again!")
critter = input("Please select a critter: ")
return int(critter)
def check_critters(critters_list):
if (critters_list != []):
print("The room has some critters in it:")
for i in range(len(critters_list)):
print()
print(critters_list[i])
else:
print("No critters here yet; try adding one!")
def create_critter(critters_list):
name = input("New critter's name: ")
adj = input("What's an adjective that describes the critter? ")
p1 = input("What's the critter's personal pronoun (e.g. she, they)? ")
p2 = input("What's the critter's possessive pronoun (e.g. her, their)" +
"? ")
food = input("What does the critter like to eat? ")
critter = Critter(name, adj, p1, p2, food)
critters_list.append(critter)
main()