Created
May 6, 2025 16:02
-
-
Save AnastasiyaGapochkina01/0891cca1515e044c9844588808c4cde7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def location_hallway(locations, character): | |
current_location = locations["hallway"] | |
print(current_location["description"]) | |
print("Where do you want to go?") | |
actions = list(current_location["actions"].keys()) | |
print_list(actions) | |
choice = int(input("Your choise: ").lower()) | |
if choice == 1: | |
print("You're in the library.") | |
current_location = locations["library"] | |
print(current_location["description"]) | |
actions = list(current_location["actions"].keys()) | |
print("You can:") | |
print_list(actions) | |
choice = int(input("Your choise: ").lower()) | |
if choice == 1: | |
print("You take silver key") | |
character["inventory"].append("silver key") | |
print("Now you have in inventory:") | |
print_list(character["inventory"]) | |
elif choice == 2: | |
print("You found a clue in the book (way).") | |
character["memory"] = "way" | |
elif choice == 3: | |
print("Go back to hallway") | |
location_hallway(locations, character) | |
elif choice == 2: | |
print("You're in the kitchen.") | |
elif choice == 3: | |
print("There's a closed door with a rusty lock in front of you. You need a rusty key") | |
if "rusty key" in character["inventory"]: | |
print("You opened the door and got into the Hall of the Ghost") | |
else: | |
print("The door is closed and you don't have a key.") | |
else: | |
print("Incorrect input") | |
def print_dict(dict_obj): | |
for key, val in dict_obj.items(): | |
if type(val) is list and check_empty(val) == True: | |
print(f"{key} is empty") | |
elif type(val) is list and check_empty(val) == False: | |
print(f"{key} - {print_list(val)}") | |
else: | |
print(f"{key} - {val}") | |
def check_empty(list_obj): | |
if len(list_obj) == 0: | |
return True | |
return False | |
def print_list(list_obj): | |
for item in list_obj: | |
print(item, end="\n") | |
locations = { | |
"dungeon": { | |
"description": "You wake up in a damp dungeon. The light of the torch barely illuminates the stone walls. There is a heavy iron door in front of you. On the right is a pile of crates, on the left is a pool of blood.", | |
"actions": { | |
"Inspect the boxes (1)": "a rusty key", | |
"Try to kick down the door (2)": "the trap", | |
"Look for a hidden lever (3)": "hallway" | |
}, | |
}, | |
"hallway": { | |
"description": "You are in a long corridor with torches on the walls. There are claw marks on the floor. Two doors: to the left (library) and to the right (kitchen). At the end of the corridor is a staircase to the top.", | |
"actions": { | |
"the left branch of the corridor (1)": "library", | |
"the right branch of the corridor (2)": "kitchen", | |
"up the stairs (3)": "stairs"} | |
}, | |
"library": { | |
"description": "Shelves with dusty books. On the table is an open folio and a silver key. The window is barred.", | |
"actions": { | |
"Take the silver key (1)": "silver key", | |
"Read a book (2)": "way", | |
"Go back to the hallway (3)": "hallway"} | |
} | |
} | |
tmp_name = input("Enter you character name: ") | |
character = { | |
"name": tmp_name, | |
"hp": 3, | |
"inventory": [] | |
} | |
current_location = locations["dungeon"] | |
print(f"Welcome to text quest!\nYou charecter:") | |
print_dict(character) | |
print(current_location["description"]) | |
actions = list(current_location["actions"].keys()) | |
print("You can:") | |
print_list(actions) | |
choice = int(input("Your choise: ").lower()) | |
if choice == 1: | |
print("You found a rusty key.") | |
character["inventory"].append("rusty key") | |
print("Now you have in inventory:") | |
print_list(character["inventory"]) | |
elif choice == 2: | |
print("You tried to kick down the door, but there was a trap.") | |
character["hp"] -= 1 | |
if character["hp"] <= 0: | |
print("You died from your wounds") | |
#TODO: break | |
else: | |
print(f"Now you have {character["hp"]} points hp") | |
elif choice == 3: | |
print("You found the hidden lever and got into the hallway.") | |
location_hallway(locations, character) | |
else: | |
print("Incorrect input") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment