import random import time player_level = 1 player_health = 100 player_attack = 10 player_defense = 0 player_gold = 0 armor = "None" blade = "None" poison_potions = 0 healing_potions = 0 hunger = 100 enemy_types = { "Goblin": {"health": 50, "attack": 20}, "Skeleton": {"health": 80, "attack": 15}, "Zombie": {"health": 120, "attack": 25}, } coin_toss_attack = { "power": 50, "boost_turns": 2, } armor_options = { "Leather Armor": {"defense": 5}, "Iron Armor": {"defense": 10}, "Steel Armor": {"defense": 15}, } blade_options = { "Iron Blade": {"attack": 10}, "Steel Blade": {"attack": 20}, "Legendary Blade": {"attack": 30}, } while True: print("1. Explore") print("2. Stats") print("3. Inventory") print("4. Exit") choice = input("Enter your choice: ") time.sleep(1) if choice == "1": encounter = random.choice(["Nothing", "Monster", "Treasure", "Boss"]) if encounter == "Nothing": if player_health < 100: player_health += random.randint(5, 10) print("Caught your breath. Regenerated some health.") time.sleep(1) else: print("Nothing interesting here.") time.sleep(1) if hunger < 100: hunger += random.randint(2, 5) print("Found some mushrooms. Satisfied your hunger.") time.sleep(1) elif encounter == "Monster": enemy_type = random.choice(list(enemy_types.keys())) enemy_health = enemy_types[enemy_type]["health"] + player_level * 20 enemy_attack = enemy_types[enemy_type]["attack"] + player_level * 5 print("A wild " + enemy_type + " appears! (Health: " + str(enemy_health) + ", Attack: " + str(enemy_attack) + ")") time.sleep(1) while player_health > 0 and enemy_health > 0: print("1. Attack") print("2. Flee") print("3. Coin Toss Attack") battle_choice = input("Enter your choice: ") time.sleep(1) if battle_choice == "1": enemy_health -= player_attack print("You attack the " + enemy_type + "!") time.sleep(1) if enemy_health > 0: player_health -= enemy_attack print("The " + enemy_type + " attacks you!") time.sleep(1) elif battle_choice == "2": if random.randint(1, 10) <= 5: print("You successfully flee!") time.sleep(1) break else: print("You failed to flee. The " + enemy_type + " attacks!") time.sleep(1) player_health -= enemy_attack elif battle_choice == "3": coin_toss_result = random.choice(["Head", "Tail"]) print("Coin toss result:", coin_toss_result) time.sleep(1) if coin_toss_result == "Head": player_health -= coin_toss_attack["power"] print("Coin toss failed! Endured a powerful attack.") time.sleep(1) else: player_attack += coin_toss_attack["power"] print("Coin toss succeeded! Escaped the attack and gained a boost for the next attack.") time.sleep(1) else: print("Invalid choice. Try again.") time.sleep(1) if player_health <= 0: print("Defeated by the " + enemy_type + ". Game over!") break else: gold_earned = random.randint(10, 20) player_gold += gold_earned print("Defeated the " + enemy_type + "! Found " + str(gold_earned) + " gold.") time.sleep(1) if player_gold >= 100: print("Enough gold to improve stats at the shop.") time.sleep(1) elif encounter == "Treasure": gold_found = random.randint(5, 10) player_gold += gold_found print("Found treasure! Gained " + str(gold_found) + " gold.") time.sleep(1) if hunger < 100: hunger += random.randint(5, 10) print("Found some meat. Satisfied your hunger.") time.sleep(1) elif encounter == "Boss": boss_type = random.choice(["Demon Lord", "Ancient Dragon", "Lich King"]) boss_health = (player_level * 100) + random.randint(50, 100) boss_attack = (player_level * 20) + random.randint(10, 20) print("You encounter a mighty " + boss_type + "! (Health: " + str(boss_health) + ", Attack: " + str(boss_attack) + ")") time.sleep(1) while player_health > 0 and boss_health > 0: print("1. Attack") print("2. Coin Toss Attack") battle_choice = input("Enter your choice: ") time.sleep(1) if battle_choice == "1": boss_health -= player_attack print("You attack the " + boss_type + "!") time.sleep(1) if boss_health > 0: player_health -= boss_attack print("The " + boss_type + " attacks you!") time.sleep(1) elif battle_choice == "2": coin_toss_result = random.choice(["Head", "Tail"]) print("Coin toss result:", coin_toss_result) time.sleep(1) if coin_toss_result == "Head": player_health -= coin_toss_attack["power"] print("Coin toss failed! Endured a powerful attack.") time.sleep(1) else: player_attack += coin_toss_attack["power"] print("Coin toss succeeded! Escaped the attack and gained a boost for the next attack.") time.sleep(1) else: print("Invalid choice. Try again.") time.sleep(1) if player_health <= 0: print("Defeated by the " + boss_type + ". Game over!") break else: gold_earned = random.randint(50, 100) player_gold += gold_earned print("Defeated the " + boss_type + "! Found " + str(gold_earned) + " gold.") time.sleep(1) if player_gold >= 100: print("Enough gold to improve stats at the shop.") time.sleep(1) if hunger > 0: hunger -= random.randint(1, 3) if hunger <= 0: print("You are starving! Lose health.") player_health -= random.randint(5, 10) time.sleep(1) elif choice == "2": print("Player Stats:") print("Level:", player_level) print("Health:", player_health) print("Attack:", player_attack) print("Defense:", player_defense) print("Gold:", player_gold) print("Armor:", armor) print("Blade:", blade) time.sleep(1) elif choice == "3": print("1. Use Poison Potion") print("2. Use Healing Potion") print("3. Equip Armor") print("4. Equip Blade") print("5. Leave Inventory") inventory_choice = input("Enter your choice: ") time.sleep(1) if inventory_choice == "1": if poison_potions > 0: player_attack += 10 poison_potions -= 1 print("Used a Poison Potion. Attack increased!") time.sleep(1) else: print("No Poison Potions available.") time.sleep(1) elif inventory_choice == "2": if healing_potions > 0: player_health += 20 healing_potions -= 1 print("Used a Healing Potion. Health increased!") time.sleep(1) else: print("No Healing Potions available.") time.sleep(1) elif inventory_choice == "3": print("Available Armor Options:") for i, option in enumerate(armor_options.keys()): print(str(i + 1) + ". " + option) equip_choice = input("Enter the number of the armor you want to equip: ") time.sleep(1) if equip_choice.isdigit() and int(equip_choice) in range(1, len(armor_options) + 1): armor = list(armor_options.keys())[int(equip_choice) - 1] player_defense = armor_options[armor]["defense"] print("Equipped " + armor + ". Defense increased!") time.sleep(1) else: print("Invalid choice. Try again.") time.sleep(1) elif inventory_choice == "4": print("Available Blade Options:") for i, option in enumerate(blade_options.keys()): print(str(i + 1) + ". " + option) equip_choice = input("Enter the number of the blade you want to equip: ") time.sleep(1) if equip_choice.isdigit() and int(equip_choice) in range(1, len(blade_options) + 1): blade = list(blade_options.keys())[int(equip_choice) - 1] player_attack = blade_options[blade]["attack"] print("Equipped " + blade + ". Attack increased!") time.sleep(1) else: print("Invalid choice. Try again.") time.sleep(1) elif inventory_choice == "5": print("Leaving inventory.") time.sleep(1) else: print("Invalid choice. Try again.") time.sleep(1) elif choice == "4": print("Exiting the game.") break else: print("Invalid choice. Try again.") time.sleep(1)