Python文本RPG-处理while循环和if语句的困难
房间列表非常大,问题出在函数中,所以我没有包含这部分代码。列表中的每个条目基本上是:Python文本RPG-处理while循环和if语句的困难,python,Python,房间列表非常大,问题出在函数中,所以我没有包含这部分代码。列表中的每个条目基本上是: [room_description, # of room North, East, South, West] 问题是,每当我测试while循环和if语句以处理无效输入时,程序就会卡在while循环中,我不知道如何修复它 def room_movement(): current_room = 0 done = False print("") while done is False:
[room_description, # of room North, East, South, West]
问题是,每当我测试while循环和if语句以处理无效输入时,程序就会卡在while循环中,我不知道如何修复它
def room_movement():
current_room = 0
done = False
print("")
while done is False:
print(room_list[current_room][0])
print("")
direction = input("Which direction do you want to go?\n\n")
direction = direction.lower()
if direction == "north":
next_room = room_list[current_room][1]
if next_room is None:
while next_room is None:
print("When you try to move in that direction you are blocked by an invisible wall. Try again")
direction = input("\n")
if direction == "east":
next_room = room_list[current_room][2]
if direction == "south":
next_room = room_list[current_room][3]
if direction == "west":
next_room = room_list[current_room][4]
else:
direction = input("That wasn't a valid direction... Try again.\n")
else:
current_room = next_room
print(current_room)
current_room = next_room
print(current_room)
elif direction == "east":
next_room = room_list[current_room][2]
if next_room is None:
while next_room is None:
print("When you try to move in that direction you are blocked by an invisible wall. Try again")
direction = input("\n")
if direction == "north":
next_room = room_list[current_room][1]
if direction == "west":
next_room= room_list[current_room][4]
if direction == "south":
next_room = room_list[current_room][3]
else:
direction = input("That wasn't a valid direction... Try again.\n")
else:
current_room = next_room
print(current_room)
current_room = next_room
print(current_room)
elif direction == "south":
next_room = room_list[current_room][3]
if next_room is None:
while next_room is None:
print("When you try to move in that direction you are blocked by an invisible wall. Try again")
direction = input("\n")
if direction == "north":
next_room = room_list[current_room][1]
if direction == "east":
next_room = room_list[current_room][2]
if direction == "west":
next_room = room_list[current_room][4]
else:
direction = input("That wasn't a valid direction... Try again.\n")
else:
current_room = next_room
print(current_room)
current_room = next_room
print(current_room)
elif direction == "west":
next_room = room_list[current_room][4]
if next_room is None:
while next_room is None:
print("When you try to move in that direction you are blocked by an invisible wall. Try again")
direction = input("\n")
if direction == "north":
next_room = room_list[current_room][1]
if direction == "east":
next_room = room_list[current_room][2]
if direction == "south":
next_room = room_list[current_room][3]
else:
direction = input("That wasn't a valid direction... Try again.\n")
else:
current_room = next_room
print(current_room)
current_room = next_room
print(current_room)
else:
while direction != "north" or "south" or "west" or "east":
print("That command is beyond the system's intelligence. Try again")
direction = input("\n")
房间移动()我想你必须更具体地处理你的问题。首先,阅读并提取一个。另外,作为这里的新用户,请接受。我认为您必须更具体地解决您的问题。首先,阅读并提取一个。另外,作为这里的新用户,请使用。