我将这些不同的对象存储在数据字典中并且正在切换使用currentmap
变量打印的对象,但是当我更改data.tilemaps
的索引时,如果我无关紧要将其设置为0或1,它始终只显示数据字典中定义的第一个地图的tilemap。为什么会这样?
class Map:
grid = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]
object = []
def __init__(self):
self.loadMap()
def loadMap(self):
for x in range(18):
for y in range(20):
print(str(self.maplist[x][y])+", ("+str(x)+","+str(y)+")")
#print(len(self.grid[0]))
self.grid[x].append(Tile(self.maplist[x][y], y, x))
def printMap(self):
for x in range(18):
for y in range(20):
self.grid[x][y].printTile()
class HomeIsland(Map):
maplist = ((0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
(0,0,0,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
(0,0,4,2,2,2,4,4,0,0,0,0,0,0,0,0,0,0,0,0),
(0,0,4,2,2,2,2,2,4,0,0,0,0,0,0,0,0,0,0,0),
(0,0,4,2,2,2,2,2,2,4,4,4,0,0,0,0,0,0,0,0),
(0,0,4,2,2,2,5,2,2,2,2,4,4,4,4,0,0,0,0,0),
(0,0,0,4,2,2,2,2,2,2,2,2,2,2,2,4,4,0,0,0),
(0,0,0,0,3,3,3,3,3,9,9,3,3,2,2,2,4,4,0,0),
(0,0,0,0,3,3,3,3,3,9,9,3,3,3,2,2,2,4,4,0),
(0,0,0,0,4,4,2,2,2,2,2,2,3,3,3,2,2,2,4,0),
(0,0,0,0,4,4,2,2,2,8,2,2,2,3,3,2,2,2,4,0),
(0,0,0,0,4,4,2,2,2,2,2,2,2,3,3,2,2,4,0,0),
(0,0,0,0,4,1,6,2,2,2,2,2,2,3,3,2,2,4,0,0),
(0,0,0,4,1,1,1,1,1,1,1,2,2,2,3,3,2,4,0,0),
(0,0,0,4,1,1,7,7,7,1,1,1,2,2,3,3,2,4,0,0),
(0,0,4,1,1,1,7,7,7,1,1,1,1,2,3,3,2,4,0,0),
(0,0,4,1,1,1,1,1,1,1,1,1,1,2,3,3,2,4,0,0),
(0,0,4,1,1,1,1,1,1,1,1,1,1,2,3,3,2,2,4,0))
class DungeonHub(Map):
maplist = ((0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
(0,0,0,0,0,12,12,12,12,12,12,12,12,12,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,11,10,10,11,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,11,10,10,11,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,11,10,10,11,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,11,10,10,11,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,10,10,10,10,10,10,10,10,12,0,0,0,0,0),
(0,0,0,0,0,12,12,12,12,12,12,12,12,12,12,0,0,0,0,0),
(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))
class Data:
def loadTileMaps(self):
self.tilemaps = {
0:DungeonHub(),
1:HomeIsland()
}
class Game:
def __init__(self):
pygame.init()
xsize = 1000
ysize = 1000
self.surface = pygame.display.set_mode((xsize,ysize))
data.loadTileMaps()
def main(self):
while True:
self.ev = pygame.event.poll()
if self.ev.type == pygame.QUIT:
break
self.surface.fill((202, 205, 209))
currentmap.printMap()
currentmap.printAllObject()
pygame.display.flip()
pygame.time.delay(10)
currentmap = data.tilemaps[1]