Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Another Text Adventure
- #Author: Josh Scott
- #Version 1.0.1
- #imports time
- import time
- #allows for random functions
- import random
- #allows SQL actions
- import sqlite3
- #this is the library used for claering the brackets from the leaderboard.
- import itertools
- MapData="wwwwwwwwwwwwwwwwwwwwwwffffffffpsvswwwwwwwfftffffffppsssswwwwwffffffffpppwwwwwwwwwffffffpppppwtppbbswwfffffppppppwppwwsswwffffpppppppwwwwsspwwppppppppbppwppppppwwvpppppwwbwwwppppmpwwwwwwwwwpbpppppppmmwwpppppppppppppppmmmwwpppppppvpppppppmmmwwmmppppppppppppppppwwmmmmmmmmmpppvmmpppwwmmmmmmmmmpmmmmmmmpwwmmmdmmmmppmmmmmmmmwwwmmmmmmmpppmmmmmmmwwwmmmmmmppppppmmmmwwwwwmmmmpppppppptwwwwwwwwwwwwwwwwwwwwwwww"
- LoadArray = ["","","","","","","","","","","","","","","","","",""]
- #access of the files made global
- Userfile = sqlite3.connect("Users.db")
- USER = Userfile.cursor()
- Itemfile = sqlite3.connect("Items.db")
- ITEM = Itemfile.cursor()
- Monsterfile = sqlite3.connect("Monsters.db")
- MONSTER = Monsterfile.cursor()
- print("")
- print(" █████╗ ███╗ ██╗ ██████╗ ████████╗██╗ ██╗███████╗██████╗ ")
- print(" ██╔══██╗████╗ ██║██╔═══██╗╚══██╔══╝██║ ██║██╔════╝██╔══██╗ ")
- print(" ███████║██╔██╗ ██║██║ ██║ ██║ ███████║█████╗ ██████╔╝ ")
- print(" ██╔══██║██║╚██╗██║██║ ██║ ██║ ██╔══██║██╔══╝ ██╔══██╗ ")
- print(" ██║ ██║██║ ╚████║╚██████╔╝ ██║ ██║ ██║███████╗██║ ██║ ")
- print(" ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ")
- time.sleep(.5)
- print(" ")
- print(" ████████╗███████╗██╗ ██╗████████╗ ")
- print(" ╚══██╔══╝██╔════╝╚██╗██╔╝╚══██╔══╝ ")
- print(" ██║ █████╗ ╚███╔╝ ██║ ")
- print(" ██║ ██╔══╝ ██╔██╗ ██║ ")
- print(" ██║ ███████╗██╔╝ ██╗ ██║ ")
- print(" ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ")
- time.sleep(.5)
- print(" ")
- print(" █████╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗████████╗██╗ ██╗██████╗ ███████╗")
- print(" ██╔══██╗██╔══██╗██║ ██║██╔════╝████╗ ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝")
- print(" ███████║██║ ██║██║ ██║█████╗ ██╔██╗ ██║ ██║ ██║ ██║██████╔╝█████╗ ")
- print(" ██╔══██║██║ ██║╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║ ██║ ██║██╔══██╗██╔══╝ ")
- print(" ██║ ██║██████╔╝ ╚████╔╝ ███████╗██║ ╚████║ ██║ ╚██████╔╝██║ ██║███████╗")
- print(" ╚═╝ ╚═╝╚═════╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝")
- time.sleep(1)
- #main menu
- def Main():
- PlayerOption = "4"
- while PlayerOption not in["1","2","3","9"]:
- print("\n\nMain Menu")
- print("")
- print("1. Load Game")
- print("2. New Game")
- print("3. Leader Board")
- print("9. Quit")
- print("")
- PlayerOption = input("> ")
- print("")
- if PlayerOption == ("1"):
- Loadgame(Userfile, USER,LoadArray)
- elif PlayerOption == ("2"):
- Newgame(Userfile, USER, LoadArray)
- elif PlayerOption == ("3"):
- Leaderboard(Userfile,USER,LoadArray)
- elif PlayerOption == ("9"):
- exit()
- #loading an already saved game
- def Loadgame(Userfile, USER, LoadArray):
- MapData="wwwwwwwwwwwwwwwwwwwwwwffffffffpssswwwwwwwfftffffffppsssswwwwwffffffffpppwwwwwwwwwffffffpppppwtppbbswwfffffppppppwppwwsswwffffpppppppwwwwsspwwppppppppbppwppppppwwvpppppwwbwwwppppmpwwwwwwwwwpbpppppppmmwwpppppppppppppppmmmwwpppppppppppppppmmmwwmmppppppppppppppppwwmmmmmmmmmpppvmmpppwwmmmmmmmmmpmmmmmmmpwwmmmdmmmmppmmmmmmmmwwwmmmmmmmpppmmmmmmmwwwmmmmmmppppppmmmmwwwwwmmmmpppppppptwwwwwwwwwwwwwwwwwwwwwwww"
- UserName = ""
- while UserName == "":
- UserName = input("What is your name?\n> ")
- print("Ah yes and what was our password?")
- UserPass = ""
- while UserPass == "":
- UserPass = input("> ")
- NoExist = True
- while NoExist == True:
- try:
- #checking if the Username is already in use
- #if the name cannot be found the program will break and run into the 'except' section
- 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,))
- Load = USER.fetchone()
- Place = 0
- for x in Load:
- LoadArray[Place] = x
- Place += 1
- ID = LoadArray[0]
- UserName = LoadArray[1]
- Password = LoadArray[2]
- Level = LoadArray[3]
- PlayerType = LoadArray[4]
- Health = LoadArray[5]
- XCoord = LoadArray[6]
- YCoord = LoadArray[7]
- Gold = LoadArray[8]
- Helm = LoadArray[9]
- Arm = LoadArray[10]
- Weapon = LoadArray[11]
- Item1 = LoadArray[12]
- Item2 = LoadArray[13]
- Item3 = LoadArray[14]
- Item4 = LoadArray[15]
- Item5 = LoadArray[16]
- MapData = LoadArray[17]
- Count = 0
- for Row in range(20):
- MapRow = []
- for Column in range(20):
- MapRow.append(MapData[Count])
- Count+=1
- Map.append(MapRow)
- #at this point username exists.
- if UserPass == Password:
- NoExist = False
- PlayGame(UserName,Password,Level,PlayerType,Health,XCoord,YCoord,Gold,Helm,Arm,Weapon,Item1,Item2,Item3,Item4,Item5,Map)
- else:
- print("I know of nobody by that name friend.")
- print("What is your real name?")
- UserName = input("> ")
- UserPass = input("And your password?\n> ")
- except:
- print("I know of nobody by that name friend.")
- print("What is your real name?")
- UserName = input("> ")
- UserPass = input("And your password?\n> ")
- #creating a new save file
- def Newgame(Userfile, USER, LoadArray):
- print("What is your name traveller?")
- UserName = ""
- while UserName == "":
- UserName = input("> ")
- AlreadyUsed = True
- while AlreadyUsed == True:
- try:
- #checking if the Username is already in use
- #if the name cannot be found the program will break and run into the 'except' section
- 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,))
- Load = USER.fetchone()
- Place = 0
- for x in Load:
- LoadArray[Place] = x
- Place += 1
- ID = LoadArray[0]
- UserName = LoadArray[1]
- Password = LoadArray[2]
- Level = LoadArray[3]
- PlayerType = LoadArray[4]
- Health = LoadArray[5]
- XCoord = LoadArray[6]
- YCoord = LoadArray[7]
- Gold = LoadArray[8]
- Helm = LoadArray[9]
- Arm = LoadArray[10]
- Weapon = LoadArray[11]
- Item1 = LoadArray[12]
- Item2 = LoadArray[13]
- Item3 = LoadArray[14]
- Item4 = LoadArray[15]
- Item5 = LoadArray[16]
- MapData = LoadArray[17]
- Count = 0
- print("I already know someone by that name.")
- UserName = input("What is your name traveller?\n> ")
- except:
- 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")
- PlayerType = int(input("> "))
- while PlayerType not in (1,2,3):
- print("invalid Choice")
- PlayerType = int(input("> "))
- 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]")
- PlayerOption = input("> ")
- if PlayerOption in ["y", "Y", "Yes", "YES", "yes"]:
- print("Good")
- else:
- while PlayerOption not in ["y", "Y", "Yes", "YES", "yes"]:
- x = random.randint(1,3)
- if x == 1:
- print("Please?")
- elif x == 2:
- print("Pretty Please?")
- elif x == 3:
- print("But you're the Hero!")
- else:
- print("loop Error")
- PlayerOption = input("> ")
- print("Now, for when we next meet we should have a password to make sure you are who you say you are.")
- print("PASSWORD:")
- Password1 = input("> ")
- print("I’m a smidge deaf in that ear. Once more?")
- Password2 = input("> ")
- while Password1 != Password2:
- print("Those two weren't the same. \nTry again")
- Password1 = input("> ")
- print("One more time")
- Password2 = input("> ")
- Password = Password1
- Health = 10
- Level = 1
- Gold = 5
- Weapon = 0
- XCoord = 1
- YCoord = 8
- #creating the table for the players if on a new system
- NewTable = """
- CREATE TABLE IF NOT EXISTS Users(
- ID INTEGER PRIMARY KEY,
- Name VARCHAR (20),
- Pass VARCHAR(20),
- Lvl INTEGER,
- Type INTEGER,
- HP INTEGER,
- X INTEGER,
- Y INTEGER,
- Money INTEGER,
- Helm INTEGER,
- Arm INTEGER,
- Weapon INTEGER,
- Item1 INTEGER,
- Item2 INTEGER,
- Item3 INTEGER,
- Item4 INTEGER,
- Item5 INTEGER,
- Map VARCHAR (400),
- FOREIGN KEY(Helm)REFERENCES Items(Id),
- FOREIGN KEY(Arm)REFERENCES Items(Id),
- FOREIGN KEY(Weapon)REFERENCES Items(Id),
- FOREIGN KEY(Item1)REFERENCES Items(Id),
- FOREIGN KEY(Item2)REFERENCES Items(Id),
- FOREIGN KEY(Item3)REFERENCES Items(Id),
- FOREIGN KEY(Item4)REFERENCES Items(Id),
- FOREIGN KEY(Item5)REFERENCES Items(Id));"""
- USER.execute(NewTable)
- #save function with placeholder data
- insert= """
- INSERT INTO Users(Name,Pass,Lvl,Type,HP,X,Y,Money,Helm,Arm,Weapon,Map,Item1,Item2,Item3,Item4,Item5)
- VALUES("PLACEHOLDER","PLACEHOLDER",1,0,10,1,8,50,17,19,0,"wwwwwwwwwwwwwwwwwwwwwwffffffffpssswwwwwwwfftffffffppsssswwwwwffffffffpppwwwwwwwwwffffffpppppwtppbbswwfffffppppppwppwwsswwffffpppppppwwwwsspwwppppppppbppwppppppwwvpppppwwbwwwppppmpwwwwwwwwwpbpppppppmmwwpppppppppppppppmmmwwpppppppppppppppmmmwwmmppppppppppppppppwwmmmmmmmmmpppvmmpppwwmmmmmmmmmpmmmmmmmpwwmmmdmmmmppmmmmmmmmwwwmmmmmmmpppmmmmmmmwwwmmmmmmppppppmmmmwwwwwmmmmpppppppptwwwwwwwwwwwwwwwwwwwwwwww",0,0,0,0,0)"""
- USER.execute(insert)
- USER.execute ("SELECT * FROM Users ")
- #saving over the placeholders
- USER.execute("UPDATE Users SET Name = ? WHERE Name = 'PLACEHOLDER' ",(UserName,))
- USER.execute("UPDATE Users SET Pass = ? WHERE Pass = 'PLACEHOLDER' ",(Password,))
- USER.execute("UPDATE Users SET Type = ? WHERE Type = 0 ",(PlayerType,))
- USER.execute("UPDATE Users SET Weapon = ? WHERE Weapon = 0 ",(PlayerType,))
- Userfile.commit()
- AlreadyUsed = False
- def Leaderboard(Userfile,USER,LoadArray):
- #print leader board after sorting
- Place = 0
- Scorelist = []
- Namelist = []
- Score = ""
- Name = ""
- USER.execute("SELECT u.ID FROM Users u")
- #loading data from table into separate arrays until end of list
- Length = len(USER.fetchall())
- Length = int(Length)
- USER.execute('SELECT * FROM Users')
- #Fetches the data in the specified rows
- Userfile.row_factory = lambda USER, row: row[0]
- Scorelist = USER.execute('SELECT Money FROM Users').fetchall()
- Namelist = USER.execute('SELECT Name FROM Users').fetchall()
- Scorelist
- Namelist
- #Bubblesort function
- #Grade A Algorithm
- for passnum in range(abs(Length)-1):
- i = 0
- for i in range(abs(Length)-1):
- if Scorelist[i]<Scorelist[i+1]:
- tempScore = Scorelist[i]
- tempName = Namelist[i]
- Scorelist[i] = Scorelist[i+1]
- Namelist[i] = Namelist[i+1]
- Scorelist[i+1] = tempScore
- Namelist[i+1] = tempName
- passnum += 1
- #Bubblesort complete
- #removes brackets from the named lists
- Names = list(itertools.chain.from_iterable(Namelist))
- Scores = list(itertools.chain.from_iterable(Scorelist))
- x=0
- while x<abs(Length):
- print("\t",(x+1),".",Names[x]," \t ",Scores[x])
- x+=1
- Main()
- #main game section
- def PlayGame(UserName,Password,Level,PlayerType,Health,XCoord,YCoord,Gold,Helm,Arm,Weapon,Item1,Item2,Item3,Item4,Item5,Map):
- Map = []
- Count = 0
- Itemfile = sqlite3.connect("Items.db")
- ITEM = Itemfile.cursor()
- for Row in range(20):
- MapRow = []
- for Column in range(20):
- MapRow.append(MapData[Count])
- Count+=1
- Map.append(MapRow)
- print("Welcome to the game,",UserName,". To travel enter in a direction type: N = North, E = East, S = South, W = West) Find The Relics!")
- while Running:
- #every 5 turns the user's health will increase by 1 until it is at it's maximum.
- if Health < 10+(Level*2):
- Health += 1
- #checks the map tile to determine what landscape the user is on.
- if Map[YCoord][XCoord] == "p":
- print("The plains span across the land before you")
- elif Map[YCoord][XCoord] == "f":
- print("A thick forest looms over you")
- elif Map[YCoord][XCoord] == "v":
- print("You enter a small villiage")
- Leaving = False
- while not Leaving:
- PlayerOption = input("Do you wish to visit:\n\t1.The Inn\n\t2.The Shop\n\t9.Leave\n> ")
- if PlayerOption == "1":
- NewGold = Inn(Gold)
- if NewGold < Gold:
- Health = 10 + (Level*2)
- Gold = NewGold
- elif PlayerOption == "2":
- #ensures that the data from the shop isn't incorrect
- #then inputs it into correct variable
- BoughtItem = Shop(Weapon,Arm,Helm,Gold,Item1,Item2,Item3,Item4,Item5,Health,Level)
- if BoughtItem == 50:
- print("That isn't an option")
- elif BoughtItem <13:
- Gold -= 50
- Weapon = BoughtItem
- Level += 1
- print("You have a new weapon")
- elif BoughtItem == 20:
- Armour = BoughtItem
- Gold-=75
- Level += 1
- print("You addorn your new armour")
- elif BoughtItem == 18:
- Helm=BoughtItem
- Gold -=25
- Level += 1
- print("You place the new helmet on your head; you feel protected.")
- elif BoughtItem == 16:
- if Item1 != 16:
- Item1 = 16
- Gold -=25
- elif Item2 != 16:
- Item2 = 16
- Gold -=25
- elif Item3 !=16:
- Item3 = 16
- Gold -=25
- elif Item4 != 16:
- Item4 = 16
- Gold -=25
- elif Item5 != 16:
- Item5 = 16
- Gold -=25
- else:
- print("ShopError")
- elif PlayerOption =="9":
- Leaving = True
- elif Map[YCoord][XCoord] == "m":
- print("You are stood on a great mountain")
- elif Map[YCoord][XCoord] == "b":
- print("This bridge can take you across the water")
- elif Map[YCoord][XCoord] == "s":
- print("Course sand sinks into your boots as you find yourself on a beach")
- elif Map[YCoord][XCoord] == "d":
- #this is the end of the game. if all items have been found then the final text will play.
- if Weapon in range(12,16):
- print("")
- if Arm == 22:
- if Helm == 21:
- 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.")
- 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> "))
- if x != 3:
- print("That is most noble. For a second I thought that you were going to take over as the new protagonist.")
- else:
- 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.")
- else:
- print("You do not have the Holy Helmet")
- else:
- print("You do not have the Mighty Breastplate or the Holy Helmet")
- else:
- print("You are not ready to face the Dragon Vex")
- elif Map[YCoord][XCoord] == "t":
- print("You found a treasure chest.")
- #tells the user what treasure they have found and then changes the treasure tile to plains.
- #this stops the user from repetetively activating the treasure tile to cheat.
- if Weapon != 12 + PlayerType:
- Weapon = 12 + PlayerType
- if PlayerType == 1:
- print(UserName,"! You have found the Ancient Sword")
- elif PlayerType ==2:
- print(UserName,"! You have found the Ancient Bow")
- elif PlayerType ==3:
- print(UserName,"! You have found the Ancient Wand")
- elif Arm != 22:
- Arm = 22
- print(UserName,"! You have found the Breastplate of Buttkicking")
- elif Helm != 21:
- Helm = 21
- print(UserName,"! You have found the Holy Helmet")
- Map[YCoord][XCoord] = "p"
- else:
- print("invalid")
- #users interaction with the game is logged and the corresponding action takes place.
- PlayerOption = input ("(n,e,s,w,save,inventory)\n> ")
- while PlayerOption in ["Save", "save", "SAVE", "sAVE","inventory","INVENTORY","Inventory","iNVENTORY"]:
- if PlayerOption in ["Save", "save", "SAVE", "sAVE"]:
- Save(Userfile,Itemfile,UserName,Password,Level,PlayerType,Health,XCoord,YCoord,Gold,Helm,Arm,Weapon,Item1,Item2,Item3,Item4,Item5,Map)
- PlayerOption = input ("(n,e,s,w)\n> ")
- elif PlayerOption in ["inventory","INVENTORY","Inventory","iNVENTORY"]:
- if Item1 == 0:
- A = "Empty"
- else:
- A = "Health Potion"
- if Item2 == 0:
- B = "Empty"
- else:
- B = "Health Potion"
- if Item3 == 0:
- C = "Empty"
- else:
- C = "Health Potion"
- if Item4 == 0:
- D = "Empty"
- else:
- D = "Health Potion"
- if Item5 == 0:
- E = "Empty"
- else:
- E = "Health Potion"
- Weapon = int(Weapon)
- Arm = int(Arm)
- Helm = int(Helm)
- #load inventory.
- while True:
- try:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Weapon,))
- Place = 0
- Gear = ITEM.fetchone()
- ItemData = ["","","","",""]
- for G in Gear:
- ItemData[Place] = G
- Place += 1
- WeaponName = ItemData[1]
- break
- except:
- print("Weapon Error Bug!")
- while True:
- try:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Arm,))
- Place = 0
- Gear = ITEM.fetchone()
- ItemData = ["","","","",""]
- for G in Gear:
- ItemData[Place] = G
- Place += 1
- ArmName = ItemData[1]
- break
- except:
- print("Armour Bug!")
- while True:
- try:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Helm,))
- Place = 0
- Gear = ITEM.fetchone()
- ItemData = ["","","","",""]
- for G in Gear:
- ItemData[Place] = G
- Place += 1
- HelmName = ItemData[1]
- break
- except:
- print("Helmet Bug")
- 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)
- PlayerOption = input ("(n,e,s,w)\n> ")
- if (PlayerOption in ["n","N"]) and (Map[YCoord-1][XCoord]!= "w"):
- YCoord -= 1
- print("You travelled North")
- elif (PlayerOption in ["E","e"]) and (Map[YCoord][XCoord+1]!= "w"):
- XCoord += 1
- print("You travelled East")
- elif (PlayerOption in ["s","S"]) and (Map[YCoord+1][XCoord]!="w"):
- YCoord += 1
- print("You travelled South")
- elif (PlayerOption in ["W","w"]) and (Map[YCoord][XCoord-1]!="w"):
- XCoord -= 1
- print("You travelled West")
- else:
- print("Invalid")
- battle = random.randint(1,20)
- if battle == 1:
- Health = Battle(UserName,Health,Weapon,Arm,Helm,Item1,Item2,Item3,Item4,Item5,Level,Gold)
- if Health <= 0:
- print("You Died!")
- Main()
- else:
- Loot = random.randint(5,20)
- print("You found",Loot,"Gold on the body")
- Gold += Loot
- def Save(Userfile,Itemfile,UserName,Password,Level,PlayerType,Health,XCoord,YCoord,Gold,Helm,Arm,Weapon,Item1,Item2,Item3,Item4,Item5,Map):
- #opens items from inventory into Items variables for storing.
- MapData=""
- Count = 0
- #sets the data from Map lists into a single string
- for y in range(20):
- MapRow = []
- for x in range(20):
- MapData += Map[y][x]
- 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,))
- Userfile.commit()
- #requests continuation
- print("sucesfsful save")
- print("Continue?")
- PlayerOption = input("> ")
- if PlayerOption in ["no","n","N","NO","No","nO"]:
- Main()
- def Inn(Gold):
- #user entered the Inn
- print("Welcome to the Inn Child")
- print("Do you wish to stay the night for 5 Gold?")
- print("\nGold:",Gold)
- InnOption = input("> ")
- while InnOption not in ["y","Y","Yes","yES","YES","yes","n","N","No","nO","NO","no"]:
- if InnOption in ["y","Y","Yes","yES","YES","yes"]:
- if Gold < 5:
- print("You don't appear to be able to afford the room.")
- else:
- Gold -= 5
- print("Have a nice night!")
- else:
- print("What was that?")
- innOption = ("> ")
- return Gold
- def Shop(Weapon,Arm,Helm,Gold,Item1,Item2,Item3,Item4,Item5,Health,Level):
- #opens the items that are better and all potions
- print("Welcome to the shop")
- Itemfile = sqlite3.connect("Items.db")
- ITEM = Itemfile.cursor()
- full = False
- #checks if the Players inventory is full
- if Item1 != 0 and Item2 != 0 and Item3 != 0 and Item4 != 0 and Item5 != 0:
- full = True
- #maximum buying weapons are 4th Tier so Max is 9+3
- if Weapon < 10:
- SaleWeapon = Weapon + 3
- else:
- SaleWeapon = 50
- if Arm == 19:
- SaleArm = 20
- else:
- SaleArm = 50
- if Helm == 17:
- SaleHelm = 18
- else:
- SaleHelm = 50
- SalePotion = 16
- Place = 0
- #seeing what the next weapon or armour above the current is.
- if SaleWeapon != 50:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(SaleWeapon,))
- WeaponSaleList = ITEM.fetchone()
- for x in WeaponSaleList:
- if Place == 1:
- WeaponName = x
- Place += 1
- Place = 0
- if SaleArm != 50:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(SaleArm,))
- ArmourSaleList = ITEM.fetchone()
- for x in ArmourSaleList:
- if Place ==1:
- ArmourName = x
- Place += 1
- Place = 0
- if SaleHelm != 50:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(SaleHelm,))
- HelmetSaleList = ITEM.fetchone()
- for x in HelmetSaleList:
- if Place == 1:
- HelmetName = x
- Place += 1
- #prints list where if there is not weapon or armour above the current it will print that it is out of stock.
- if SaleWeapon != 50:
- print("\n1.",WeaponName,"-50 Gold")
- else:
- print("1. Out of Stock")
- if SaleArm != 50:
- print("2.",ArmourName,"-75 Gold")
- else:
- print("2.Out of Stock")
- if SaleHelm != 50:
- print("3.",HelmetName,"-25 Gold")
- else:
- print("3. Out of Stock")
- print("4. Healing Potion -25 Gold")
- print("9. Exit Shop")
- print("\nYou own",Gold,"Gold")
- if Item1 == 0:
- A = "Empty"
- else:
- A = "Health Potion"
- if Item2 == 0:
- B = "Empty"
- else:
- B = "Health Potion"
- if Item3 == 0:
- C = "Empty"
- else:
- C = "Health Potion"
- if Item4 == 0:
- D = "Empty"
- else:
- D = "Health Potion"
- if Item5 == 0:
- E = "Empty"
- else:
- E = "Health Potion"
- Weapon = int(Weapon)
- Arm = int(Arm)
- Helm = int(Helm)
- while True:
- try:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Weapon,))
- Place = 0
- Gear = ITEM.fetchone()
- ItemData = ["","","","",""]
- for G in Gear:
- ItemData[Place] = G
- Place += 1
- WeaponName = ItemData[1]
- break
- except:
- print("Weapon Error Bug!")
- while True:
- try:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Arm,))
- Place = 0
- Gear = ITEM.fetchone()
- ItemData = ["","","","",""]
- for G in Gear:
- ItemData[Place] = G
- Place += 1
- ArmName = ItemData[1]
- break
- except:
- print("Armour Bug!")
- while True:
- try:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Helm,))
- Place = 0
- Gear = ITEM.fetchone()
- ItemData = ["","","","",""]
- for G in Gear:
- ItemData[Place] = G
- Place += 1
- HelmName = ItemData[1]
- break
- except:
- print("Helmet Bug")
- 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)
- PlayerOption = input("> ")
- while PlayerOption not in ["1","2","3","4","9"]:
- print("What was that?")
- PlayerOption = input("> ")
- if PlayerOption == "1" and SaleWeapon != 50 and Gold>=50:
- Gold -= 50
- SoldItem = SaleWeapon
- elif PlayerOption == "2" and SaleArm != 50 and Gold >= 75:
- Gold -= 75
- SoldItem = SaleArm
- elif PlayerOption == "3" and SaleHelm != 50 and Gold >=25:
- Gold -= 25
- SoldItem = SaleHelm
- elif PlayerOption == "4" and full == False and Gold >= 25:
- Gold -= 25
- SoldItem = 16
- elif PlayerOption == "9":
- print()
- SoldItem = 50
- else:
- SoldItem = 50
- return SoldItem
- #battle function
- def Battle(UserName,Health,Weapon,Arm,Helm,Item1,Item2,Item3,Item4,Item5,Level,Gold):
- #Random addition on every attack
- Monsterfile = sqlite3.connect("Monsters.db")
- MONSTER = Monsterfile.cursor()
- Itemfile = sqlite3.connect("Items.db")
- ITEM = Itemfile.cursor()
- inventory= [Item1,Item2,Item3,Item4,Item5]
- Weapon = int(Weapon)
- #data from the player file is used to gain further data about their gear and/or stats
- #data about monsters is also gained.
- while True:
- try:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Weapon,))
- Place = 0
- Gear = ITEM.fetchone()
- ItemData = ["","","","",""]
- for G in Gear:
- ItemData[Place] = G
- Place += 1
- Buff = ItemData[2]
- break
- except:
- print("Weapon Error Bug!")
- print("Error Error\n\nline640 ish")
- while True:
- try:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Arm,))
- Place = 0
- Gear = ITEM.fetchone()
- ItemData = ["","","","",""]
- for G in Gear:
- ItemData[Place] = G
- Place += 1
- AC = 0
- AC += ItemData[2]
- break
- except:
- print("Armour Bug!")
- while True:
- try:
- ITEM.execute("SELECT * FROM Items WHERE Id = ?",(Helm,))
- Place = 0
- Gear = ITEM.fetchone()
- ItemData = ["","","","",""]
- for G in Gear:
- ItemData[Place] = G
- Place += 1
- AC += ItemData[2]
- break
- except:
- print("Helmet Bug")
- LoadMonster=["","","",""]
- M = random.randint(1,10)
- while True:
- try:
- MONSTER.execute("SELECT * FROM Monsters WHERE Id = ?",(M,))
- Load = MONSTER.fetchone()
- Place = 0
- for x in Load:
- LoadMonster[Place] = x
- Place += 1
- MonsterName = LoadMonster[1]
- MonsterHealth = LoadMonster[2]
- MonsterAtk = LoadMonster[3]
- break
- except:
- print("Monster Bug!")
- #begin battle sequence
- Intro = random.randint(1,3)
- if Intro ==1:
- print(UserName," stop! A ",MonsterName," is aproaching!")
- elif Intro ==2:
- print("That ",MonsterName," looks like it is about to charge... Prepare to fight!")
- elif Intro ==3:
- print("It's an ambush! Kill the ",MonsterName,"!")
- 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]")
- print("What will you do?")
- while Health > 0 and MonsterHealth > 0:
- moved = False
- print("\nATK",Buff)
- print("DEF",AC)
- print("\nHP:",Health)
- while not moved:
- PlayerOption = input("\n> ")
- Addition = random.randint(-2,+2)
- chance = random.randint(1,20)
- if (PlayerOption in ["attack","hit","smack","shoot","fire","kill","zap","loose","throw","chuck","blast","slice","cut","stab","finish","hug"]) and (8 < chance < 20):
- MonsterHealth -= (Buff + Addition)
- moved = True
- #calculates damage output
- print("\nYou did",(Buff + Addition),"damage to the",MonsterName)
- elif PlayerOption in ["1","2","3","4","5"]:
- #seeing if user has potions to use
- if inventory[int(PlayerOption-1)] == 0:
- print("You have no Potions in that slot")
- else:
- Health += 5
- if Health > 10+(Level*2):
- Health = 10 +(Level*2)
- inventory[int(PlayerOption-1)] = 0
- moved = True
- elif (PlayerOption in ["attack","hit","smack","shoot","fire","kill","zap","loose","throw","chuck","blast","slice","cut","stab","finish","hug"]) and(chance==20):
- #critical hit
- MonsterHealth -=(Buff*2 + Addition)
- moved = True
- print("\nCritical Hit!")
- print("You did",(Buff + Addition),"damage to the",MonsterName)
- elif (PlayerOption in ["attack","hit","smack","shoot","fire","kill","zap","loose","throw","chuck","blast","slice","cut","stab","finish","hug"]):
- #miss
- print("You missed!")
- moved = True
- else:
- print("That's not an action you can make.")
- Addition = random.randint(-5,+1)
- chance = random.randint(1,20)
- Damage = MonsterAtk + Addition
- #monster attack
- if Damage<0:
- Damage=0
- if AC < chance and MonsterHealth > 0:
- Health -= Damage
- print("The",MonsterName,"did",Damage,"damage to you!")
- else:
- print("The",MonsterName,"missed!")
- if Health <= 0:
- if inventory[0] == 16:
- Health = 10 +(Level*2)
- print("I just gave Healthyou a potion becuase otherwise you would've died.")
- inventory[0] = 0
- elif inventory[1] == 16:
- Health = 10 +(Level*2)
- print("I just gave you a potion becuase otherwise you would've died.")
- inventory[1] = 0
- elif inventory[2] == 16:
- Health = 10 +(Level*2)
- print("I just gave you a potion becuase otherwise you would've died.")
- inventory[2] = 0
- elif inventory[3] == 16:
- Health = 10 +(Level*2)
- print("I just gave you a potion becuase otherwise you would've died.")
- inventory[3] = 0
- elif inventory[4] == 16:
- Health = 10 +(Level*2)
- print("I just gave you a potion becuase otherwise you would've died.")
- inventory[4] = 0
- else:
- print("You died, do you wish to continue?(y/n)")
- PlayerOption = input("> ")
- if PlayerOption in ["y","Y","Yes","YES","yes","yES"]:
- Loadgame(Userfile, USER, LoadArray)
- return Health
- Map = []
- Count = 0
- for Row in range(20):
- MapRow = []
- for Column in range(20):
- MapRow.append(MapData[Count])
- Count+=1
- Map.append(MapRow)
- Running = True
- while Running:
- if Main() == 1 :
- Loadgame()
- elif Main() == 2 :
- Newgame()
- PlayGame()
- elif Main() ==3:
- Leadboard()
- elif Main() == 9:
- exit
Add Comment
Please, Sign In to add comment