Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Text Dungeon Game
- # Zachary Privee 2024
- '''
- To-Do List
- - Level up point gain
- '''
- # Imports
- import os, random, time
- pName = "PLAYER"
- pHealth = 20
- pMana = 20
- # Max Health, Max Mana, Attack, Agility, Defense
- playerStats = [20, 20, 1, 1, 1]
- pExp = 100
- levelUpPts = 0
- pLevel = 1
- spellList = ["Fireball", "Heal", "Barrier"]
- itemNames = ["Health Potion", "Mana Potion", "Gold"]
- itemAmount = [0, 0, 0]
- totalGold = 0
- critChance = 20
- killCount = 0
- artifactCount = 0
- # Technical
- myList = ""
- levelUpMenu = ["Health", "Mana", "Agility", "Back"]
- dashboard = ["Stats", "Inventory", "Actions", "Quit"]
- combatMenu = ["Attack", "Spells", "Defend", "Inventory", "Quit"]
- startMenu = ["Start", "Help", "Quit"]
- townMenu = ["Alter", "Shop", "Smith", "Return", "Quit"]
- shopMenu = ["Health Potion", "Mana Potion", "Back"]
- smithMenu = ["Sword", "Armor", "Back"]
- actionMenu = ["Search", "Proceed", "Back"]
- currentFloor = 1
- difficulty = 1
- gameLoop = False
- inCombat = False
- finalBoss = False
- alreadySearched = False
- moving = False
- enemyList = ["Goblin", "Skeleton", "Giant Rat", "Slime", "Kobold", "Giant Spider"]
- currentEnemy = ""
- wizardStats = [100, 10, 10, 100, 500]
- def enemy_stats(enemy):
- # HP, ATK, AGL, Max gold, EXP
- enemies = {
- "Giant Rat": [15, 2, 4, 2, 3],
- "Giant Spider": [15, 5, 4, 2, 10],
- "Goblin": [30, 2, 3, 20, 5],
- "Skeleton": [20, 4, 5, 5, 8],
- "Slime": [45, 2, 1, 8, 8],
- "Kobold": [35, 4, 3, 9, 10],
- }
- if enemy in enemies:
- return enemies[enemy]
- else:
- print("Enemy not found")
- return None
- # Dice roll
- def dice_roll(x, y, show):
- show = str(show).capitalize()
- dice = random.randint(x, y)
- if show == "No":
- return dice
- elif show == "Yes":
- print("Rolling dice...")
- time.sleep(1)
- print(dice)
- return dice
- else:
- return dice
- # Convert list to text
- def list_to_text(myLists):
- combinedText = ""
- for i in range(len(myLists)):
- combinedText += str(i + 1) + ". " + "[" + myLists[i].capitalize() + "] " + "\n"
- return combinedText
- # Menu selection
- def option_menu(question, listName):
- print(question + "\n" + list_to_text(listName)) # Display the question prompt and list of options
- while True:
- user_input = input("> ").strip().lower()
- if user_input.isdigit(): # Check if input is a number
- index = int(user_input) - 1 # Convert to zero-based index
- if 0 <= index < len(listName):
- return listName[index]
- else:
- print("Invalid, try again.")
- else:
- for i, option in enumerate(listName):
- if user_input == option.lower():
- return option
- print("Invalid, try again.")
- # Clears screen
- def clear():
- os.system('cls' if os.name == 'nt' else 'clear')
- def game_over():
- global pName, pLevel, currentFloor, killCount, totalGold, currentEnemy
- clear()
- print(
- f"""========= GAME OVER =========
- You have died. Killed by {currentEnemy}
- Name: {pName}
- LVL: {pLevel}
- Floor: {currentFloor}
- Kills: {killCount}
- Total Gold Collected: {totalGold}
- Rest in peace...""")
- input("> ")
- quit()
- # Start screen
- def intro_prompt():
- clear()
- while True:
- clear()
- print('''
- ================= Dungeon Delver =================
- Version 0.1
- A game by Captain-Arbiter, 2024
- How to play:
- When prompted with a ">", type out the word or
- number that corresponds with the action you wish
- to perform and press enter. If no actions are present
- then you may simply press enter to continue. \n''')
- choice = option_menu("", startMenu)
- if choice == "Start":
- clear()
- print("Starting game...")
- break
- elif choice == "Help":
- clear()
- help_screen()
- clear()
- elif choice == "Quit":
- if confirm_loop() == True:
- print("Closing game...")
- time.sleep(0.5)
- sys.exit()
- break
- else:
- intro_prompt()
- def help_screen():
- print(
- """==================== Game Guide ====================
- Page 1: Room Dashboard
- When in the dungeon, and not in combat you may perform
- a few actions:
- - [STATS] Will open the character sheet for you to
- inspect your character's status.
- - [INVENTORY] will open your inventory and
- show you all currently held items, as well as give you
- acces to the Homeward Ring, which we'll cover later.
- - [ACTIONS] Will let you either, [SEARCH] for any
- treasure in the room, or [PROCEED] to the next
- floor in the dungeon.
- - [QUIT] will ask if you wish to close the game.
- Progress will not be saved.\n""")
- input("Next Page > ")
- clear()
- print(
- """==================== Game Guide ====================
- Page 2: Combat
- Everytime you enter a room. There is a 1 in 3 chance
- """)
- def combat():
- global pHealth, pMana, enemyList, playerStats, critChance, pExp, inCombat, moving, currentEnemy, killCount
- moving = False
- inCombat = True
- dice = dice_roll(1, 6, "No")
- currentEnemy = enemyList[dice - 1] if 1 <= dice <= 6 else "ERROR: ENEMY ID NOT FOUND"
- currentEnemyStats = enemy_stats(currentEnemy)
- if finalBoss == True:
- currentEnemy = "Dark-Wizard Telinoir"
- currentEnemyStats = wizardStats
- print("Telinoir, the dark wizard, appears before you!")
- else:
- print(f"A {currentEnemy} appears!")
- input("> ")
- while True:
- if pHealth <= 0:
- game_over()
- defend = playerStats[4] * 1.12
- crHit = False
- clear()
- print(
- f'''========= floor {currentFloor} =========
- {currentEnemy}:
- HP: {currentEnemyStats[0]}
- {pName}:
- HP: {pHealth}/{playerStats[0]} MP: {pMana}/{playerStats[1]}
- ''')
- choice = option_menu("What will you do?\n", combatMenu)
- if choice == "Attack":
- dice = dice_roll(1, 20, "No")
- attackMulti = playerStats[2] / 2 + 1
- round(attackMulti, 2)
- damageDealt = 5 * attackMulti
- if dice >= critChance:
- damageDealt += damageDealt * 1.75
- damageDealt = round(damageDealt)
- currentEnemyStats[0] -= damageDealt
- print("Critcal hit!")
- time.sleep(1)
- print(f"You attack for {damageDealt} damage")
- elif dice <= currentEnemyStats[2]:
- print("You missed!")
- else:
- damageDealt = round(damageDealt)
- currentEnemyStats[0] -= damageDealt
- print("Hit!")
- time.sleep(1)
- print(f"You attack for {damageDealt} damage")
- input("> ")
- clear()
- elif choice == "Spells":
- if pMana < 10:
- print("Insufficient Mana")
- continue
- pMana -= 10
- spellChoice = option_menu(
- """What spell will you cast?
- -10 MP per spell""", spellList)
- if spellChoice == "Fireball":
- currentEnemyStats[0] -= 20
- print("You cast fireball")
- time.sleep(1)
- print("Your attack deals 20 damage")
- elif spellChoice == "Heal":
- heal_amount = 25
- pHealth += heal_amount
- print("You cast heal")
- if pHealth > playerStats[0]:
- hOverflow = pHealth - playerStats[0]
- pHealth = playerStats[0]
- print(f"You healed {heal_amount - hOverflow} HP.\n")
- else:
- print(f"You healed {heal_amount} HP.\n")
- elif spellChoice == "Barrier":
- defend = defend * 5.5
- print("You cast barrier")
- print("Your magic sheild stands strong...")
- else:
- print("INVALID SPELL")
- input("> ")
- elif choice == "Defend":
- defend = defend * 2.5
- print("You raise your guard...")
- time.sleep(1)
- input("> ")
- elif choice == "Inventory":
- show_inventory()
- continue
- elif choice == "Quit":
- if confirm_loop():
- quit
- if currentEnemyStats[0] <= 0:
- print(f"The {currentEnemy} has died!")
- killCount += 1
- break
- dice = dice_roll(1, 100, "No")
- if dice <= playerStats[3] * 1.75:
- print(
- f'''========= floor {currentFloor} =========
- {currentEnemy}:
- HP: {currentEnemyStats[0]}
- {pName}:
- HP: {pHealth}/{playerStats[0]} MP: {pMana}/{playerStats[1]}
- ''')
- print(f"The {currentEnemy} goes to attack\n")
- time.sleep(1)
- print(f"The {currentEnemy} missed!")
- input("> ")
- elif dice > playerStats[3] * 1.75:
- enemyCrit = dice_roll(1, 20, "No")
- enemyAttack = currentEnemyStats[1] * 1.75 / defend
- enemyAttack = round(enemyAttack)
- if enemyCrit == 1:
- crHit = True
- enemyAttack += enemyAttack * 0.75
- enemyAttack = round(enemyAttack)
- if enemyAttack <= 0:
- enemyAttack = 0
- pHealth -= enemyAttack
- print(
- f'''========== floor {currentFloor} ==========
- {currentEnemy}:
- HP: {currentEnemyStats[0]}
- ''')
- print(f"The {currentEnemy} goes to attack!\n")
- time.sleep(1)
- if crHit == True:
- print("Critical Hit!")
- print(f"The {currentEnemy} deals {enemyAttack} damage!")
- else:
- print("Hit!")
- print(f"The {currentEnemy} deals {enemyAttack} damage!")
- input("> ")
- else:
- print("ERROR IN DAMAGE OUTPUT")
- goldFound = dice_roll(0, currentEnemyStats[3], "No")
- add_gold(goldFound)
- pExp += currentEnemyStats[4]
- print(f"{currentEnemyStats[4]} XP gained")
- # Confirm message
- def confirm_loop():
- confirm = input(str("Are you sure about this? [y/n]: \n> ")).lower()
- if confirm == "y":
- clear()
- return True
- elif confirm == "n":
- clear()
- return False
- else:
- clear()
- print("Invalid, try again")
- # Decorative line creator
- def line_flair(character, numRows, pause):
- line = "=" * 20 + " " + character + " " + "=" * 20
- for i in range(numRows):
- print(line)
- time.sleep(pause)
- # Text box function
- def dialogue_box(character, text, pause):
- line_flair(character, 1, 0.5)
- print(text)
- time.sleep(pause)
- # All of the games item effects. Must add items to itemName list and increase the size of the itemAmount list
- # if you want to add new items.
- def item_effects(itm):
- global pHealth
- global pMana
- if itm == "Health Potion":
- heal_amount = 50
- pHealth += heal_amount
- if pHealth > playerStats[0]:
- hOverflow = pHealth - playerStats[0]
- pHealth = playerStats[0]
- print(f"You healed {heal_amount - hOverflow} HP.\n")
- else:
- print(f"You healed {heal_amount} HP.\n")
- elif itm == "Mana Potion":
- mana_amount = 50
- pMana += mana_amount
- if pMana > playerStats[1]:
- mOverflow = pMana - playerStats[1]
- pMana = playerStats[1]
- print(f"You restored {mana_amount - mOverflow} MP.\n")
- else:
- print(f"You restored {mana_amount} mana.\n")
- else:
- print("Error")
- # Use an item
- def use_item(item_name):
- index = itemNames.index(item_name)
- if itemAmount[index] > 0:
- clear()
- print(f"You used {item_name}.")
- itemAmount[index] -= 1
- item_effects(item_name)
- else:
- print("You don't have any of that item.")
- # Function to show inventory
- def show_inventory():
- global inCombat
- clear()
- print("======== Inventory ========")
- for item, amount in zip(itemNames, itemAmount):
- if amount > 0:
- print(f"{item}: {amount}")
- print("Homeward Ring")
- # Display the options menu
- pInventory_updated = [item for item, amount in zip(itemNames, itemAmount) if amount > 0] + ["Homeward Ring"] + ["Back"]
- # Remove "Gold" from the options menu if it's present
- if "Gold" in pInventory_updated:
- pInventory_updated.remove("Gold")
- choice = option_menu("\nWhat item do you want to use?\n", pInventory_updated)
- if choice == "Back":
- # Go back to action menu
- return
- elif choice == "Homeward Ring":
- if inCombat == True:
- print("The evil presence disrupts the ring\n")
- input("> ")
- return
- print(
- """This ring teleports you back to town.
- When you return to the dungeon you will
- go back one floor.""")
- if confirm_loop():
- homeward_ring()
- else:
- return
- else:
- use_item(choice)
- # Use selected item
- # Item add system: 1 = HP Potion, 2 = MA Potion
- def add_inventory(item, amount):
- if item == 1:
- itemAmount[0] += amount
- if amount == 1:
- print("Health Potion added to inventory")
- else:
- print(f"{amount} Health Potions added to inventory")
- elif item == 2:
- itemAmount[1] += amount
- if amount == 1:
- print("Mana Potion added to inventory")
- else:
- print(f"{amount} Mana Potions added to inventory")
- else:
- print("ERROR INVALID ITEM CODE")
- # Add gold to player inventory
- def add_gold(amount):
- global itemAmount, totalGold
- totalGold += amount
- if amount > 0:
- itemAmount[2] += amount
- print(f"{amount} gold added to inventory")
- elif amount == 0:
- print("No gold found")
- else:
- itemAmount[2] += amount
- print(f"{amount} gold removed from inventory")
- # Player sheet
- def stat_menu():
- clear()
- print(f"""
- ======== {pName} ========
- Level: {pLevel}
- XP: {pExp}
- Health: {pHealth} / {playerStats[0]}
- Mana: {pMana} / {playerStats[1]}
- ATK: {playerStats[2]}
- AGL: {playerStats[3]}
- DFS: {playerStats[4]}""")
- input("\n> ")
- # Name creator
- def name_selection():
- global pName
- while True:
- dialogue_box("Stranger",
- """Hello there, you're far from home arent you?
- You must be here for the bounty on the wizard, what else
- could an adventurer like you be doing here. Fine then.
- Beyond the valley and over the hill will take you to
- Vindleheim Ruins, where the rogue wizard Telinoir has
- made his lair. We're counting on you. Oh where are my
- manners!""", 0.5)
- input("> ")
- pName = input(str("What is your name?\n> ")).title()
- print(f"Your name is {pName}?")
- if confirm_loop():
- break
- # Primary tool menu
- def dashboard_menu():
- inCombat = False
- while True:
- if moving == True:
- break
- print(
- f"""========= floor {currentFloor} =========\n""")
- choice = option_menu("What do you want to do?\n", dashboard)
- print(choice)
- time.sleep(0.5)
- if choice == "Stats":
- stat_menu()
- elif choice == "Inventory":
- show_inventory()
- elif choice == "Actions":
- action_menu()
- elif choice == "Quit":
- if confirm_loop():
- print("Closing Game...")
- exit()
- else:
- print("Invalid Input")
- # Hub village ring.
- def homeward_ring():
- global currentFloor, inCombat
- print("A warm glow emmits from the ring...")
- if currentFloor > 1:
- currentFloor -= 1
- time.sleep(1)
- print("In a flash you find yourself back in Hartswell.\n")
- print(
- """========== Hartswell ==========
- You can:
- - Visit the church, and level up at the alter
- - Go to the Apothocary's potion shop
- - Get your gear upgraded at the blacksmith
- """)
- while True:
- choice = option_menu("What will you do?\n", townMenu)
- if choice == "Alter":
- church_menu()
- elif choice == "Shop":
- shop_menu()
- elif choice == "Smith":
- blacksmith_menu()
- elif choice == "Return":
- if confirm_loop():
- print("You focus on the ring, and return to the dungeon.")
- break
- elif choice == "Quit":
- if confirm_loop():
- print("Closing Game...")
- exit()
- else:
- print("Invalid")
- # Potion shop menu
- def shop_menu():
- NPC = "Apothocary Zelmik"
- global itemAmount
- clear()
- print("You go to the potion shop")
- dialogue_box(NPC,
- f"""Hello {pName}. Come in, come, don't worry about the smell,
- just a new brew I'm working on.""", 0.5)
- input("> ")
- clear()
- while True:
- dialogue_box(NPC,
- '''What can I provide for you today? All potions are 25 gold.''', 0.5)
- print(f"""
- Gold: {itemAmount[2]}
- Healh Potions: {itemAmount[0]}
- Mana Potions: {itemAmount[1]}
- """)
- choice = option_menu("",shopMenu)
- if choice == "Health Potion" or choice == "Mana Potion":
- if itemAmount[2] < 25:
- clear()
- dialogue_box(NPC,"We don't take credit here. Get out!", 0.5)
- print("\nYou leave the shop and return to the town square.")
- break
- elif choice == "Health Potion":
- add_gold(-25)
- add_inventory(1, 1)
- clear()
- print("Thank you kind sir!")
- print(f"1 Health Potion added to inventory. Held: {itemAmount[0]}")
- continue
- elif choice == "Mana Potion":
- add_gold(-25)
- add_inventory(2, 1)
- clear()
- print("Thank you kind sir!")
- print(f"1 Mana Potion added to inventory. Held: {itemAmount[1]}")
- continue
- elif choice == "Back":
- clear()
- dialogue_box(NPC, "Come again soon!", 0.5)
- print("\nYou leave the shop and return to the town square.")
- break
- else:
- print("What was that?")
- # Attack and defense level up
- def blacksmith_menu():
- NPC = "Blacksmith Gilligan"
- global playerStats
- global itemAmount
- clear()
- print("You go to the blacksmith")
- dialogue_box(NPC,
- f"""Haha! Come in {pName}, ya gear be needin' a tune-up?
- Nothin' me hammer can't forge.""", 0.5)
- input("> ")
- clear()
- while True:
- dialogue_box(NPC,
- """So what'll it be? Sword need sharpenin' or yer
- armor need reinforcin'? 50 gold service charge of course.""", 0.5)
- print(f"""
- Gold: {itemAmount[2]}
- Sword ATK: {playerStats[2]}
- Armor DFS: {playerStats[4]}
- """)
- choice = option_menu("", smithMenu)
- if choice == "Sword" or choice == "Armor":
- if itemAmount[2] < 50:
- clear()
- dialogue_box(NPC,"Oi! Come back when ya got some coin! No freebies here.", 0.5)
- print("\nYou leave the shop and return to the town square.")
- break
- elif choice == "Sword":
- add_gold(-50)
- playerStats[2] += 1
- clear()
- print("A fine piece, but finer now I've got me hands on it.")
- print("+1 to sword ATK")
- continue
- elif choice == "Armor":
- add_gold(-50)
- playerStats[4] += 1
- clear()
- print("Some hardened plates here, tighter fastenins' there, and\nthis armor'll keep ya safe.")
- print("+1 to armor DFS")
- elif choice == "Back":
- clear()
- print("Ya know were to find me.")
- print("\nYou leave the shop and return to the town square.")
- break
- else:
- print("What was that?")
- # Level up menu
- def church_menu():
- NPC = "Sister Charlotte"
- global pExp
- global levelUpPts
- global playerStats
- clear()
- print("You go to the church")
- dialogue_box(NPC,
- """Come O' weary soul. Shed thine burdens, and find
- strength in ones faith.""", 0.5)
- input("> ")
- clear()
- while True:
- dialogue_box(NPC,
- """Sit beside me, and reach within thineself. In what
- way doth wish to revieve blessing""", 0.5)
- print(f"""
- Points to spend: {levelUpPts}
- Max HP: {playerStats[0]}
- Max MP: {playerStats[1]}
- AGL: {playerStats[3]}
- """)
- choice = option_menu("", levelUpMenu)
- if choice == "Health" or choice == "Mana" or choice == "Agility":
- if levelUpPts < 1:
- clear()
- dialogue_box(NPC,
- """You must grow thine soul further to revieve blessing. May you find strength.""", 0.5)
- print("\nYou leave the church and return to the town square.")
- break
- elif choice == "Health":
- levelUpPts -= 1
- playerStats[0] += 10
- pHealth = playerStats[0]
- pMana = playerStats[1]
- clear()
- print("May thine heart remain steadfast and true, always.")
- print("+10 to max HP")
- elif choice == "Mana":
- levelUpPts -= 1
- playerStats[1] += 10
- pHealth = playerStats[0]
- pMana = playerStats[1]
- clear()
- print("Free thine mind, to reach thous't true potential.")
- print("+10 to max Mana")
- elif choice == "Agility":
- levelUpPts -= 1
- playerStats[3] += 10
- pHealth = playerStats[0]
- pMana = playerStats[1]
- clear()
- print("Keep up thine wits and reflexes, may harm elude you.")
- print("+1 to Agility")
- elif choice == "Back":
- clear()
- print("Come again child, may faith guide thine path.")
- print("\nYou leave the church and return to the town square.")
- break
- else:
- print("I don't understand.")
- def action_menu():
- global currentFloor, moving, pHealth, alreadySearched, artifactCount
- while True:
- clear()
- print(
- f"""========= floor {currentFloor} =========\n""")
- choice = option_menu("What will you do?\n", actionMenu)
- print(choice)
- if choice == "Search":
- if alreadySearched == True:
- print("You've aleady searched this room")
- return
- if alreadySearched != True:
- alreadySearched = True
- print("You look around for anything of use...")
- time.sleep(1)
- dice = dice_roll(1, 10, "No")
- if dice <= 4:
- dice2 = dice_roll(1, 10, "No")
- print("You find a treasure chest in the room!")
- input("> ")
- if dice2 == 1:
- pHealth -= 5
- print("The chest is trapped!\nYou take 5 damage!")
- input("> ")
- if pHealth <= 0:
- currentEnemy = "Trapped Chest"
- game_over()
- else:
- return
- elif dice2 <= 6:
- print("You found some gold inside!")
- add_gold(dice_roll(5, 30, "No"))
- input("> ")
- return
- elif dice2 <= 9:
- print("You found a potion inside!")
- add_inventory(dice_roll(1, 2, "No"), 1)
- input("> ")
- return
- else:
- print("You found an artifact inside!\nIt swells with warmth to your touch.")
- artifactCount += 1
- dice3 = dice_roll(1, 5, "No")
- if dice3 == 1:
- print("The feel your vitality strengthen!\n+10 to max HP")
- playerStats[0] += 10
- pHealth = playerStats[0]
- elif dice3 == 2:
- print("Your mind grows sharper!\n+10 to max MP")
- playerStats[1] += 10
- pMana = playerStats[1]
- elif dice3 == 3:
- print("You feel your strength rise!\n+1 to ATK")
- playerStats[2] += 1
- elif dice3 == 4:
- print("Your body loosens, you feel as nimble as a cat!\n+1 to AGL")
- playerStats[3] += 1
- elif dice3 == 5:
- print("Your body hardens, your skin becomes like stone!\n+1 to DFS")
- playerStats[4] += 1
- return
- else:
- print("You don't find anything\n")
- input("> ")
- clear()
- return
- elif choice == "Proceed":
- print("You move onward to the next floor")
- input("> ")
- currentFloor += 1
- moving = True
- return
- elif choice == "Back":
- return
- add_inventory(1,1)
- add_inventory(2,1)
- add_gold(100)
- # Main gameplay body
- gameLoop = True
- while gameLoop == True:
- alreadySearched = False
- if pHealth <= 0:
- game_over()
- if pExp >= 100:
- pLevel += 1
- levelUpPts += 1
- pExp = 0
- print("You've leveled up!\nVisit the church in town to increase your stats.")
- input("> ")
- moving = False
- if currentFloor == 100:
- finalBoss = True
- combat()
- print("Congratulations! The wizard is beat!")
- gameLoop = False
- clear()
- roomResult = dice_roll(1,3, "no")
- if roomResult == 3: # Combat
- combat()
- inCombat = False
- else:
- print("The room seems clear")
- dashboard_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement