如何有效地为基于文本的游戏锁定房间?

2024-04-27 01:14:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我在这个游戏中使用python2.7。我看过其他类似的答案和问题,但由于我是一个python初学者,有一些python的经验,所以我不太理解其中的一些答案,而且我看到的一些答案也不太清楚。由于我目前的代码,它产生了一个问题,当我得到解锁房间所需的物品时,它说房间还没有找到。代码如下:

## checks which connecting rooms player.currentRoom has available and updates currentRoom on player choice.
def navigate(player,enemyToken):
    os.system("clear")

    # print available rooms to navigate to
    i = 0
    for room in player.currentRoom.connectingRooms:
        print(str(i) + ": " + room.name)
        i = i + 1

    try:
        navigate = input("Choose room to navigate to [type its number]: ")

        # change players current room to selected room and contains the locking code after the "and".
        if(navigate <= len(player.currentRoom.connectingRooms) and player.items[0].unlocks == room == True): 
            player.currentRoom = player.currentRoom.connectingRooms[navigate]
        else:
            print("room not found!")
            time.sleep(1)
    except NameError:
        print("that was not a number!")
        time.sleep(1)
    except SyntaxError:
        print("that was not a number!")
        time.sleep(1)
    except IndexError:
        print("that was not an option!")
        time.sleep(2)

我该如何做一个锁,成功地锁定玩家访问该房间,直到他们抓住了打开这个房间所需的对象。如果你需要更多的代码来帮助我,我会提供它。你知道吗


Tags: andto答案代码numbertimenotsleep
2条回答

根据我的评论,这个代码应该是word(未测试,因为我不知道锁机制应该去哪里)

代码:

x = True
while x = True:
    if LockRoom != RoomUnlock:
        Code here
    else:
        Code here when you unlock the room
        x = False

player.items[0].unlocks == room == True

我觉得这部分很奇怪。player.items项目[0].unlocks==空间应该足够检查这两个数字是否匹配。你知道吗

相关问题 更多 >