-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpgtext.py
More file actions
452 lines (399 loc) · 11.6 KB
/
rpgtext.py
File metadata and controls
452 lines (399 loc) · 11.6 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
import os, random
run = True
menu = True
play = False
rules = False
key = False
fight = False
standing = True
buy = False
speak = False
boss = False
HP = 50
HPMAX = 50
ATK = 3
pot = 1
elix = 0
gold = 0
x = 0
y = 0
# x = 0 x = 1 x = 2 x = 3 x = 4 x = 5 x = 6
map = [["plains", "plains", "plains", "plains", "forest", "mountain", "cave"], # y = 0
["forest", "forest", "forest", "forest", "forest", "hills", "mountain"], # y = 1
["forest", "fields", "bridge", "plains", "hills", "forest", "hills"], # y = 2
["plains", "shop", "town", "mayor", "plains", "hills", "mountain"], # y = 3
["plains", "fields", "fields", "plains", "hills", "mountain", "mountain"]] # y = 4
y_len = len(map)-1
x_len = len(map[0])-1
biom = {
"plains": {
"t": "PLAINS",
"e": True},
"forest": {
"t": "WOODS",
"e": True},
"fields": {
"t": "FIELDS",
"e": False},
"bridge": {
"t": "BRIGE",
"e": True},
"town": {
"t": "TOWN CENTRE",
"e": False},
"shop": {
"t": "SHOP",
"e": False},
"mayor": {
"t": "MAYOR",
"e": False},
"cave": {
"t": "CAVE",
"e": False},
"mountain": {
"t": "MOUNTAIN",
"e": True},
"hills": {
"t": "HILLS",
"e": True,
}
}
e_list = ["Goblin", "Orc", "Slime"]
mobs = {
"Goblin": {
"hp": 15,
"at": 3,
"go": 8
},
"Orc": {
"hp": 35,
"at": 5,
"go": 18
},
"Slime": {
"hp": 30,
"at": 2,
"go": 12
},
"Dragon": {
"hp": 100,
"at": 8,
"go": 100
}
}
def clear():
os.system("cls")
def draw():
print("xX--------------------xX")
def save():
list = [
name,
str(HP),
str(ATK),
str(pot),
str(elix),
str(gold),
str(x),
str(y),
str(key)
]
file = open("load.txt", "w")
for item in list:
file.write(item + "\n")
file.close()
def heal(amount):
global HP
if HP + amount < HPMAX:
HP += amount
else:
HP = HPMAX
print(name + "'s HP refilled to " + str(HP) + "!")
def battle():
global fight, play, run, HP, pot, elix, gold, boss
if not boss:
enemy = random.choice(e_list)
else:
enemy = "Dragon"
hp = mobs[enemy]["hp"]
hpmax = hp
atk = mobs[enemy]["at"]
g = mobs[enemy]["go"]
while fight:
clear()
draw()
print("Defeat the " + enemy + "!")
draw()
print(enemy + "'s HP: " + str(hp) + "/" + str(hpmax))
print(name + "'s HP: " + str(HP) + "/" + str(HPMAX))
print("POTIONS: " + str(pot))
print("ELIXIR: " + str(elix))
draw()
print("1 - ATTACK")
if pot > 0:
print("2 - USE POTION (30HP)")
if elix > 0:
print("3 - USE ELIXIR (50HP)")
draw()
choice = input("# ")
if choice == "1":
hp -= ATK
print(name + " dealt " + str(ATK) + " damage to the " + enemy + ".")
if hp > 0:
HP -= atk
print(enemy + " dealt " + str(atk) + " damage to " + name + ".")
input("> ")
elif choice == "2":
if pot > 0:
pot -= 1
heal(30)
HP -= atk
print(enemy + " dealt " + str(atk) + " damage to " + name + ".")
else:
print("No potions!")
input("> ")
elif choice == "3":
if elix > 0:
elix -= 1
heal(50)
HP -= atk
print(enemy + " dealt " + str(atk) + " damage to " + name + ".")
else:
print("No elixirs!")
input("> ")
if HP <= 0:
print(enemy + " defeated " + name + "...")
draw()
fight = False
play = False
run = False
print("GAME OVER")
input("> ")
if hp <= 0:
print(name + " defeated the " + enemy + "!")
draw()
fight = False
gold += g
print("You've found " + str(g) + " gold!")
if random.randint(0, 100) < 30:
pot += 1
print("You've found a potion!")
if enemy == "Dragon":
draw()
print("Congratulations, you've finished the game!")
boss = False
play = False
run = False
input("> ")
clear()
def shop():
global buy, gold, pot, elix, ATK
while buy:
clear()
draw()
print("Welcome to the shop!")
draw()
print("GOLD: " + str(gold))
print("POTIONS: " + str(pot))
print("ELIXIRS: " + str(elix))
print("ATK: " + str(ATK))
draw()
print("1 - BUY POTION (30HP) - 5 GOLD")
print("2 - BUY ELIXIR (MAXHP) - 8 GOLD")
print("3 - UPGRADE WEAPON (+2ATK) - 10 GOLD")
print("4 - LEAVE")
draw()
choice = input("# ")
if choice == "1":
if gold >= 5:
pot += 1
gold -= 5
print("You've bought a potion!")
else:
print("Not enough gold!")
input("> ")
elif choice == "2":
if gold >= 8:
elix += 1
gold -= 8
print("You've bought an elixir!")
else:
print("Not enough gold!")
input("> ")
elif choice == "3":
if gold >= 10:
ATK += 2
gold -= 10
print("You've upgraded your weapon!")
else:
print("Not enough gold!")
input("> ")
elif choice == "4":
buy = False
def mayor():
global speak, key
while speak:
clear()
draw()
print("Hello there, " + name + "!")
if ATK < 10:
print("You're not strong enough to face the dragon yet! Keep practicing and come back later!")
key = False
else:
print("You might want to take on the dragon now! Take this key but be careful with the beast!")
key = True
draw()
print("1 - LEAVE")
draw()
choice = input("# ")
if choice == "1":
speak = False
def cave():
global boss, key, fight
while boss:
clear()
draw()
print("Here lies the cave of the dragon. What will you do?")
draw()
if key:
print("1 - USE KEY")
print("2 - TURN BACK")
draw()
choice = input("# ")
if choice == "1":
if key:
fight = True
battle()
elif choice == "2":
boss = False
while run:
while menu:
print("1, NEW GAME")
print("2, LOAD GAME")
print("3, RULES")
print("4, QUIT GAME")
if rules:
print("I'm the creator of this game and these are the rules.")
rules = False
choice = ""
input("> ")
else:
choice = input("# ")
if choice == "1":
clear()
name = input("# What's your name, hero? ")
menu = False
play = True
elif choice == "2":
try:
f = open("load.txt", "r")
load_list = f.readlines()
if len(load_list) == 9:
name = load_list[0][:-1]
HP = int(load_list[1][:-1])
ATK = int(load_list[2][:-1])
pot = int(load_list[3][:-1])
elix = int(load_list[4][:-1])
gold = int(load_list[5][:-1])
x = int(load_list[6][:-1])
y = int(load_list[7][:-1])
key = bool(load_list[8][:-1])
clear()
print("Welcome back, " + name + "!")
input("> ")
menu = False
play = True
else:
print("Corrupt save file!")
input("> ")
except OSError:
print("No loadable save file!")
input("> ")
elif choice == "3":
rules = True
elif choice == "4":
quit()
while play:
save() # autosave
clear()
if not standing:
if biom[map[y][x]]["e"]:
if random.randint(0, 100) < 30:
fight = True
battle()
if play:
draw()
print("LOCATION: " + biom[map[y][x]]["t"])
draw()
print("NAME: " + name)
print("HP: " + str(HP) + "/" + str(HPMAX))
print("ATK: " + str(ATK))
print("POTIONS: " + str(pot))
print("ELIXIRS: " + str(elix))
print("GOLD: " + str(gold))
print("COORD:", x, y)
draw()
print("0 - SAVE AND QUIT")
if y > 0:
print("1 - NORTH")
if x < x_len:
print("2 - EAST")
if y < y_len:
print("3 - SOUTH")
if x > 0:
print("4 - WEST")
if pot > 0:
print("5 - USE POTION (30HP)")
if elix > 0:
print("6 - USE ELIXIR (50HP)")
if map[y][x] == "shop" or map[y][x] == "mayor" or map[y][x] == "cave":
print("7 - ENTER")
draw()
dest = input("# ")
if dest == "0":
play = False
menu = True
save()
elif dest == "1":
if y > 0:
y -= 1
standing = False
elif dest == "2":
if x < x_len:
x += 1
standing = False
elif dest == "3":
if y < y_len:
y += 1
standing = False
elif dest == "4":
if x > 0:
x -= 1
standing = False
elif dest == "5":
if pot > 0:
pot -= 1
heal(30)
else:
print("No potions!")
input("> ")
standing = True
elif dest == "6":
if elix > 0:
elix -= 1
heal(50)
else:
print("No elixirs!")
input("> ")
standing = True
elif dest == "7":
if map[y][x] == "shop":
buy = True
shop()
if map[y][x] == "mayor":
speak = True
mayor()
if map[y][x] == "cave":
boss = True
cave()
else:
standing = True