-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarma.py
333 lines (297 loc) · 10.7 KB
/
karma.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
import os
import time
import random
import karma_cfg
def reset_cfg():
karma_cfg.day = 1
karma_cfg.social = 1
karma_cfg.hunger = 1
karma_cfg.obey = 1
karma_cfg.fun = 3
def clear_screen():
os.system('cls||clear')
def print_pause(message="", speed=0.025, sleep=1.5):
for char in message:
print(char, end="", flush=True)
time.sleep(speed)
time.sleep(sleep)
def print_ellipsis():
count = 0
while count < 3:
print(".", end="", flush=True)
count += 1
time.sleep(0.5)
print("\n")
time.sleep(1.5)
def display_karma():
clear_screen()
print(" (((((/((############( \n"
" .*/(/(//*//((#############/## \n"
" *****(/*******((#############(*(# \n"
" .//****,*/,***//(///(#######((####*(###*, \n"
" ((******,,*,,,*,.,,/**((######(/*/,**/###### \n"
" #(/*,*,*,,,**..*,,,,..,/(######(***//*(###### \n"
" ((/******,**,.,***(***//(######(###*/####### \n"
" ,//*****,,*,..,**//***/((#####(##(*#######* \n"
" ******,,,...*******//((#(#####*(####### \n"
" ****,,,,..***,****/((#######((####### \n"
" *****,*,,..*******(/(########(##(##(# \n"
" **,*,,,,...,******//(////###########* \n"
" ,*,,...,,.******..,**/***###(# \n"
" **,/,..*///****,,....,/####, \n"
" ,*(**....,,*(///((##(#####(, \n"
" ...,/(*,..,*##&&#&#&((//**// \n"
" (*.....*##*.##((((*.,*/(#&&@& \n"
" ,((##(/(#**/(##&&(/*.,/#&&&&&&* \n"
" ((########/**/###&&##(/(#&&&### \n"
" .///(########/((##&&&##(/**/((## \n"
" *****/(##(*,.//((*.. . .***//## \n"
" /***//((, ..... .....,,,**//, \n"
" *****(# ,....,,*,,**/ \n"
" ,***///( .,..,,,,,,,**, \n"
" */(,(/(//(( ,*,,**/,,****,/ \n"
" .*,*,,///. ......,,. .., \n\n")
print_pause("Oh, Karma. Aren't you cute?\n\n", sleep=5)
clear_screen()
def train():
clear_screen()
if karma_cfg.obey < 5:
print_pause("You trained with Karma using some treats.\n"
"She will obey you more now.\n\n")
karma_cfg.obey += 1
else:
print_pause("You trained with Karma using some treats.\n"
"She now obeys every command.\n\n")
while karma_cfg.hunger >= 0:
karma_cfg.hunger -= 1
clear_screen()
def play():
clear_screen()
print_pause("You played with Karma.\n"
"She had fun with you.\n")
karma_cfg.fun += 1
clear_screen()
def socialize():
clear_screen()
if karma_cfg.hunger < 5:
if karma_cfg.social == 0:
print_pause("Karma is too shy to play with "
"other dogs.\n\n")
elif 0 < karma_cfg.social < 5:
outcome = random.randrange(6)
if outcome == 0:
print_pause("Another dog scared Karma.\n"
"She had no fun and feels distrust"
"toward you.\n\n")
karma_cfg.fun -= 1
karma_cfg.social -= 1
karma_cfg.obey -= 1
else:
print_pause("Karma had a lot of fun.")
karma_cfg.fun += 1
karma_cfg.social += 1
else:
print_pause("Karma keeps licking and biting\n"
"your fingers ever so slightly.\n")
print_pause("She's probably hungry.\n\n")
clear_screen()
def treat():
clear_screen()
if karma_cfg.hunger == 0:
print_pause("Karma doesn't want food now.\n\n")
elif karma_cfg.hunger < 5:
print_pause("You gave a treat to Karma. She loved it.\n\n")
karma_cfg.fun += 2
karma_cfg.hunger -= 1
else:
print_pause("Karma devoured the treat like there's no tomorrow.\n\n")
karma_cfg.fun += 1
karma_cfg.hunger -= 1
clear_screen()
def feed():
clear_screen()
if karma_cfg.hunger == 0:
print_pause("Karma doesn't want food now.\n\n")
elif karma_cfg.hunger < 3:
print_pause("You fed Karma. She is munching happily.\n\n")
karma_cfg.hunger -= 1
else:
print_pause("You fed Karma. She ate it a little too fast.\n\n")
karma_cfg.hunger = 3
clear_screen()
def walk():
clear_screen()
if karma_cfg.hunger < 5:
if karma_cfg.obey < 2:
verb = ["peed", "pooped"]
activity = random.randint(1, 2)
print_pause("Karma kept sitting stubbornly.\n"
"Desperate, you took her in your arms\n"
"and went back home, where she " + verb[activity]
+ "\non the carpet.")
karma_cfg.hunger += 1
clear_screen()
home()
if 4 > karma_cfg.obey >= 2:
print_pause("After a while, Karma finally moved on.\n"
"The walk was okay, and she seemed to\n"
"enjoy it.\n")
karma_cfg.fun += 1
karma_cfg.hunger += 1
if karma_cfg.obey >= 4:
print_pause("Karma followed you happily.\n"
"You both enjoyed the walk and she seems "
"a little less shy.\n\n")
karma_cfg.fun += 2
karma_cfg.hunger += 1
karma_cfg.social += 1
else:
print_pause("Karma keeps licking and biting\n"
"your fingers ever so slightly.\n")
print_pause("She's probably hungry.\n\n")
clear_screen()
def new_day():
clear_screen()
print_pause("Whew, what a day!\n"
"Both of you deserve a good night's sleep.\n\n")
karma_cfg.hunger = 4
karma_cfg.day += 1
clear_screen()
print_pause("It's Day no. " + str(karma_cfg.day) + ".")
def park():
clear_screen()
print_pause("You are in the park.\n")
dogs_present = random.choice([True, False])
if dogs_present:
print_pause("There are some people walking their dogs.\n")
print_pause("What do you want to do?\n\n")
outcome = input("[1] Walk Karma in the park.\n"
"[2] Give her a treat.\n"
"[3] Train her a bit.\n"
"[4] Let her play with other dogs.\n"
"[5] Go back home.\n"
"Type the number of your choice: ")
if outcome == "1":
walk()
park()
elif outcome == "2":
treat()
park()
elif outcome == "3":
train()
park()
elif outcome == "4":
socialize()
park()
elif outcome == "5":
home()
else:
print_pause("That doesn't seem to be an option.\n")
print_ellipsis()
park()
else:
print_pause("There seem to be no dogs in the park.\n")
print_pause("What do you want to do?\n\n")
outcome = input("[1] Walk Karma in the park.\n"
"[2] Give her a treat.\n"
"[3] Train her a bit.\n"
"[4] Go back home.\n"
"Type the number of your choice: ")
if outcome == "1":
walk()
park()
elif outcome == "2":
treat()
park()
elif outcome == "3":
train()
park()
elif outcome == "4":
home()
def home():
if karma_cfg.day != 7:
print_pause("You are at home.\n")
print_pause("What do you want to do?\n\n")
outcome = input("[1] Take Karma to the park.\n"
"[2] Give her a treat.\n"
"[3] Train her a bit.\n"
"[4] Give her food.\n"
"[5] Take a picture.\n"
"[6] Play with her.\n"
"[0] Call it a day.\n"
"Type the number of your choice: ")
if outcome == "1":
park()
elif outcome == "2":
treat()
home()
elif outcome == "3":
train()
home()
elif outcome == "4":
feed()
home()
elif outcome == "5":
display_karma()
home()
elif outcome == "6":
play()
home()
elif outcome == "0":
new_day()
home()
else:
print_pause("That doesn't seem to be an option.\n")
print_ellipsis()
clear_screen()
home()
else:
outro()
def intro():
print_pause("Your friends P. and M. asked you to dogsit Karma,\n"
"a dachshund puppy, for a week. Make sure that:\n\n"
"- she is not hungry\n"
"- she has fun\n"
"- she isn't shy of other dogs.\n\n"
"Good luck!", sleep=5)
clear_screen()
def outro():
print_pause("It's your last day with Karma "
"and the owners came to pick her up.\n")
if karma_cfg.hunger >= 4 or karma_cfg.fun < 3 or karma_cfg.social < 2:
print_pause("She ran to them and growled sadly, "
"nipping at their fingers.\n")
print_pause("'It seems she isn't too happy.', said M., "
"obviously worried.\n", sleep=1)
print_ellipsis()
print_pause("GAME OVER.\n\n")
clear_screen()
else:
print_pause("She was happy to see them, but looked back "
"at you with longing.\n")
print_pause("'Oh, she seems to have fallen for you, mate,' "
"said P. with a friendly smile.", sleep=1)
print_ellipsis()
print_pause("YOU WIN!\n\n")
display_karma()
clear_screen()
while True:
outcome = input("[1] Play again.\n"
"[2] Quit game.\n"
"Type the number of your choice: ")
if "1" in outcome:
clear_screen()
play_game()
elif "2" in outcome:
exit(0)
else:
print_pause("That doesn't seem to be an option.\n")
print_ellipsis()
clear_screen()
def play_game():
reset_cfg()
clear_screen()
intro()
home()
if __name__ == '__main__':
play_game()