Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python for循环溢出?_Python_For Loop_Pygame - Fatal编程技术网

Python for循环溢出?

Python for循环溢出?,python,for-loop,pygame,Python,For Loop,Pygame,我对这个代码片段有一点问题: GrasTexture = pygame.image.load('Textures/Grounds/Gras.png') StoneTexture = pygame.image.load('Textures/Grounds/Stone.png') PathTexture = pygame.image.load('Textures/Grounds/Path.png') SandTexture = pygame.image.load('Textures/Grounds/

我对这个代码片段有一点问题:

GrasTexture = pygame.image.load('Textures/Grounds/Gras.png')
StoneTexture = pygame.image.load('Textures/Grounds/Stone.png')
PathTexture = pygame.image.load('Textures/Grounds/Path.png')
SandTexture = pygame.image.load('Textures/Grounds/Sand.png')
SnowTexture = pygame.image.load('Textures/Grounds/Snow.png')
WaterTexture = pygame.image.load('Textures/Grounds/Water.png')
for i in range(936000):
        if(mapList[i][0] == 0):
            screen.blit(GrasTexture, (posX,posY))
        elif(mapList[i][0] == 1):
            screen.blit(StoneTexture, (posX,posY))
        elif(mapList[i][0] == 2):
            screen.blit(PathTexture, (posX,posY))
        elif(mapList[i][0] == 3):
            screen.blit(SandTexture, (posX,posY))
        elif(mapList[i][0] == 4):
            screen.blit(SnowTexture, (posX,posY))
        elif(mapList[i][0] == 5):
            screen.blit(WaterTexture, (posX,posY))
        if(posX != 144000):
            posX += 80
        else:
            posY += 80
            posX = 0
地图是这样创建的:

list01 =  [[0,0,0] for i in range(936000)]
f = open("map.txt", "w")
f.write(str(list01))
f.close()
f = open("map.txt", "r")
mapList = f.read()
mapList = ast.literal_eval(mapList)
f.close()
问题是: 当我更改贴图列表中的某些内容(如贴图列表[0][0]=4)时,纹理不会更改。 但是当我切断for循环并用0替换I时。纹理是正确的。
那么我的问题是什么?请帮帮我

“更改地图列表中的某些内容,如地图列表[0][0]==4”,这是什么意思?如果您认为mapList[0][0]==4将进行赋值;这是一个相等检查,将返回True或False。请使用不起作用的代码段更新您的代码。您不会显示将4指定给mapList的位置。这很可能就是错误所在。如果在f之后添加这些行,输出是什么。close“|”只是我用于行尾的分隔符。?打印更改地图|打印地图列表[0][0]|地图列表[0][0]=5 |打印地图列表[0][0]这是您可能希望在某些python版本中使用xrange的情况。更改地图| 0 | 5表明地图列表[0][0]是零,而不是4。在for循环之前打印一次怎么样:printmapList[0][0],posX,posY。