2017-10-27 5 views
0

私はコーディングの初心者です。私は単純な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() 
+0

実際には 'm.lower'メソッドを' m.lower() 'のように呼び出さなければなりません。 Pythonの関数とメソッドはそれ自身がオブジェクトなので、文字列と直接比較しようとしています –

+0

mooはfooのm.lower()ですか? – astidham2003

答えて

0

fooでは、関数定義m.lowerを文字と比較しています。関数を呼び出すにはm.lower()を試してください。

関連する問題