[Python] Text based game: Movement between rooms

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I am creating a text based game where the character has to move between rooms to defeat the final boss: HUNGER. However, I am not sure how to create the code needed to move between rooms. This is what I have so far. How do I go about making the character move from Great Hall to Bedroom?


    rooms = {
    'Great Hall': {'South': 'Bedroom'},
    'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
    'Cellar': {'West': 'Bedroom'}
    }

    directions = ['North', 'South', 'East', 'West']
    location = 'Great Hall'
    Inventory = []

    print("Welcome to Trials of Harvest. You can go North, East, South, or West. Type 'Exit' to leave the game.")


    while True: #gameplay loop
    print('You are in the ', location)
    print('------------------------------')
    direction = input("Type North, East, South, West, or Exit. ")
    if direction == 'North' or 'South' or 'East' or 'West':
    print("You are in the", location)
    elif direction == "Exit":
    print('Thanks for playing!')
    exit()
    else:
    print('Invalid Direction!!')

    Continue reading...

Compartilhe esta Página