[Python] Issues with text-based game for school project

Discussão em 'Python' iniciado por Stack, Abril 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a project for school, and I need to create a text-based adventure game. what I have so far is

    """#Introduction to the game"""
    from django.template.defaultfilters import lower

    print('Welcome to the end of the world!')
    print('After the collapse of society')
    print('You are left to wander in the barren wasteland left behind')
    print('On your journey, you come across what appears to be an abandoned home')
    print('You must search the home for anything to help you on your journey')
    print('Collect them all before encountering the Zombie')
    rooms = {
    'Building Entrance': {'east': 'Barrack'},
    'Barrack': {'north': 'Supply Room', 'south': 'Med Bay', 'east': 'Armory'},
    'Supply Room': {'south': 'Barrack', 'east': 'Locker Room'},
    'Med Bay': {'north': 'Barrack', 'east': 'Kitchen'},
    'Armory': {'west': 'Barrack', 'north': 'Kill Zone'},
    'Locker Room': {'west': 'Supply Room'},
    'Kitchen': {'west': 'Med Bay'}

    }
    inventory = {
    'Barrack': {'item': 'Food Rations'},
    'Supply Room': {'item': 'Water Purification Tablets'},
    'Med Bay': {'item': 'First Aid Kit'},
    'Armory': {'item': 'Hatchet'},
    'Locker Room': {'item': 'Flask'},
    'Kitchen': {'item': 'Fire Starting Kit'}
    }
    def Barrack():

    print('You are now in the Barrack.')
    status= 'Barrack'
    print('Would you like to collect the item?')
    answer = lower(input())
    if answer == 'yes':
    print('Congrats!, you have received', inventory['item'])
    print('Which way would you like to go?')
    '#current location'


    print('You are currently at the entrance of the house')
    status = 'Building entrance'
    def direction_request():
    print('Which way would you like to go?')
    print('Possible directions and north, south, east, west, and leave')
    direction_request()

    direction = lower(input())
    while direction != 'exit':

    if direction == 'east':
    Barrack()
    elif direction == 'north' 'west' 'south':
    print('Sorry, you cant go that way from here!')
    else:
    print('Please enter a valid direction')"


    and yes, I know its a mess. I'm really struggling with this class, and anytime I attempt to run what I have so far, if I enter an invalid direction, it repeats the output indefinitely.

    Continue reading...

Compartilhe esta Página