如何在循环时停止此操作?

时间:2017-10-27 02:53:00

标签: python-3.x while-loop

我是编码的初学者,我正在制作一个简单的RPG。我目前只有4个房间。我希望游戏无限循环。我还希望游戏在输入无效命令时提示玩家输入有效命令,但是while循环无限重复。有人可以给我一个初学者可以理解的修复,也许还有一些指示? while循环是
while foo(move) == False:

def foo(m):
    """
    """
    if m.lower == 'l' or m.lower == 'r' or m.lower == 'help' or m.lower == 'pokemon':
        return True
    else:
        return False

print() #Put storyline here
print("You may input 'help' to display the commands.")
print()

gamePlay = True
floor4 = ['floor 4 room 4', 'floor 4 room 3', 'floor 4 room 2', 'floor 4 room 1']
floor4feature = ['nothing here', 'nothing here', 'stairs going down', 'a Squirtle']
currentRoom = 0
pokemonGot = ['Bulbasaur']

while gamePlay == True:
    print("You are on " + floor4[currentRoom] + ". You find " + floor4feature[currentRoom] + ".")
    move = input("What would you like to do? ")
    while foo(move) == False:
        move = input("There's a time and place for everything, but not now! What would you like to do? ")
    if move.lower() == 'l':
        if currentRoom > 0:
            currentRoom = currentRoom - 1
            print("Moved to " + floor4[currentRoom] + ".")
        else:
            print("*Bumping noise* Looks like you can't go that way...")
    elif move.lower() == 'r':
        if currentRoom < len(floor4) - 1:
            currentRoom = currentRoom + 1
            print("Moved to " + floor4[currentRoom] + ".")
        else:
            print("*Bumping noise* Looks like you can't go that way...")
    elif move.lower() == 'help':
        print("Input 'r' to move right. Input 'l' to move left. Input 'pokemon' to see what Pokemon are on your team. Input 'help' to see the commands again.")
    elif move.lower() == 'pokemon':
        print("The Pokemon on your team are: " + str(pokemonGot) + ".")
    print()

1 个答案:

答案 0 :(得分:0)

在foo中,您将函数定义m.lower与字符进行比较。尝试使用m.lower()来调用函数。