Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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 map()的参数2必须支持迭代_Python_List_Arguments_Pygame_Iteration - Fatal编程技术网

Python map()的参数2必须支持迭代

Python map()的参数2必须支持迭代,python,list,arguments,pygame,iteration,Python,List,Arguments,Pygame,Iteration,大家好,我正在制作一个基本的raycast引擎,所以我认为从minimap开始会很好,但问题是我的类映射在构造函数中要求一个mapGrid,当我传递它时,python给我这个错误参数2 to map()必须支持迭代 代码如下: 主体 import pygame def map(object): def __init__(self,grid,scale): self.grid= grid self.mapWidth= len(grid[0]) #Number

大家好,我正在制作一个基本的raycast引擎,所以我认为从minimap开始会很好,但问题是我的类映射在构造函数中要求一个mapGrid,当我传递它时,python给我这个错误
参数2 to map()必须支持迭代

代码如下: 主体

import pygame
def map(object):
    def __init__(self,grid,scale):
        self.grid= grid
        self.mapWidth= len(grid[0]) #Number of map blocks
        self.mapHeight= len(grid) 
        self.miniMapScale= scale #How many pixels to draw a map block
        self.miniWidth= self.mapWidth * self.miniMapScale #Size of the minimap
        self.miniHeight= self.mapHeight * self.miniMapScale

        self.rectGrid= grid

        for y in range(self.mapHeight):
            for x in range(self.mapWidth):
                self.rectGrid[y][x]= pygame.Rect(x,y,self.miniWidth,self.miniHeight)

    def blitMiniMap():
        pass
数据文件

mapGrid= [
    [1,1,1,1],
    [1,0,0,1],
    [1,0,0,1],
    [1,1,1,1]
]

size = [640, 480]
地图类

import pygame
def map(object):
    def __init__(self,grid,scale):
        self.grid= grid
        self.mapWidth= len(grid[0]) #Number of map blocks
        self.mapHeight= len(grid) 
        self.miniMapScale= scale #How many pixels to draw a map block
        self.miniWidth= self.mapWidth * self.miniMapScale #Size of the minimap
        self.miniHeight= self.mapHeight * self.miniMapScale

        self.rectGrid= grid

        for y in range(self.mapHeight):
            for x in range(self.mapWidth):
                self.rectGrid[y][x]= pygame.Rect(x,y,self.miniWidth,self.miniHeight)

    def blitMiniMap():
        pass 

谢谢。

map
是python的内置函数。使用<代码> map < /COD>作为函数名,从而导致混淆,因此您应该考虑将您的<代码> map < /C>函数改为不同的。


此外,您所谓的“映射类”只定义了一个函数,而不是一个类。您是否将类定义中的
def
class
混淆?

您确定必须发布两次相同的代码?有一个名为
map
的内置函数,它有两个参数要传递给它