import json import os import sys from pathlib import Path from typing import List, Dict, Tuple MAPDATA_FILE = os.path.join("mapdata.json") VALID_DIRECTIONS = { "n": "North", "s": "South", "e": "East", "w": "West" } mapdata_raw = Path(MAPDATA_FILE).read_text() mapdata = json.loads(mapdata_raw) def get_room(data, room_id) -> Dict: for room in data["rooms"]: if room["id"] == room_id: return room answer = input('Would you like to play a game?(y/n)') if answer.lower() == 'n': print( 'Ok Maybe Some other time' ) sys.exit() print('Welcome to the Adventure') start = True inventory = [] player_room = 0 name = input("Enter Your Name : ") print("Greetings, " + name + "\n###Let's Start the Game###") #print("""\nAs you slowly regained consciousness, you found yourself in a strange room bathed in an eerie glow. #There are three imposing doors, each beckoning you towards a different path. #Which door would you choose---1, 2 or 3???""") current_room_data = get_room(mapdata, player_room) print(f"You wake up in {current_room_data['name']}") print(f"\n{current_room_data['discription']}") print(f"{current_room_data['action']}") print(f"\n{current_room_data['player']}") door = "" while door not in current_room_data["directions"].keys(): print("Available directions to travel: ", end='') for direction, room_id in current_room_data['directions'].items(): print(f" {direction}", end='') print() door = input(">") door = door.lower()[0:1] if door not in VALID_DIRECTIONS.keys(): print(" You bump into a wall of your own incompetence.") door = "" else: door = VALID_DIRECTIONS[door] player_room = current_room_data["directions"][VALID_DIRECTIONS[door.lower()[0:1]]] current_room_data = get_room(mapdata, player_room) if(door == "1"): print("You entered the First room and through time travelling you found yourself in a an ancient Battle") print("By looking at the Flag of an Empire you come to knw that\nIt is the battle of Spartans") print("You hide in the bush and finds a Sword lying on the ground") print("What would you do???") print("1-Pick the Sword and Run from the Battleground") print("2-Pick the Sword and Fight for your life") print("3-Leave it and come back to Present time without altering the timeline") options = input(">") if(options == "1"): print("As you started running\nomeone from back hit you with the Arrow!\nBoom!!!You are dead.") elif(options == "2"): print("You started fighting from the spartans side, \nluckily you survived the battlefield and lived the rest of the life as a commander in the Army\nYou stucked in the past for the rest of your life") elif(options == "3"): print("You leaved the sword in its place and witnessed the ancient war.\nCame back to present time\nWith the memories of the huge Battlefield, which you can't share with anyone.\n###You Won the Game###") else: print("Type a Number!!!\nGAME OVER\nPLEASE RESTART the GAME") if(door == "2"): print("You entered the Second room and found yourself in a remote jungle with an ancient map beside you") print("The Map contains a route leading to a treasure hidden in the forest") print('What would you do???') print("1-Wait for the help.") print("2-Find for an exit on on your own.") print("3-Take the Map.") forest = input(">") if(forest == "1"): print("No one was there to help you.\nYou hide from the wild animals for a while.\nGets killed by the Wolf in the End") elif(forest == "2"): print("You look for an exit in jungle on your own.\nIn the pain of hunger you ate poisoned berries.\nGood job! You Died!!!") elif(forest == "3"): print("You followed the Map, discovered some beautiful sceneries of deep forest.\nFinally reached the treasure chest.\nYou opened the chest but it was empty") print("You get disappointed\nAfter walking for a while.\nYou saw a river and sat near the river and relaxed.\n###You Won the Game###") else: print("Type a Number!!!\nGAME OVER\nPLEASE RESTART the GAME") if (door == "3"): print("You entered the Third room and found yourself in front of a Witch brewing Potions") print("She ask-What are you doing here young boy?") print("What will you answer-") print("1-You tell her that you're lost, and want to get out of here.") print("2-You stab her with a knife.") print("3-You try to runway.") witch = input(">") if(witch == "1"): print("She cast a spell on you and you become unconscious.") print("She brewed you into her potion") print("Good bye! You Died") elif(witch == "2"): print("You come close to her and swing your knife at her face and then stab her to death.") print("Good job. You are free now.\nWith a tag of Murderer!!!\n###But You Won the Game###") elif(witch == "3"): print("She casts a spell that freezes you in place.") print("She prisoned you in her cabin.") print("Good job! You became her slave for the rest of your life.") else: print("Type a Number!!!\nGAME OVER\nPLEASE RESTART the GAME")