无法开始游戏,不知道如何添加库存

Can't start the game and don't know how to add inventory

我必须为期末项目制作一个基于文本的游戏。目标是捡起 6 件物品并从一个房间移动到另一个房间。我在这方面还很陌生,需要一些帮助!我似乎无法调用函数,也不知道如何添加库存。这是我当前的代码:

def show_instructions():
   #print a main menu and the commands
   print("Thousand Year Vampire")
   print("Collect 6 items to defeat the vampire or be destroyed by her.")
   print("Move commands: go South, go North, go East, go West")
   print("Add to Inventory: get 'item name'")


def showStatus(current_room, inventory, rooms):
    #print the player's current location
    #print the current inventory
    #print an item if there is one


def main():
    #define inventory and dictionary linking other rooms
    rooms = {

        'Entry Way': { 'North': 'Stalagmite Cavern'},
        'Stalagmite Cavern': {'North': 'Grand Cavern', 'South': 'Entry Way', 'item': 'torch'},
        'Grand Cavern': {'North': 'Hallway', 'East': 'Armory', 'West': 'Bedroom', 'South': 'Stalagmite Cavern', 'item': 'cross'},
        'Armory': {'North': 'Treasure Trove', 'West': 'Grand Cavern', 'item': 'Stake'},
        'Treasure Trove': {'South': 'Armory', 'item': 'silver'},
        'Bedroom': {'North': 'Storage', 'East': 'Grand Cavern', 'item': 'elaborate comb'},
        'Storage': {'South': 'Bedroom', 'item': 'mirror'},
        'Hallway': {'North': 'Cliff Top', 'South': 'Grand Cavern'},
        'Cliff Top': {'South': 'Hallway', 'item': 'Orla'}
    }
# setting up inventory
inventory = []

# setting the starting room
starting_room = 'Great Hall'

# set current room to starting room
current_room = starting_room

while True:
    print("\nYou are currently in {}".format(current_room))
    move = input("Enter 'go North/South/East/West' to move or 'Exit': ").split()[-1].capitalize()

    # user to exit
    if move == 'Exit':
        current_room = 'exit'
        break

    # a correct move
    elif move in rooms[current_room]:
        current_room = rooms[current_room][move]

    # incorrect move
    else:
        print("You can't go that way. There is nothing to the {}".format(move))



#loop forever

#show game instructions
show_instructions()

这不是最终答案,但我想向您展示您可以对代码进行哪些更改以使程序正常运行。

这只是重构您的代码。这不是解决方案。一旦我们了解了问题所在,我可以帮助解决这个问题。

def show_instructions():
   #print a main menu and the commands
   print("Thousand Year Vampire")
   print("Collect 6 items to defeat the vampire or be destroyed by her.")
   print("Move commands: go South, go North, go East, go West")
   print("Add to Inventory: get 'item name'")

def showStatus(current_room, inventory, rooms):
    #print the player's current location
    #print the current inventory
    #print an item if there is one

#define inventory and dictionary linking other rooms
rooms = {

    'Entry Way': { 'North': 'Stalagmite Cavern'},
    'Stalagmite Cavern': {'North': 'Grand Cavern', 'South': 'Entry Way', 'item': 'torch'},
    'Grand Cavern': {'North': 'Hallway', 'East': 'Armory', 'West': 'Bedroom', 'South': 'Stalagmite Cavern', 'item': 'cross'},
    'Armory': {'North': 'Treasure Trove', 'West': 'Grand Cavern', 'item': 'Stake'},
    'Treasure Trove': {'South': 'Armory', 'item': 'silver'},
    'Bedroom': {'North': 'Storage', 'East': 'Grand Cavern', 'item': 'elaborate comb'},
    'Storage': {'South': 'Bedroom', 'item': 'mirror'},
    'Hallway': {'North': 'Cliff Top', 'South': 'Grand Cavern'},
    'Cliff Top': {'South': 'Hallway', 'item': 'Orla'}
}
# setting up inventory
inventory = []

# setting the starting room
starting_room = 'Hallway'

# set current room to starting room
current_room = starting_room

#show game instructions
show_instructions()

while True:
    print("\nYou are currently in {}".format(current_room))
    move = input("Enter 'go North/South/East/West' to move or 'Exit': ").split()[-1].capitalize()

    # user to exit
    if move == 'Exit':
        current_room = 'exit'
        break

    # a correct move
    elif move in rooms[current_room]:
        current_room = rooms[current_room][move]

    # incorrect move
    else:
        print("You can't go that way. There is nothing to the {}".format(move))

#loop forever