def changeDimensions(self, nDim): newGrid = [[0 for i in range(nDim)] for j in range(nDim)] # expanding if nDim > self.DIM: for i in range(nDim): if i < self.DIM: for j in range(nDim): if j < self.DIM: newGrid[i][j] = self.grid[i][j] else: newGrid[i][j] = tile.Tile(i, j, const.DFLOOR1, self.defaultBkgd) else: for j in range(nDim): newGrid[i][j] = tile.Tile(i, j, const.DFLOOR1, self.defaultBkgd) self.grid = newGrid #shrinking elif self.DIM > nDim: self.grid = self.grid[:nDim] for i in range(nDim): self.grid[i] = self.grid[i][:nDim] #same else: return self.DIM = nDim self.cursorPos = (0, 0)
def __init__(self, dX, dY, defaultFloor): self.DIMX = dX self.DIMY = dY self.grid = [] self.portal = (0, 0) for i in range(self.DIMX): for j in range(self.DIMY): self.grid[i][j] = tile.Tile(i, j, defaultFloor) for i in range(self.DIMX): self.grid[i][0] = tile.Tile(i, j, 0)
def __init__(self, DIM, level, name): generalmap.__init__(self, DIM, const.VOID) self.level = level self.BFSQueue = queue.Queue() for i in range(self.DIM): self.grid += [range(self.DIM)] for j in range(self.DIM): self.grid[i][j] = tile.Tile(i, j, const.VOID, const.VOID) self.setName(name)
def place(self, x, y, nTile): if self.myMap.getEntry(x, y) == const.VOID: self.myMap.grid[x] = self.myMap.grid[x][:y] + [ tile.Tile(x, y, nTile, const.DFLOOR1) ] + self.myMap.grid[x][y + 1:] return if self.placeNPC: self.addNPC((x, y)) else: if self.drawLayer == 'back': self.myMap.setTileBG(x, y, nTile) return if self.currentTile == const.CHEST: self.myMap.addChest((x, y), self.fillChest([])) param = None elif self.currentTile == const.SIGN: param = self.getInput('Sign text: ') elif self.currentTile in const.doorsList: param = None else: param = None self.myMap.setEntry(x, y, nTile, param)
def __init__(self, mBall=None, name=None): generalmap.__init__(self, 2 * const.DIM) if mBall is not None: self.installBall(mBall) else: self.defaultBkgd = const.DFLOOR1 for i in range(self.DIM): self.grid += [range(self.DIM)] for j in range(self.DIM): self.grid[i][j] = tile.Tile(i, j, const.DFLOOR1, self.defaultBkgd) self.heroStart = None self.pointOfEntry = None self.pointOfExit = None self.portals = [] # location : (type, level) self.shops = {} self.setName('Untitled') self.level = 0 self.itemShop = None self.magicShop = None self.Armory = None self.Blacksmith = None self.Tavern = None self.Townhall = None for s in self.shops: if self.shops[s][0] == 'armory': self.Armory = s elif self.shops[s][0] == 'blacksmith': self.Blacksmith = s elif self.shops[s][0] == 'magicshop': self.magicShop = s elif self.shops[s][0] == 'itemshop': self.itemShop = s elif self.shops[s][0] == 'tavern': self.Tavern = s elif self.shops[s][0] == 'townhall': self.Townhall = s
def __init__(self, xdim, ydim, pos=(0, 0), shape='square'): self.pos = pos self.xdim = xdim self.ydim = ydim self.grid = [range(xdim) for _ in range(ydim)] for i in range(xdim): for j in range(ydim): self.grid[j][i] = tile.Tile(i, j, const.DFLOOR1, const.DFLOOR1) self.entrances = [] self.neighbors = [] self.secret = False if shape == 'square': (xpos, ypos) = self.getPos() (xdim, ydim) = self.getDimensions() for i in range(1, xdim - 1): self.setGrid(i, 0, const.EWWALL, const.DFLOOR1) self.setGrid(i, ydim - 1, const.EWWALL, const.DFLOOR1) for i in range(1, ydim - 1): self.setGrid(0, i, const.NSWALL, const.DFLOOR1) self.setGrid(xdim - 1, i, const.NSWALL, const.DFLOOR1) self.setGrid(0, 0, const.ULWALL, const.DFLOOR1) self.setGrid(xdim - 1, 0, const.URWALL, const.DFLOOR1) self.setGrid(0, ydim - 1, const.LLWALL, const.DFLOOR1) self.setGrid(xdim - 1, ydim - 1, const.LRWALL, const.DFLOOR1) for i in range(1, xdim - 1): for j in range(1, ydim - 1): self.setGrid(i, j, const.DFLOOR1, const.DFLOOR1) if shape == 'round': (xpos, ypos) = self.getPos() self.xdim = 9 self.ydim = 9 self.grid = [range(self.xdim) for _ in range(self.ydim)] layout = [[ const.VOID, const.VOID, const.ULWALL, const.EWWALL, const.EWWALL, const.EWWALL, const.URWALL, const.VOID, const.VOID ], [ const.VOID, const.ULWALL, const.LRWALL, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.LLWALL, const.URWALL, const.VOID ], [ const.ULWALL, const.LRWALL, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.LLWALL, const.URWALL ], [ const.NSWALL, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.NSWALL ], [ const.NSWALL, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.NSWALL ], [ const.NSWALL, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.NSWALL ], [ const.LLWALL, const.URWALL, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.ULWALL, const.LRWALL ], [ const.VOID, const.LLWALL, const.URWALL, const.DFLOOR1, const.DFLOOR1, const.DFLOOR1, const.ULWALL, const.LRWALL, const.VOID ], [ const.VOID, const.VOID, const.LLWALL, const.EWWALL, const.EWWALL, const.EWWALL, const.LRWALL, const.VOID, const.VOID ]] for i in range(self.xdim): for j in range(self.ydim): self.grid[j][i] = tile.Tile(i, j, layout[j][i], const.DFLOOR1)