from argparse import Namespace from ast import Name from imghdr import what from time import * from random import * import os, sys, random from turtle import title def clear_screen(): print(""" __ _ __ / / ___ __ _ ___ _ __ __| | ___ / _| /\ /\___ _ __ ___ ___ ___ / / / _ \/ _` |/ _ \ '_ \ / _` | / _ \| |_ / /_/ / _ \ '__/ _ \ / _ \/ __| / /__| __/ (_| | __/ | | | (_| | | (_) | _| / __ / __/ | | (_) | __/\__ \\ \____/\___|\__, |\___|_| |_|\__,_| \___/|_| \/ /_/ \___|_| \___/ \___||___/ """) print() def castle(): print(""" * |>>> + + * | * + |>>> _ _|_ _ * |>>> * | |;| |;| |;| | + _ _|_ _ \\. . / _ _|_ _ + * |;|_|;|_|;| \\: + / |;|_|;|_|;| \\.. / ||:+++. | \\. . / * + \\. , / ||:+++ | \\: . / ||:+ |_ _ ||_ . _ | _ _||:+ | * * ||+++.|||_|;|_|;|_|;|_|;|_|;||+++ | + ||+++ ||. . . . ||+++.| + * ||: . ||:. . . . , ||: | * * ||: ||: , + . ||: , | + * ||: ||:. +++++ . ||: | * + ||: ||. +++++++ . ||: . | + + ||: . ||: , +++++++ . . ||: | + ||: . ||: , +++++++ . . ||: | * ||: . ||: , +++++++ . . ||: | ||: . ||: , +++++++ . . ||: | ||: . ||: , +++++++ . . ||: | +""") print() def north(): print("To go north, press 'n' then enter") def east(): print("To go east, press 'e' then enter") def south(): print("To go south, press 's' then enter") def west(): print("To go west, press 'w' then enter") def setup(): name = input("What is your name? ") HP = randint(5,20) MP = randint(5,20) return name, HP, MP def villager(): responses = ["Hi", "Are you a hero?", "Are you from this village?", "There has been a dark shadow cast across the village"] nponamechoice = ["Roger", "Dexter", "Sarah", "Susan"] nponame = choice(nponamechoice) print("\n["+nponame+":] Hello, my name is "+nponame+", would you like to talk to me?\n") print("Press 'y' to talk to the villager") if input() == "y": shuffle(responses) print("["+nponame+"] " + responses[0]) else: print("["+nponame+"] Goodbye") def enemy(): enemyHP = randint(5,20) enemyMP = randint(5,20) enemyname = "Ogre" print("\nSuddenly you hear a roar, and from the shadows you see an "+enemyname+" coming straight at you ....") print("your enemy has " + " " + str(enemyHP) + " " + " Health points") print("your enemy has " + " " + str(enemyMP) + " " + " Magic points") # Add enemy function def enemy_encounter(): enemyHP = randint(5, 20) enemyMP = randint(5, 20) enemyname = "Ogre" print("\nSuddenly you hear a roar, and from the shadows you see an " + enemyname + " coming straight at you ....") print("Your enemy has " + str(enemyHP) + " Health points") print("Your enemy has " + str(enemyMP) + " Magic points") return enemyHP # Inside the main function def main(): clear_screen() name, HP, MP = setup() print("Welcome to Middle Earth, " + name) sleep(2) print("\nYour health is " + str(HP)) print("Your magic skill is " + str(MP)) print("Would you like to venture out into the land? Press 'y' then enter to continue") if input() == "y": print("You are in your home, with a roaring fireplace in front of you.") print("Above the fire, you can see your sword and shield.") print("In the distance to the north, you can see a small village.") print("To the east, there is a river.") print("To the south, there is a mysterious forest.") print("To the west, there is a field of wildflowers.") while True: print("\nWhat would you like to do?") print("1. Go north") print("2. Go east") print("3. Go south") print("4. Go west") print("5. Quit") choice = input("Enter your choice (1-5): ") if choice == "1": print("\nYou move to the north, walking in the sunshine.") print("A villager is in your path and greets you.") villager() # Encounter an enemy enemyHP = enemy_encounter() # Implement combat scenario # For example, ask the player if they want to fight or flee, and handle the outcome accordingly # Update player attributes based on the outcome of the battle print("To the north, you see the village.") print("To the east, you see the river.") print("To the south, you see the mysterious forest.") print("To the west, you see the field of wildflowers.") # Add similar code blocks for other directions elif choice == "5": print("Goodbye.") break def main(): clear_screen() name, HP, MP = setup() print("Welcome to Middle Earth, " + name) sleep(2) print("\nYour health is " + str(HP)) print("Your magic skill is " + str(MP)) print("Would you like to venture out into the land? Press 'y' then enter to continue") if input() == "y": print("You are in your home, with a roaring fireplace in front of you.") print("Above the fire, you can see your sword and shield.") print("In the distance to the north, you can see a small village.") print("To the east, there is a river.") print("To the south, there is a mysterious forest.") print("To the west, there is a field of wildflowers.") while True: print("\nWhat would you like to do?") print("1. Go north") print("2. Go east") print("3. Go south") print("4. Go west") print("5. Quit") choice = input("Enter your choice (1-5): ") if choice == "1": print("\nYou move to the north, walking in the sunshine.") print("A villager is in your path and greets you.") villager() enemy() print("To the north, you see the village.") print("To the east, you see the river.") print("To the south, you see the mysterious forest.") print("To the west, you see the field of wildflowers.") elif choice == "2": print("\nYou walk to the river which lies to the east of your home.") print("A villager is in your path and greets you.") villager() enemy() print("To the north, you see the village.") print("To the east, you see a deeper part of the river.") print("To the south, you see the mysterious forest.") print("To the west, you see your home.") print("\nSuddenly you hear a roar, and from the shadows you see an Ogre coming straight at you ....") enemyHP = randint(10, 20) enemyMP = randint(5, 10) print("Your enemy has " + str(enemyHP) + " Health points") print("Your enemy has " + str(enemyMP) + " Magic points") print("\nWhat would you like to do?") print("1. Fight") print("2. Run") fight_choice = input("Enter your choice (1-2): ") if fight_choice == "1": print("\nYou prepare for battle!") while HP > 0 and enemyHP > 0: player_damage = randint(1, 5) print("You attack the Ogre and deal " + str(player_damage) + " damage!") enemyHP -= player_damage if enemyHP <= 0: print("You defeated the Ogre!") print("You gain 10 HP and 5 MP.") HP += 10 MP += 5 break enemy_damage = randint(1, 4) print("The Ogre attacks you and deals " + str(enemy_damage) + " damage!") HP -= enemy_damage print("Your HP: " + str(HP)) print("Ogre's HP: " + str(enemyHP)) if HP <= 0: print("You were defeated by the Ogre!") print("Game Over.") break elif fight_choice == "2": print("\nYou run away from the Ogre!") print("To the north, you see the village.") print("To the east, you see a deeper part of the river.") print("To the south, you see the mysterious forest.") print("To the west, you see your home.") else: print("Invalid choice. Please enter 1 or 2.") elif choice == "3": print("\nYou decide to go south.") print("You enter the mysterious forest, full of ancient trees.") print("You find a hidden cave with treasures!") print("You gain 10 HP and 5 MP.") HP += 10 MP += 5 print("Your health is now " + str(HP)) print("Your magic skill is now " + str(MP)) print("To the north, you see the river.") print("To the east, you see the field of wildflowers.") print("To the south, you see a deeper part of the forest.") print("To the west, you see your home.") elif choice == "4": print("\nYou walk to the field of wildflowers, stopping to take in the beauty.") print("A villager is in your path and greets you.") villager() enemy() print("To the north, you see the village.") print("To the east, you see the river.") print("To the south, you see the mysterious forest.") print("To the west, you see a deeper part of the field.") print("\nYou find a group of bandits!") banditsHP = randint(8, 15) print("The bandits have " + str(banditsHP) + " Health points") print("\nWhat would you like to do?") print("1. Fight") print("2. Flee") bandits_choice = input("Enter your choice (1-2): ") if bandits_choice == "1": print("\nYou prepare to fight the bandits!") while HP > 0 and banditsHP > 0: player_damage = randint(1, 5) print("You attack the bandits and deal " + str(player_damage) + " damage!") banditsHP -= player_damage if banditsHP <= 0: print("You defeated the bandits!") print("You find a chest with treasures!") print("You gain 15 HP and 10 MP.") HP += 15 MP += 10 break bandits_damage = randint(1, 4) print("The bandits attack you and deal " + str(bandits_damage) + " damage!") HP -= bandits_damage print("Your HP: " + str(HP)) print("Bandits' HP: " + str(banditsHP)) if HP <= 0: print("The bandits overwhelmed you!") print("Game Over.") break elif bandits_choice == "2": print("\nYou flee from the bandits!") print("To the north, you see the village.") print("To the east, you see the river.") print("To the south, you see the mysterious forest.") print("To the west, you see a deeper part of the field.") else: print("Invalid choice. Please enter a number between 1 and 5.") if __name__ == "__main__": main() if input() == "y": print("You are in your home, with a roaring fireplace in front of you.") print("Would you like to take your sword and shield? Press 'y' then enter to continue") if input() == "y": weapons = ["sword", "shield"] print(f"You are now carrying your {weapons[0]} and your {weapons[1]}") print(f"Armed with your {weapons[0]} and {weapons[1]}, you swing open the door to your home and see a green valley gleaming in the sunshine.") else: print("You choose not to take your weapons") print("Armed with your sense of humour, you swing open the door to see a green valley full of opportunity awaiting you") else: print("You stay at home, sat in your favorite chair watching the fire grow colder. Middle Earth no longer has a hero.") print("Game over") sys.exit(0) print("In the distance to the north you can see a small village, to the east you can a river and to the west a field of wildflowers.") print("\n") north() east() west() move = input("Where would you like to go? ") if move == 'n': print("\nYou move to the north, walking in the sunshine.") print("A villager is in your path and greets you") elif move == 'e': print("\nYou walk to the river which lies to the east of your home.") print("A villager is in your path and greets you") elif move == 'w': print("\nYou walk to the field of wildflowers, stopping to take in the beauty") print("A villager is in your path and greets you\n") villager() enemy() sleep(3) fight = input("Do you wish to fight? ") if fight == "y": while HP > 0: hit = randint(0, 5) print(f"You swing your sword and cause {hit} of damage") enemyHP = enemyHP - hit print(enemyHP) enemyhit = randint(0, 5) print(f"The ogre swings a club at you and causes {enemyhit} of damage") HP = HP - enemyhit print(HP) else: print("You turn and run away from the ogre") print("This is where this template ends. This is now your world, build your adventure and share it with the world") print(""" _ _ _ /_\ __| |_ _____ _ __ | |_ _ _ _ __ ___ //_\\ / _` \ \ / / _ \ '_ \| __| | | | '__/ _ \\ / _ \ (_| |\ V / __/ | | | |_| |_| | | | __/ \_/ \_/\__,_| \_/ \___|_| |_|\__|\__,_|_| \___| """) print(""" _ _ __ ___ ____ _(_) |_ ___ / _` \ \ /\ / / _` | | __/ __| | (_| |\ V V / (_| | | |_\__ \ \__,_| \_/\_/ \__,_|_|\__|___/ """) print(""" _ _ ___ _ _ | | | |/ _ \| | | | | |_| | (_) | |_| | \__, |\___/ \__,_| |___/ """)