· 9 years ago · Mar 17, 2017, 01:30 PM
1#Another Text Adventure
2#Author: Josh Scott
3#Version 1.0.1
4
5#imports time
6import time
7
8#allows for random functions
9import random
10
11#allows SQL actions
12import sqlite3
13
14#this is the library used for claering the brackets from the leaderboard.
15import itertools
16
17MapData="wwwwwwwwwwwwwwwwwwwwwwffffffffpsvswwwwwwwfftffffffppsssswwwwwffffffffpppwwwwwwwwwffffffpppppwtppbbswwfffffppppppwppwwsswwffffpppppppwwwwsspwwppppppppbppwppppppwwvpppppwwbwwwppppmpwwwwwwwwwpbpppppppmmwwpppppppppppppppmmmwwpppppppvpppppppmmmwwmmppppppppppppppppwwmmmmmmmmmpppvmmpppwwmmmmmmmmmpmmmmmmmpwwmmmdmmmmppmmmmmmmmwwwmmmmmmmpppmmmmmmmwwwmmmmmmppppppmmmmwwwwwmmmmpppppppptwwwwwwwwwwwwwwwwwwwwwwww"
18
19LoadArray = ["","","","","","","","","","","","","","","","","",""]
20
21#access of the files made global
22Userfile = sqlite3.connect("Users.db")
23USER = Userfile.cursor()
24
25Itemfile = sqlite3.connect("Items.db")
26ITEM = Itemfile.cursor()
27
28Monsterfile = sqlite3.connect("Monsters.db")
29MONSTER = Monsterfile.cursor()
30
31print("")
32print(" █████╗ ███╗ ██╗ ██████╗ ████████╗██╗ ██╗███████╗██████╗ ")
33print(" ██╔â•â•██╗████╗ ██║██╔â•â•â•██╗╚â•â•██╔â•â•â•██║ ██║██╔â•â•â•â•â•██╔â•â•██╗ ")
34print(" ███████║██╔██╗ ██║██║ ██║ ██║ ███████║█████╗ ██████╔╠")
35print(" ██╔â•â•██║██║╚██╗██║██║ ██║ ██║ ██╔â•â•██║██╔â•â•╠██╔â•â•██╗ ")
36print(" ██║ ██║██║ ╚████║╚██████╔╠██║ ██║ ██║███████╗██║ ██║ ")
37print(" ╚â•╠╚â•â•╚â•╠╚â•â•â•╠╚â•â•â•â•â•╠╚â•╠╚â•╠╚â•â•╚â•â•â•â•â•â•â•╚â•╠╚â•â• ")
38time.sleep(.5)
39print(" ")
40print(" ████████╗███████╗██╗ ██╗████████╗ ")
41print(" ╚â•â•██╔â•â•â•██╔â•â•â•â•â•╚██╗██╔â•╚â•â•██╔â•â•â• ")
42print(" ██║ █████╗ ╚███╔╠██║ ")
43print(" ██║ ██╔â•â•╠██╔██╗ ██║ ")
44print(" ██║ ███████╗██╔╠██╗ ██║ ")
45print(" ╚â•╠╚â•â•â•â•â•â•â•╚â•╠╚â•╠╚â•â• ")
46time.sleep(.5)
47print(" ")
48print(" █████╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗████████╗██╗ ██╗██████╗ ███████╗")
49print(" ██╔â•â•██╗██╔â•â•██╗██║ ██║██╔â•â•â•â•â•████╗ ██║╚â•â•██╔â•â•â•██║ ██║██╔â•â•██╗██╔â•â•â•â•â•")
50print(" ███████║██║ ██║██║ ██║█████╗ ██╔██╗ ██║ ██║ ██║ ██║██████╔â•█████╗ ")
51print(" ██╔â•â•██║██║ ██║╚██╗ ██╔â•██╔â•â•╠██║╚██╗██║ ██║ ██║ ██║██╔â•â•██╗██╔â•â•â• ")
52print(" ██║ ██║██████╔╠╚████╔╠███████╗██║ ╚████║ ██║ ╚██████╔â•██║ ██║███████╗")
53print(" ╚â•╠╚â•â•╚â•â•â•â•â•╠╚â•â•â•╠╚â•â•â•â•â•â•â•╚â•╠╚â•â•â•╠╚â•╠╚â•â•â•â•â•╠╚â•╠╚â•â•╚â•â•â•â•â•â•â•")
54time.sleep(1)
55
56#main menu
57def Main():
58 PlayerOption = "4"
59 while PlayerOption not in["1","2","3","9"]:
60 print("\n\nMain Menu")
61 print("")
62 print("1. Load Game")
63 print("2. New Game")
64 print("3. Leader Board")
65 print("9. Quit")
66 print("")
67 PlayerOption = input("> ")
68 print("")
69
70 if PlayerOption == ("1"):
71 Loadgame(Userfile, USER,LoadArray)
72 elif PlayerOption == ("2"):
73 Newgame(Userfile, USER, LoadArray)
74 elif PlayerOption == ("3"):
75 Leaderboard(Userfile,USER,LoadArray)
76 elif PlayerOption == ("9"):
77 exit()
78
79#loading an already saved game
80def Loadgame(Userfile, USER, LoadArray):
81 MapData="wwwwwwwwwwwwwwwwwwwwwwffffffffpssswwwwwwwfftffffffppsssswwwwwffffffffpppwwwwwwwwwffffffpppppwtppbbswwfffffppppppwppwwsswwffffpppppppwwwwsspwwppppppppbppwppppppwwvpppppwwbwwwppppmpwwwwwwwwwpbpppppppmmwwpppppppppppppppmmmwwpppppppppppppppmmmwwmmppppppppppppppppwwmmmmmmmmmpppvmmpppwwmmmmmmmmmpmmmmmmmpwwmmmdmmmmppmmmmmmmmwwwmmmmmmmpppmmmmmmmwwwmmmmmmppppppmmmmwwwwwmmmmpppppppptwwwwwwwwwwwwwwwwwwwwwwww"
82 UserName = ""
83
84 while UserName == "":
85 UserName = input("What is your name?\n> ")
86
87 print("Ah yes and what was our password?")
88 UserPass = ""
89
90 while UserPass == "":
91 UserPass = input("> ")
92
93 NoExist = True
94 while NoExist == True:
95 try:
96 #checking if the Username is already in use
97 #if the name cannot be found the program will break and run into the 'except' section
98 USER.execute("SELECT u.ID, u.Name, u.Pass, u.lvl, u.Type, u.HP, u.X, u.Y, u.Money, u.Helm, u.Arm, u.Weapon, u.Item1, u.Item2, u.Item3, u.Item4, u.Item5,u.Map FROM Users u WHERE u.Name = ?", (UserName,))
99 Load = USER.fetchone()
100 Place = 0
101
102 for x in Load:
103 LoadArray[Place] = x
104 Place += 1
105
106 ID = LoadArray[0]
107 UserName = LoadArray[1]
108 Password = LoadArray[2]
109 Level = LoadArray[3]
110 PlayerType = LoadArray[4]
111 Health = LoadArray[5]
112 XCoord = LoadArray[6]
113 YCoord = LoadArray[7]
114 Gold = LoadArray[8]
115 Helm = LoadArray[9]
116 Arm = LoadArray[10]
117 Weapon = LoadArray[11]
118 Item1 = LoadArray[12]
119 Item2 = LoadArray[13]
120 Item3 = LoadArray[14]
121 Item4 = LoadArray[15]
122 Item5 = LoadArray[16]
123 MapData = LoadArray[17]
124
125 Count = 0
126
127 for Row in range(20):
128 MapRow = []
129 for Column in range(20):
130 MapRow.append(MapData[Count])
131 Count+=1
132 Map.append(MapRow)
133 #at this point username exists.
134
135
136 if UserPass == Password:
137 NoExist = False
138 PlayGame(UserName,Password,Level,PlayerType,Health,XCoord,YCoord,Gold,Helm,Arm,Weapon,Item1,Item2,Item3,Item4,Item5,Map)
139 else:
140 print("I know of nobody by that name friend.")
141 print("What is your real name?")
142 UserName = input("> ")
143 UserPass = input("And your password?\n> ")
144
145
146 except:
147 print("I know of nobody by that name friend.")
148 print("What is your real name?")
149 UserName = input("> ")
150 UserPass = input("And your password?\n> ")
151
152
153
154#creating a new save file
155def Newgame(Userfile, USER, LoadArray):
156 print("What is your name traveller?")
157 UserName = ""
158 while UserName == "":
159 UserName = input("> ")
160
161 AlreadyUsed = True
162 while AlreadyUsed == True:
163 try:
164 #checking if the Username is already in use
165 #if the name cannot be found the program will break and run into the 'except' section
166 USER.execute("SELECT u.ID, u.Name, u.Pass, u.lvl, u.Type, u.HP, u.X, u.Y, u.Money, u.Helm, u.Arm, u.Weapon, u.Item1, u.Item2, u.Item3, u.Item4, u.Item5,u.Map FROM Users u WHERE u.Name = ?", (UserName,))
167 Load = USER.fetchone()
168 Place = 0
169
170 for x in Load:
171 LoadArray[Place] = x
172 Place += 1
173
174 ID = LoadArray[0]
175 UserName = LoadArray[1]
176 Password = LoadArray[2]
177 Level = LoadArray[3]
178 PlayerType = LoadArray[4]
179 Health = LoadArray[5]
180 XCoord = LoadArray[6]
181 YCoord = LoadArray[7]
182 Gold = LoadArray[8]
183 Helm = LoadArray[9]
184 Arm = LoadArray[10]
185 Weapon = LoadArray[11]
186 Item1 = LoadArray[12]
187 Item2 = LoadArray[13]
188 Item3 = LoadArray[14]
189 Item4 = LoadArray[15]
190 Item5 = LoadArray[16]
191 MapData = LoadArray[17]
192
193 Count = 0
194 print("I already know someone by that name.")
195 UserName = input("What is your name traveller?\n> ")
196
197 except:
198
199
200 print("Greetings",UserName,"It has been many moons since a HERO of your calibre has been seen in these lands. Remind me, which school do you follow?\n\t1. The Fighter\n\t2. The Ranger\n\t3. The Wizard")
201 PlayerType = int(input("> "))
202 while PlayerType not in (1,2,3):
203 print("invalid Choice")
204
205 PlayerType = int(input("> "))
206
207 print("Ahh, good. I hope you can help the people of this land. A TERRIBLE creature; The Dragon Vex. Controls and torments these lands. To defeat him you must first collect the ancient relics. A Helm, A chest piece and the great weapon of the hero to defeat him. Will you do this for us? [Y/N]")
208 PlayerOption = input("> ")
209 if PlayerOption in ["y", "Y", "Yes", "YES", "yes"]:
210 print("Good")
211 else:
212
213 while PlayerOption not in ["y", "Y", "Yes", "YES", "yes"]:
214
215 x = random.randint(1,3)
216
217 if x == 1:
218 print("Please?")
219 elif x == 2:
220 print("Pretty Please?")
221 elif x == 3:
222 print("But you're the Hero!")
223 else:
224 print("loop Error")
225 PlayerOption = input("> ")
226
227 print("Now, for when we next meet we should have a password to make sure you are who you say you are.")
228 print("PASSWORD:")
229 Password1 = input("> ")
230 print("I’m a smidge deaf in that ear. Once more?")
231 Password2 = input("> ")
232
233 while Password1 != Password2:
234 print("Those two weren't the same. \nTry again")
235 Password1 = input("> ")
236 print("One more time")
237 Password2 = input("> ")
238
239 Password = Password1
240 Health = 10
241 Level = 1
242 Gold = 5
243 Weapon = 0
244 XCoord = 1
245 YCoord = 8
246
247 #creating the table for the players if on a new system
248 NewTable = """
249 CREATE TABLE IF NOT EXISTS Users(
250 ID INTEGER PRIMARY KEY,
251 Name VARCHAR (20),
252 Pass VARCHAR(20),
253 Lvl INTEGER,
254 Type INTEGER,
255 HP INTEGER,
256 X INTEGER,
257 Y INTEGER,
258 Money INTEGER,
259 Helm INTEGER,
260 Arm INTEGER,
261 Weapon INTEGER,
262 Item1 INTEGER,
263 Item2 INTEGER,
264 Item3 INTEGER,
265 Item4 INTEGER,
266 Item5 INTEGER,
267 Map VARCHAR (400),
268 FOREIGN KEY(Helm)REFERENCES Items(Id),
269 FOREIGN KEY(Arm)REFERENCES Items(Id),
270 FOREIGN KEY(Weapon)REFERENCES Items(Id),
271 FOREIGN KEY(Item1)REFERENCES Items(Id),
272 FOREIGN KEY(Item2)REFERENCES Items(Id),
273 FOREIGN KEY(Item3)REFERENCES Items(Id),
274 FOREIGN KEY(Item4)REFERENCES Items(Id),
275 FOREIGN KEY(Item5)REFERENCES Items(Id));"""
276
277 USER.execute(NewTable)
278
279 #save function with placeholder data
280
281 insert= """
282 INSERT INTO Users(Name,Pass,Lvl,Type,HP,X,Y,Money,Helm,Arm,Weapon,Map,Item1,Item2,Item3,Item4,Item5)
283 VALUES("PLACEHOLDER","PLACEHOLDER",1,0,10,1,8,50,17,19,0,"wwwwwwwwwwwwwwwwwwwwwwffffffffpssswwwwwwwfftffffffppsssswwwwwffffffffpppwwwwwwwwwffffffpppppwtppbbswwfffffppppppwppwwsswwffffpppppppwwwwsspwwppppppppbppwppppppwwvpppppwwbwwwppppmpwwwwwwwwwpbpppppppmmwwpppppppppppppppmmmwwpppppppppppppppmmmwwmmppppppppppppppppwwmmmmmmmmmpppvmmpppwwmmmmmmmmmpmmmmmmmpwwmmmdmmmmppmmmmmmmmwwwmmmmmmmpppmmmmmmmwwwmmmmmmppppppmmmmwwwwwmmmmpppppppptwwwwwwwwwwwwwwwwwwwwwwww",0,0,0,0,0)"""
284
285 USER.execute(insert)
286
287 USER.execute ("SELECT * FROM Users ")
288
289 #saving over the placeholders
290
291 USER.execute("UPDATE Users SET Name = ? WHERE Name = 'PLACEHOLDER' ",(UserName,))
292
293 USER.execute("UPDATE Users SET Pass = ? WHERE Pass = 'PLACEHOLDER' ",(Password,))
294
295 USER.execute("UPDATE Users SET Type = ? WHERE Type = 0 ",(PlayerType,))
296
297 USER.execute("UPDATE Users SET Weapon = ? WHERE Weapon = 0 ",(PlayerType,))
298 Userfile.commit()
299 AlreadyUsed = False
300
301
302
303def Leaderboard(Userfile,USER,LoadArray):
304 #print leader board after sorting
305
306 Place = 0
307
308 Scorelist = []
309 Namelist = []
310 Score = ""
311 Name = ""
312 USER.execute("SELECT u.ID FROM Users u")
313
314 #loading data from table into separate arrays until end of list
315
316 Length = len(USER.fetchall())
317 Length = int(Length)
318
319 USER.execute('SELECT * FROM Users')
320 #Fetches the data in the specified rows
321
322 Userfile.row_factory = lambda USER, row: row[0]
323 Scorelist = USER.execute('SELECT Money FROM Users').fetchall()
324 Namelist = USER.execute('SELECT Name FROM Users').fetchall()
325
326 Scorelist
327 Namelist
328
329 #Bubblesort function
330 #Grade A Algorithm
331
332 for passnum in range(abs(Length)-1):
333 i = 0
334
335 for i in range(abs(Length)-1):
336
337 if Scorelist[i]<Scorelist[i+1]:
338 tempScore = Scorelist[i]
339 tempName = Namelist[i]
340 Scorelist[i] = Scorelist[i+1]
341 Namelist[i] = Namelist[i+1]
342 Scorelist[i+1] = tempScore
343 Namelist[i+1] = tempName
344
345 passnum += 1
346 #Bubblesort complete
347
348 #removes brackets from the named lists
349 Names = list(itertools.chain.from_iterable(Namelist))
350 Scores = list(itertools.chain.from_iterable(Scorelist))
351
352 x=0
353 while x<abs(Length):
354 print("\t",(x+1),".",Names[x]," \t ",Scores[x])
355 x+=1
356 Main()
357
358
359
360#main game section
361def PlayGame(UserName,Password,Level,PlayerType,Health,XCoord,YCoord,Gold,Helm,Arm,Weapon,Item1,Item2,Item3,Item4,Item5,Map):
362 Map = []
363 Count = 0
364
365
366 Itemfile = sqlite3.connect("Items.db")
367 ITEM = Itemfile.cursor()
368
369 for Row in range(20):
370 MapRow = []
371 for Column in range(20):
372 MapRow.append(MapData[Count])
373 Count+=1
374 Map.append(MapRow)
375
376 print("Welcome to the game,",UserName,". To travel enter in a direction type: N = North, E = East, S = South, W = West) Find The Relics!")
377
378 while Running:
379
380 #every 5 turns the user's health will increase by 1 until it is at it's maximum.
381
382 if Health < 10+(Level*2):
383 Health += 1
384
385 #checks the map tile to determine what landscape the user is on.
386 if Map[YCoord][XCoord] == "p":
387 print("The plains span across the land before you")
388 elif Map[YCoord][XCoord] == "f":
389 print("A thick forest looms over you")
390 elif Map[YCoord][XCoord] == "v":
391 print("You enter a small villiage")
392 Leaving = False
393 while not Leaving:
394 PlayerOption = input("Do you wish to visit:\n\t1.The Inn\n\t2.The Shop\n\t9.Leave\n> ")
395 if PlayerOption == "1":
396 NewGold = Inn(Gold)
397 if NewGold < Gold:
398 Health = 10 + (Level*2)
399 Gold = NewGold
400 elif PlayerOption == "2":
401 #ensures that the data from the shop isn't incorrect
402 #then inputs it into correct variable
403 BoughtItem = Shop(Weapon,Arm,Helm,Gold,Item1,Item2,Item3,Item4,Item5,Health,Level)
404 if BoughtItem == 50:
405 print("That isn't an option")
406 elif BoughtItem <13:
407 Gold -= 50
408 Weapon = BoughtItem
409 Level += 1
410 print("You have a new weapon")
411 elif BoughtItem == 20:
412 Armour = BoughtItem
413 Gold-=75
414 Level += 1
415 print("You addorn your new armour")
416 elif BoughtItem == 18:
417 Helm=BoughtItem
418 Gold -=25
419 Level += 1
420 print("You place the new helmet on your head; you feel protected.")
421 elif BoughtItem == 16:
422 if Item1 != 16:
423 Item1 = 16
424 Gold -=25
425 elif Item2 != 16:
426 Item2 = 16
427 Gold -=25
428 elif Item3 !=16:
429 Item3 = 16
430 Gold -=25
431 elif Item4 != 16:
432 Item4 = 16
433 Gold -=25
434 elif Item5 != 16:
435 Item5 = 16
436 Gold -=25
437 else:
438 print("ShopError")
439
440 elif PlayerOption =="9":
441 Leaving = True
442 elif Map[YCoord][XCoord] == "m":
443 print("You are stood on a great mountain")
444 elif Map[YCoord][XCoord] == "b":
445 print("This bridge can take you across the water")
446 elif Map[YCoord][XCoord] == "s":
447 print("Course sand sinks into your boots as you find yourself on a beach")
448 elif Map[YCoord][XCoord] == "d":
449 #this is the end of the game. if all items have been found then the final text will play.
450 if Weapon in range(12,16):
451 print("")
452 if Arm == 22:
453 if Helm == 21:
454 print("'You cannot best me, mortal.' Bellows the mighty dragon, \n'Your attempt at defeating me shall be your undoing!' \nAs the beast rears it's head to exhale a crackling fireball, \nit notices the light of your glowing tunic. \n'It cannot be!' he exclaims as he looses his fiery breath, 'you shall die!' \n\nAs you walk from the burning wreckage of the door that lay behind you, \nVex admits defeat. With the weapon of the ancient in hand the beast is \nstruck and reduced to a smoldering \npile of ash.\n\nThe land is saved. Thanks to you.")
455 x = int(input("\nOne last thing hero...\n\nWhat will you do now?\n\n\t1.Live the rest of my days in peace\n\t2.Go on to find a new adventure\n\t3.Now that the dragon is gone I am free to pilliage and plunder the land as its new ruler\n\n> "))
456 if x != 3:
457 print("That is most noble. For a second I thought that you were going to take over as the new protagonist.")
458 else:
459 print("After years of ruling with an iron fist the gold you stole from the dragon corrupts you and turns you into a large dragon. An adventurer comes, wearing your old armour, and kills you where you stand. You have become Vex.")
460 else:
461 print("You do not have the Holy Helmet")
462 else:
463 print("You do not have the Mighty Breastplate or the Holy Helmet")
464 else:
465 print("You are not ready to face the Dragon Vex")
466 elif Map[YCoord][XCoord] == "t":
467 print("You found a treasure chest.")
468
469 #tells the user what treasure they have found and then changes the treasure tile to plains.
470 #this stops the user from repetetively activating the treasure tile to cheat.
471 if Weapon != 12 + PlayerType:
472 Weapon = 12 + PlayerType
473 if PlayerType == 1:
474 print(UserName,"! You have found the Ancient Sword")
475 elif PlayerType ==2:
476 print(UserName,"! You have found the Ancient Bow")
477 elif PlayerType ==3:
478 print(UserName,"! You have found the Ancient Wand")
479
480 elif Arm != 22:
481 Arm = 22
482
483 print(UserName,"! You have found the Breastplate of Buttkicking")
484
485 elif Helm != 21:
486 Helm = 21
487
488 print(UserName,"! You have found the Holy Helmet")
489 Map[YCoord][XCoord] = "p"
490 else:
491 print("invalid")
492
493 #users interaction with the game is logged and the corresponding action takes place.
494
495 PlayerOption = input ("(n,e,s,w,save,inventory)\n> ")
496 while PlayerOption in ["Save", "save", "SAVE", "sAVE","inventory","INVENTORY","Inventory","iNVENTORY"]:
497 if PlayerOption in ["Save", "save", "SAVE", "sAVE"]:
498 Save(Userfile,Itemfile,UserName,Password,Level,PlayerType,Health,XCoord,YCoord,Gold,Helm,Arm,Weapon,Item1,Item2,Item3,Item4,Item5,Map)
499 PlayerOption = input ("(n,e,s,w)\n> ")
500 elif PlayerOption in ["inventory","INVENTORY","Inventory","iNVENTORY"]:
501 if Item1 == 0:
502 A = "Empty"
503 else:
504 A = "Health Potion"
505 if Item2 == 0:
506 B = "Empty"
507 else:
508 B = "Health Potion"
509 if Item3 == 0:
510 C = "Empty"
511 else:
512 C = "Health Potion"
513 if Item4 == 0:
514 D = "Empty"
515 else:
516 D = "Health Potion"
517 if Item5 == 0:
518 E = "Empty"
519 else:
520 E = "Health Potion"
521
522 Weapon = int(Weapon)
523 Arm = int(Arm)
524 Helm = int(Helm)
525 #load inventory.
526 while True:
527 try:
528 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Weapon,))
529
530 Place = 0
531 Gear = ITEM.fetchone()
532 ItemData = ["","","","",""]
533
534 for G in Gear:
535 ItemData[Place] = G
536 Place += 1
537
538 WeaponName = ItemData[1]
539 break
540 except:
541 print("Weapon Error Bug!")
542
543 while True:
544 try:
545 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Arm,))
546
547 Place = 0
548 Gear = ITEM.fetchone()
549 ItemData = ["","","","",""]
550
551 for G in Gear:
552 ItemData[Place] = G
553 Place += 1
554
555 ArmName = ItemData[1]
556 break
557 except:
558 print("Armour Bug!")
559
560 while True:
561 try:
562 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Helm,))
563
564 Place = 0
565 Gear = ITEM.fetchone()
566 ItemData = ["","","","",""]
567
568 for G in Gear:
569 ItemData[Place] = G
570 Place += 1
571
572 HelmName = ItemData[1]
573 break
574 except:
575 print("Helmet Bug")
576
577 print("\n\nCurrent Inventory:\n##################\n\t1.",A,"\n\t2.",B,"\n\t3.",C,"\n\t4.",D,"\n\t5.",E,"\n\nHealth:",Health,"Max Health:",(10+(Level*2)),"\nGold:",Gold,"\n\nHelmet:",HelmName,"\nArmour:",ArmName,"\nWeapon:",WeaponName)
578 PlayerOption = input ("(n,e,s,w)\n> ")
579
580 if (PlayerOption in ["n","N"]) and (Map[YCoord-1][XCoord]!= "w"):
581 YCoord -= 1
582 print("You travelled North")
583 elif (PlayerOption in ["E","e"]) and (Map[YCoord][XCoord+1]!= "w"):
584 XCoord += 1
585 print("You travelled East")
586 elif (PlayerOption in ["s","S"]) and (Map[YCoord+1][XCoord]!="w"):
587 YCoord += 1
588 print("You travelled South")
589 elif (PlayerOption in ["W","w"]) and (Map[YCoord][XCoord-1]!="w"):
590 XCoord -= 1
591 print("You travelled West")
592 else:
593 print("Invalid")
594
595
596
597 battle = random.randint(1,20)
598 if battle == 1:
599 Health = Battle(UserName,Health,Weapon,Arm,Helm,Item1,Item2,Item3,Item4,Item5,Level,Gold)
600 if Health <= 0:
601 print("You Died!")
602 Main()
603 else:
604 Loot = random.randint(5,20)
605 print("You found",Loot,"Gold on the body")
606 Gold += Loot
607
608
609
610
611
612def Save(Userfile,Itemfile,UserName,Password,Level,PlayerType,Health,XCoord,YCoord,Gold,Helm,Arm,Weapon,Item1,Item2,Item3,Item4,Item5,Map):
613 #opens items from inventory into Items variables for storing.
614
615 MapData=""
616
617 Count = 0
618
619 #sets the data from Map lists into a single string
620 for y in range(20):
621 MapRow = []
622 for x in range(20):
623 MapData += Map[y][x]
624
625 USER.execute("UPDATE Users SET Lvl = ?, Money = ?, HP = ?, X = ?, Y = ?, Arm = ?, Helm = ?, Weapon = ?, Item1 = ?, Item2 = ?, Item3 = ?, Item4 = ?, Item5 = ?, Map = ? WHERE Name = ? ",(Level,Gold,Health,XCoord,YCoord,Arm,Helm,Weapon,Item1,Item2,Item3,Item4,Item5,MapData,UserName,))
626 Userfile.commit()
627
628 #requests continuation
629 print("sucesfsful save")
630 print("Continue?")
631 PlayerOption = input("> ")
632 if PlayerOption in ["no","n","N","NO","No","nO"]:
633 Main()
634
635
636
637def Inn(Gold):
638 #user entered the Inn
639 print("Welcome to the Inn Child")
640 print("Do you wish to stay the night for 5 Gold?")
641 print("\nGold:",Gold)
642 InnOption = input("> ")
643 while InnOption not in ["y","Y","Yes","yES","YES","yes","n","N","No","nO","NO","no"]:
644 if InnOption in ["y","Y","Yes","yES","YES","yes"]:
645 if Gold < 5:
646 print("You don't appear to be able to afford the room.")
647 else:
648 Gold -= 5
649 print("Have a nice night!")
650 else:
651 print("What was that?")
652 innOption = ("> ")
653
654 return Gold
655
656
657def Shop(Weapon,Arm,Helm,Gold,Item1,Item2,Item3,Item4,Item5,Health,Level):
658
659 #opens the items that are better and all potions
660 print("Welcome to the shop")
661
662
663 Itemfile = sqlite3.connect("Items.db")
664 ITEM = Itemfile.cursor()
665
666 full = False
667 #checks if the Players inventory is full
668 if Item1 != 0 and Item2 != 0 and Item3 != 0 and Item4 != 0 and Item5 != 0:
669 full = True
670
671 #maximum buying weapons are 4th Tier so Max is 9+3
672 if Weapon < 10:
673 SaleWeapon = Weapon + 3
674 else:
675 SaleWeapon = 50
676 if Arm == 19:
677 SaleArm = 20
678 else:
679 SaleArm = 50
680 if Helm == 17:
681 SaleHelm = 18
682 else:
683 SaleHelm = 50
684 SalePotion = 16
685
686 Place = 0
687 #seeing what the next weapon or armour above the current is.
688 if SaleWeapon != 50:
689 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(SaleWeapon,))
690 WeaponSaleList = ITEM.fetchone()
691 for x in WeaponSaleList:
692 if Place == 1:
693 WeaponName = x
694 Place += 1
695 Place = 0
696
697 if SaleArm != 50:
698 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(SaleArm,))
699 ArmourSaleList = ITEM.fetchone()
700 for x in ArmourSaleList:
701 if Place ==1:
702 ArmourName = x
703 Place += 1
704 Place = 0
705
706 if SaleHelm != 50:
707 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(SaleHelm,))
708 HelmetSaleList = ITEM.fetchone()
709 for x in HelmetSaleList:
710 if Place == 1:
711 HelmetName = x
712 Place += 1
713
714
715 #prints list where if there is not weapon or armour above the current it will print that it is out of stock.
716 if SaleWeapon != 50:
717 print("\n1.",WeaponName,"-50 Gold")
718 else:
719 print("1. Out of Stock")
720 if SaleArm != 50:
721 print("2.",ArmourName,"-75 Gold")
722 else:
723 print("2.Out of Stock")
724 if SaleHelm != 50:
725 print("3.",HelmetName,"-25 Gold")
726 else:
727 print("3. Out of Stock")
728 print("4. Healing Potion -25 Gold")
729 print("9. Exit Shop")
730 print("\nYou own",Gold,"Gold")
731
732 if Item1 == 0:
733 A = "Empty"
734 else:
735 A = "Health Potion"
736 if Item2 == 0:
737 B = "Empty"
738 else:
739 B = "Health Potion"
740 if Item3 == 0:
741 C = "Empty"
742 else:
743 C = "Health Potion"
744 if Item4 == 0:
745 D = "Empty"
746 else:
747 D = "Health Potion"
748 if Item5 == 0:
749 E = "Empty"
750 else:
751 E = "Health Potion"
752
753 Weapon = int(Weapon)
754 Arm = int(Arm)
755 Helm = int(Helm)
756
757 while True:
758 try:
759 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Weapon,))
760
761 Place = 0
762 Gear = ITEM.fetchone()
763 ItemData = ["","","","",""]
764
765 for G in Gear:
766 ItemData[Place] = G
767 Place += 1
768
769 WeaponName = ItemData[1]
770 break
771 except:
772 print("Weapon Error Bug!")
773
774 while True:
775 try:
776 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Arm,))
777
778 Place = 0
779 Gear = ITEM.fetchone()
780 ItemData = ["","","","",""]
781
782 for G in Gear:
783 ItemData[Place] = G
784 Place += 1
785
786 ArmName = ItemData[1]
787 break
788 except:
789 print("Armour Bug!")
790
791 while True:
792 try:
793 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Helm,))
794
795 Place = 0
796 Gear = ITEM.fetchone()
797 ItemData = ["","","","",""]
798
799 for G in Gear:
800 ItemData[Place] = G
801 Place += 1
802 HelmName = ItemData[1]
803 break
804 except:
805 print("Helmet Bug")
806
807 print("\n\nCurrent Inventory:\n##################\n\t1.",A,"\n\t2.",B,"\n\t3.",C,"\n\t4.",D,"\n\t5.",E,"\n\nHealth:",Health,"Max Health:",(10+(Level*2)),"\nGold:",Gold,"\n\nHelmet:",HelmName,"\nArmour:",ArmName,"\nWeapon:",WeaponName)
808
809
810 PlayerOption = input("> ")
811 while PlayerOption not in ["1","2","3","4","9"]:
812 print("What was that?")
813 PlayerOption = input("> ")
814
815 if PlayerOption == "1" and SaleWeapon != 50 and Gold>=50:
816 Gold -= 50
817 SoldItem = SaleWeapon
818 elif PlayerOption == "2" and SaleArm != 50 and Gold >= 75:
819 Gold -= 75
820 SoldItem = SaleArm
821 elif PlayerOption == "3" and SaleHelm != 50 and Gold >=25:
822 Gold -= 25
823 SoldItem = SaleHelm
824 elif PlayerOption == "4" and full == False and Gold >= 25:
825 Gold -= 25
826 SoldItem = 16
827 elif PlayerOption == "9":
828 print()
829 SoldItem = 50
830 else:
831 SoldItem = 50
832
833 return SoldItem
834
835#battle function
836def Battle(UserName,Health,Weapon,Arm,Helm,Item1,Item2,Item3,Item4,Item5,Level,Gold):
837 #Random addition on every attack
838
839 Monsterfile = sqlite3.connect("Monsters.db")
840 MONSTER = Monsterfile.cursor()
841
842 Itemfile = sqlite3.connect("Items.db")
843 ITEM = Itemfile.cursor()
844
845 inventory= [Item1,Item2,Item3,Item4,Item5]
846 Weapon = int(Weapon)
847 #data from the player file is used to gain further data about their gear and/or stats
848 #data about monsters is also gained.
849 while True:
850 try:
851 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Weapon,))
852
853 Place = 0
854 Gear = ITEM.fetchone()
855 ItemData = ["","","","",""]
856
857 for G in Gear:
858 ItemData[Place] = G
859 Place += 1
860
861 Buff = ItemData[2]
862 break
863 except:
864 print("Weapon Error Bug!")
865 print("Error Error\n\nline640 ish")
866 while True:
867 try:
868 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Arm,))
869
870 Place = 0
871 Gear = ITEM.fetchone()
872 ItemData = ["","","","",""]
873
874 for G in Gear:
875 ItemData[Place] = G
876 Place += 1
877
878 AC = 0
879 AC += ItemData[2]
880 break
881 except:
882 print("Armour Bug!")
883
884 while True:
885 try:
886 ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Helm,))
887
888 Place = 0
889 Gear = ITEM.fetchone()
890 ItemData = ["","","","",""]
891
892 for G in Gear:
893 ItemData[Place] = G
894 Place += 1
895
896 AC += ItemData[2]
897 break
898 except:
899 print("Helmet Bug")
900
901 LoadMonster=["","","",""]
902
903 M = random.randint(1,10)
904 while True:
905 try:
906 MONSTER.execute("SELECT * FROM Monsters WHERE Id = ?",(M,))
907
908 Load = MONSTER.fetchone()
909 Place = 0
910
911 for x in Load:
912 LoadMonster[Place] = x
913 Place += 1
914
915 MonsterName = LoadMonster[1]
916 MonsterHealth = LoadMonster[2]
917 MonsterAtk = LoadMonster[3]
918 break
919 except:
920 print("Monster Bug!")
921
922 #begin battle sequence
923 Intro = random.randint(1,3)
924
925 if Intro ==1:
926 print(UserName," stop! A ",MonsterName," is aproaching!")
927 elif Intro ==2:
928 print("That ",MonsterName," looks like it is about to charge... Prepare to fight!")
929 elif Intro ==3:
930 print("It's an ambush! Kill the ",MonsterName,"!")
931
932 print("[In a Battle type the action you wish to perform (attack, blast, shoot etc.) or the number of the item you wish to use from your inventory]")
933 print("What will you do?")
934 while Health > 0 and MonsterHealth > 0:
935 moved = False
936 print("\nATK",Buff)
937 print("DEF",AC)
938 print("\nHP:",Health)
939 while not moved:
940 PlayerOption = input("\n> ")
941 Addition = random.randint(-2,+2)
942 chance = random.randint(1,20)
943 if (PlayerOption in ["attack","hit","smack","shoot","fire","kill","zap","loose","throw","chuck","blast","slice","cut","stab","finish","hug"]) and (8 < chance < 20):
944 MonsterHealth -= (Buff + Addition)
945 moved = True
946 #calculates damage output
947 print("\nYou did",(Buff + Addition),"damage to the",MonsterName)
948 elif PlayerOption in ["1","2","3","4","5"]:
949 #seeing if user has potions to use
950 if inventory[int(PlayerOption-1)] == 0:
951 print("You have no Potions in that slot")
952 else:
953 Health += 5
954 if Health > 10+(Level*2):
955 Health = 10 +(Level*2)
956 inventory[int(PlayerOption-1)] = 0
957
958 moved = True
959 elif (PlayerOption in ["attack","hit","smack","shoot","fire","kill","zap","loose","throw","chuck","blast","slice","cut","stab","finish","hug"]) and(chance==20):
960 #critical hit
961 MonsterHealth -=(Buff*2 + Addition)
962 moved = True
963 print("\nCritical Hit!")
964 print("You did",(Buff + Addition),"damage to the",MonsterName)
965 elif (PlayerOption in ["attack","hit","smack","shoot","fire","kill","zap","loose","throw","chuck","blast","slice","cut","stab","finish","hug"]):
966 #miss
967 print("You missed!")
968 moved = True
969 else:
970 print("That's not an action you can make.")
971
972 Addition = random.randint(-5,+1)
973 chance = random.randint(1,20)
974 Damage = MonsterAtk + Addition
975 #monster attack
976 if Damage<0:
977 Damage=0
978 if AC < chance and MonsterHealth > 0:
979 Health -= Damage
980 print("The",MonsterName,"did",Damage,"damage to you!")
981 else:
982 print("The",MonsterName,"missed!")
983
984
985
986 if Health <= 0:
987 if inventory[0] == 16:
988 Health = 10 +(Level*2)
989 print("I just gave Healthyou a potion becuase otherwise you would've died.")
990 inventory[0] = 0
991 elif inventory[1] == 16:
992 Health = 10 +(Level*2)
993 print("I just gave you a potion becuase otherwise you would've died.")
994 inventory[1] = 0
995 elif inventory[2] == 16:
996 Health = 10 +(Level*2)
997 print("I just gave you a potion becuase otherwise you would've died.")
998 inventory[2] = 0
999 elif inventory[3] == 16:
1000 Health = 10 +(Level*2)
1001 print("I just gave you a potion becuase otherwise you would've died.")
1002 inventory[3] = 0
1003 elif inventory[4] == 16:
1004 Health = 10 +(Level*2)
1005 print("I just gave you a potion becuase otherwise you would've died.")
1006 inventory[4] = 0
1007 else:
1008 print("You died, do you wish to continue?(y/n)")
1009 PlayerOption = input("> ")
1010 if PlayerOption in ["y","Y","Yes","YES","yes","yES"]:
1011 Loadgame(Userfile, USER, LoadArray)
1012
1013
1014 return Health
1015
1016Map = []
1017Count = 0
1018
1019for Row in range(20):
1020 MapRow = []
1021 for Column in range(20):
1022 MapRow.append(MapData[Count])
1023 Count+=1
1024 Map.append(MapRow)
1025
1026Running = True
1027while Running:
1028 if Main() == 1 :
1029 Loadgame()
1030 elif Main() == 2 :
1031 Newgame()
1032 PlayGame()
1033 elif Main() ==3:
1034 Leadboard()
1035 elif Main() == 9:
1036 exit