def setCell(self, event): cellWidth, cellHeight = self.config.attr.game.cell.size x, y = int(event.posx)/cellWidth, int(event.posy)/cellHeight if self.game.habitat.setCell(x, y): #The value ten means hi will live for 10 generations self.cellStates[x][y] = 10 cellSprite = CellSprite(self.screen) cellSprite.put((x, y)) pygame.display.flip() self.trigger(CellAddedEvent())
def redraw(self): """ Force redraw of all the screen """ habitatSprite = HabitatSprite(self.screen) cellSprite = CellSprite(self.screen) habitatSprite.generate() for i in range(self.game.habitat.gridSize[0]): for j in range(self.game.habitat.gridSize[1]): if self.game.habitat.grid[i][j]: cellSprite.put((i,j))
def updateCells(self): cellSprite = CellSprite(self.screen) for i in range(self.game.habitat.gridSize[0]): for j in range(self.game.habitat.gridSize[1]): #If a cell is setted to keeps alive if self.cellStates[i][j] > 1: self.cellStates[i][j] -= 1 self.game.habitat.grid[i][j] = 1 if self.game.habitat.grid[i][j]: if not self.cellStates[i][j]: self.cellStates[i][j] = 1 cellSprite.put((i, j)) elif self.cellStates[i][j]: self.cellStates[i][j] = 0 cellSprite.remove((i, j))