Saturday, 17 August 2013

Dictionary not populating correctly

Dictionary not populating correctly

I've encountered an issue with my code that I simply cannot figure out.
As per the below section of code:
After creating a 2nd dictionary (worldmap) in the Generate_Game_World
class, the HQ location is stored in
self.worldmap[HQLOCATIONX,HQLOCATIONY]["Region_Type"] = "HQ"
However, after doing so it seems to fill up the entire array with the "HQ"
value as seen in the test window. I simply cannot figure out why this is
happening.
import pygame
from tkinter import *
test = Tk ()
test.geometry = ("640x480")
pygame.init()
WORLDSIZE = 499
HQLOCATIONX = int(WORLDSIZE/2)
HQLOCATIONY = int(WORLDSIZE/2)
class Generate_Game_World ():
regionData = {"Region_Type" : "None",
"Region_Level" : 0}
def __init__(self, mapSize):
self.mapSize = mapSize
def main (self):
# creates 2d map
self.worldmap = {(x,y) : self.regionData for x in
range(self.mapSize) for y in range (self.mapSize)}
# Sets the HQ to worldmap(249,249)
self.worldmap[HQLOCATIONX,HQLOCATIONY]["Region_Type"] = "HQ"
# checks worldmap(0,0) --> (10,10) for its Region Type
for x in range (10):
for y in range (10):
label = Label
(text=self.worldmap[x,y]["Region_Type"]).grid(row = x,
column=y)
class Game (object):
def main (self, screen):
gameworld = Generate_Game_World(WORLDSIZE)
gameworld.main()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
if event.type == pygame.KEYDOWN and event.key ==
pygame.K_ESCAPE:
return
test.mainloop()
pygame.display.flip()
if __name__ == "__main__":
screen = pygame.display.set_mode((1024, 768))
Game().main(screen)

No comments:

Post a Comment