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

时间:2019-12-14 22:15:03

标签: python python-2.7

我正在为该游戏使用python 2.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)

我怎么做才能成功锁定玩家进入房间的锁,直到他们抓住了打开该房间所需的物体。如果您需要更多代码来帮助我,我会提供。

2 个答案:

答案 0 :(得分:2)

根据我的评论,此代码应为单词(未经测试,因为我不知道锁定机制应该去哪里

代码:

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

答案 1 :(得分:1)

  

player.items [0]。解锁==房间==真

这部分对我来说很奇怪。 player.items [0] .unlocks ==房间应该足以检查两个数字是否匹配。