Untitled

 avatar
unknown
plain_text
6 months ago
1.9 kB
2
Indexable
def show_instructions():
    """Prints the game instructions."""
    print("Welcome to the Text Adventure Game!")
    print("You are in a series of rooms. Your goal is to find the treasure.")
    print("Use the following commands:")
    print("go north, go south, go east, go west")
    print("get [item]")

def show_status(current_room, inventory):
    """Prints the player's current status."""
    print("---------------------------")
    print("You are in the " + current_room)
    print("Inventory : " + str(inventory))
    if "item" in rooms[current_room]:
        print("You see a " + rooms[current_room]["item"])
    print("---------------------------")

# A dictionary linking rooms to other rooms
rooms = {
    "Hall": {
        "south": "Kitchen",
        "east": "Dining Room",
        "item": "key"
    },
    "Kitchen": {
        "north": "Hall"
    },
    "Dining Room": {
        "west": "Hall",
        "south": "Garden",
        "item": "potion"
    },
    "Garden": {
        "north": "Dining Room"
    }
}

inventory = []
current_room = "Hall"

show_instructions()

while True:
    show_status(current_room, inventory)

    move = ""
    while move == "":
        move = input(">").lower().split()

    if len(move) == 1:
        if move[0] in ["go"]:
            print("Go where?")
            continue
        elif move[0] == "exit":
            break
        else:
            print("Invalid input")
            continue

    if move[0] == "go":
        if move[1] in rooms[current_room]:
            current_room = rooms[current_room][move[1]]
        else:
            print("You can't go that way!")

    if move[0] == "get":
        if "item" in rooms[current_room] and move[1] == rooms[current_room]["item"]:
            inventory.append(rooms[current_room].pop("item"))
            print("You got the " + move[1] + "!")
        else:
            print("Can't get that!")

print("Thanks for playing!")
Editor is loading...
Leave a Comment