1
class Area():
def __init__(self, pos, desc):
self.pos = pos
self.desc = desc
area1 = Area([0,0], "desc")
area2 = Area([0,1], "desc")
area3 = Area([0,2], "desc")
area4 = Area([1,1], "desc")
area5 = Area([2,1], "desc")
area6 = Area([3,1], "desc")
area7 = Area([3,2], "desc")
map_coordinates = [area1.pos, area2.pos, area3.pos, area4.pos, area5.pos, area6.pos, area7.pos]
player_pos = area1.pos
print type(map_coordinates)
print type(map_coordinates[2])
print type(player_pos)
def command(x):
print "\n" #Just for readability
global player_pos
old_pos = player_pos
if x == "north":
player_pos[1] += 1
if player_pos not in map_coordinates:
player_pos = old_pos
print "Can't go that way"
else:
print "You go north"
while True:
x = raw_input("type 'north' ")
command (x)
print player_pos
我在這裏想要做的是讓一個人如果座標位於map_coordinates時向北走,但如果他們超出界限則停止它們。然而,發生的卻是玩家可以永遠向北,而「不能這樣走」永遠不會被打印出來。我的猜測是'in'關鍵字播放不好,但所有類型都是列表。Python:不想一起工作的列表
'map_coordinates'是'list's的'list'。 –