from time import sleep from random import randint def clear_screen(): # Function to clear the console screen import os os.system('cls' if os.name == 'nt' else 'clear') def title(): # Function to display the game title print(""" __ _ __ / / ___ __ _ ___ _ __ __| | ___ / _| /\ /\___ _ __ ___ ___ ___ / / / _ \/ _` |/ _ \ '_ \ / _` | / _ \| |_ / /_/ / _ \ '__/ _ \ / _ \/ __| / /__| __/ (_| | __/ | | | (_| | | (_) | _| / __ / __/ | | (_) | __/\__ \\ \____/\___|\__, |\___|_| |_|\__,_| \___/|_| \/ /_/ \___|_| \___/ \___||___/ |___/ """) def castle(): # Function to display a castle ASCII art print(""" * |>>> + + * | * + |>>> _ _|_ _ * |>>> * | |;| |;| |;| | * + _ _|_ _ \\. . / _ _|_ _ + * |;|_|;|_|;| \\: + / |;|_|;|_|;| \\.. / ||:+++. | \\. . / * + \\. , / ||:+++ | \\: . / ||:+ |_ _ ||_ . _ | _ _||:+ | * * ||+++.|||_|;|_|;|_|;|_|;|_|;||+++ | + ||+++ ||. . . . ||+++.| * + * ||: . ||:. . . . , ||: | * * ||: ||: , + . ||: , | + * ||: ||:. +++++ . ||: | * + ||: ||. +++++++ . ||: . | + + ||: . ||: , +++++++ . . ||: | + ||: . ||: , +++++++ . . ||: | ||: . ||: , +++++++ . . ||: | """) def north(): # Function to display the instruction to go north print("To go north press 'n' then enter") def east(): # Function to display the instruction to go east print("To go east press 'e' then enter") def south(): # Function to display the instruction to go south print("To go south press 's' then enter") def west(): # Function to display the instruction to go west print("To go west press 'w' then enter") def setup(): # Function to set up initial player stats global name, HP, MP name = input("What is your name, warrior? ") HP = randint(5, 20) MP = randint(5, 20) def villager(): # Function to interact with a villager global npcname, response responses = ["Hi", "Are you a hero?", "Are you from this village?", "There has been a dark shadow cast across the village"] npcnamechoice = ["Roger", "Dexter", "Sarah", "Susan"] import random random.shuffle(npcnamechoice) npcname = npcnamechoice[0] print(f"\n[{npcname}:] Hello, my name is {npcname}, would you like to talk to me?\n") random.shuffle(responses) print("Press 'y' to talk to the villager") if input() == "y": print(f"[{npcname}:] {responses[0]}") else: print(f"[{npcname}:] Goodbye") def enemy(): # Function to set up initial enemy stats global enemyHP, enemyMP, enemyname enemyHP = randint(5, 20) enemyMP = randint(5, 20) enemyname = "Ogre" print(f"\nSuddenly, you hear a roar, and from the shadows, you see an {enemyname} coming straight at you....") print(f"Your enemy has {enemyHP} Health Points") print(f"Your enemy has {enemyMP} Magic Points") # Game setup clear_screen() title() castle() setup() # Display player stats print(f"Welcome to Middle Earth, {name}") sleep(2) print(f"\nYour health is {HP}") print(f"Your magic skill is {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, above the fire you can see your sword and shield") 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 favourite chair watching the fire grow colder. Middle Earth no longer has a hero.") print("Game Over") exit(0) print("In the distance to the north, you can see a small village, to the east you can see a river, and to the west, a field of wildflowers.\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.lower() == "y": while HP > 0: hit = randint(0, 5) print(f"You swing your sword and cause {hit} of damage") enemyHP -= hit print(enemyHP) enemyhit = randint(0, 5) print(f"The ogre swings a club at you and causes {enemyhit} of damage") 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 / __/ | | | |_| |_| | | | __/ \_/ \_/\__,_| \_/ \___|_| |_|\__|\__,_|_| \___| _ _ __ ___ ____ _(_) |_ ___ / _` \ \ /\ / / _` | | __/ __| | (_| |\ V V / (_| | | |_\__ \ \__,_| \_/\_/ \__,_|_|\__|___/ """) print(""" _ _ ___ _ _ | | | |/ _ \| | | | | |_| | (_) | |_| | \__, |\___/ \__,_| |___/ """)