我有一本字典,可以生成“地图” e、 g.元组(x,y):mappile
mapGenCode = {(1, 1): 0, (2, 1): 1, (3, 1): 0, (1, 2): 0, (2, 2): 2, (3, 2): 1}
我试图实现的是,当按下键盘箭头时,同一字典中的所有x/y值都会增加+1/-1
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_loc = x_loc-1
x_map -1
mapRefresh(x_map, y_map)
def mapRefresh(x, y):
if x == -1:
for (key1, key2), value in mapGenCode.iteritems():
newkeyX = key1 -1
mapGenCode[newKey1, key2] = value
我以前遇到过这个错误
runtimeerror: dictionary changed size during iteration
代替“for key,value in dic”,您可以考虑以下代码
相关问题 更多 >
编程相关推荐