-
Notifications
You must be signed in to change notification settings - Fork 0
/
critter_caretaker_UPDATED.246.py
152 lines (129 loc) · 4.09 KB
/
critter_caretaker_UPDATED.246.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
# Critter Caretaker
# a virtual pet to care for
class Critter(object):
MAX_FOOD = 20
MAX_FUN = 20
def __init__(self, name, fullness=MAX_FOOD, happiness=MAX_FUN):
self.name = name
self.fullness = fullness
self.happiness = happiness
self.alive = True
def __pass_time(self, fullness_time=1, happiness_time=1):
self.fullness -= fullness_time
self.happiness -= happiness_time
def __str__(self):
return '{} - fullness: {}\thappiness: {}'.format(self.name, self.fullness, self.happiness)
@property
def mood(self):
if self.fullness < 5:
hungry = "famished"
elif self.fullness <= 10:
hungry = "hungry"
elif self.fullness <= 15:
hungry = "ok"
else:
hungry = "full"
if self.happiness < 5:
bored = "unloved"
elif self.happiness <= 10:
bored = "bored"
elif self.happiness <= 15:
bored = "ok"
else:
bored = "happy"
return '{} and {}'.format(hungry, bored)
def living(self):
cause1 = ''
cause2 = ''
conjunction = ''
if self.fullness <=0:
cause1 = 'starvation'
self.alive = False
if self.happiness <= 0:
cause2 = 'boredom'
self.alive = False
if cause1 and cause2:
conjunction = ' and '
return self.alive, '{}{}{}'.format(cause1, conjunction, cause2)
def talk(self):
print('I am', self.name, 'and I feel', self.mood, 'now.\n')
print('Fullness : {}'.format('*' * self.fullness))
print('Happiness: {}'.format('*' * self.happiness))
self.__pass_time()
def eat(self, food=4):
print('Brruppp. Thank you!')
self.fullness += food
if self.fullness > self.MAX_FOOD:
self.fullness = self.MAX_FOOD
happiness_time = int(food / 3) or 1
self.__pass_time(happiness_time=happiness_time)
def play(self, fun=4):
print('Wheee!')
self.happiness += fun
if self.happiness > self.MAX_FUN:
self.happiness = self.MAX_FUN
fullness_time = int(fun * 0.5) or 1
self.__pass_time(fullness_time=fullness_time)
def ignore(self):
self.__pass_time()
self.happiness -= int(self.happiness * 0.5)
self.fullness -= int(self.fullness * 0.5)
def menu(crit_name):
return \
("""
0 = Quit
1 - Listen to {name}
2 - Feed {name}
3 - Play with {name}
4 - Ignore {name}
""".format(name=crit_name))
print()
def get_choice(crit_name):
print(menu(crit_name))
choice = True
while choice:
choice = input("\nChoice:")
if choice in ['0', '1', '2', '3', '4'] or choice == 'values':
return choice
else:
print('Make a valid choice.')
choice = False
def handle_choice(crit, choice=1):
#exit
if choice == '0':
print('Good bye')
return False # don't keep playing
#listen
elif choice == '1':
crit.talk()
#feed
elif choice == '2':
amount = int(input('How much food?:'))
crit.eat(food=amount)
#play
elif choice == '3':
amount = int(input('How long?:'))
crit.play(fun=amount)
#ignore
elif choice == '4':
crit.ignore()
#values
elif choice == 'values':
print(crit)
return True # keep playing
def main():
print('\t\tCRITTER CARETAKER')
print('\n\tTake care of your critter!')
print('\tMake sure your critter is well fed and loved,\n\tor they might die!\n\n')
crit_name = input("What do you want to name your critter?:")
crit = Critter(crit_name)
play = True
choice = ''
while play:
choice = get_choice(crit.name)
play = handle_choice(crit, choice=choice)
living, cause = crit.living()
if not living:
print('{} has died from {}!'.format(crit.name, cause))
break
main()