微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从字典数组中合并项目抓取

如何解决从字典数组中合并项目抓取

这是我正在创建的文本游戏的代码,我在其中设置了 dict 以在房间之间导航。用户负责收集的每个房间中都有一个项目,我正在寻找有关如何从这些数组中收集/和存储项目的指导。

def nextroom(currentloc,direction):
    rooms = {
        'bedroom': {'north': 'Parents Office','South': 'Living-room','East': 'Kitchen','West': 'Bathroom','Item': 'Invalid'},'Parents Office': {'north': 'Invalid','South': 'bedroom','East': 'Dads Man Cave','West': 'Invalid','Item': 'Golf Club'},'Bathroom': {'north': 'invalid','South': 'Invalid','East': 'bedroom','Item': 'Hand Soap'},'Living-room': {'north': 'bedroom','East': 'Dining-room','Item': 'Nerf Gun'},'Dining-room': {'north': 'invalid','East': 'Invalid','West': 'Living-room','Item': 'Bucket of Marbles'},'Kitchen': {'north': 'Garage','West': 'bedroom','Item': 'Handcuffs' },'Garage': {'north': 'invalid','South': 'Kitchen','Item': 'Rc Car'},'Dads Man Cave': {'north': 'invalid','West': 'Parents Office','Item': 'Infiltrator'}
}
    next = rooms[currentloc][direction]
    if next.lower() == 'invalid':
        print("You can't go that direction!")
        return currentloc
    else:
        return next


def player_stat(location):
    rooms = {
        'bedroom': {'north': 'Parents Office','Item': 'Handcuffs'},'Item': 'Infiltrator'}
}

    print('----------------------------')
    print('You are in {} with {}'.format(location,rooms[location]['Item']))
    print('----------------------------')



def play():
     currentRoom = 'bedroom'
     while currentRoom != 'Exit' or 'exit':
         player_move = input('Enter your move:\n')
         if player_move == 'Exit' or player_move == 'exit':
            currentRoom = 'Exit'
            print('Play again soon!')
            break
         elif player_move == 'South' or player_move == 'south':
            currentRoom = nextroom(currentRoom,'South')
            player_stat(currentRoom)
         elif player_move == 'north' or player_move == 'north':
            currentRoom = nextroom(currentRoom,'north')
            player_stat(currentRoom)
         elif player_move == 'West' or player_move == 'west':
            currentRoom = nextroom(currentRoom,'West')
            player_stat(currentRoom)
         elif player_move == 'East' or player_move == 'east':
            currentRoom = nextroom(currentRoom,'East')
            player_stat(currentRoom)




player_move = ''
intro()
instructions()
new_game = input('Do you want to play a game? (Yes or No): ')

if new_game == 'no' or new_game == 'No':
    print('Have a good day!')
elif new_game == 'yes' or new_game == 'Yes':
    play()

我知道我必须在玩家统计数据中加入以下代码显示收集的物品的运行总数..但正在寻找有关具体操作方法的进一步指导..

ItemsCollected.append(rooms[location]['Item'])

谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。