Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import curses
- import random
- class Cell:
- alive = False
- def arise(self):
- self.alive = True
- def kill(self):
- self.alive = False
- class Grid:
- def __init__(self, height, width):
- self.height = height
- self.width = width
- self.grid = [[Cell() for y in range(height)] for x in range(width)]
- def countAliveNeighbours(self, y, x):
- c = 0
- class gui:
- def __init__(self, screen, grid):
- self.screen = screen
- self.grid = grid
- def drawBorder(self):
- pass
- def main(screen):
- num_rows, num_cols = screen.getmaxyx()
- screen.addstr("cols: " + str(num_cols) + "\n")
- screen.addstr("rows: " + str(num_rows))
- screen.refresh()
- screen.getch()
- grid = Grid(num_rows, num_cols)
- screen.clear()
- gameRandomizer(screen, grid)
- drawMap(screen, grid)
- screen.refresh()
- screen.getch()
- def gameRandomizer(screen, grid: Grid, qty = 100):
- initialCells = random.randrange(1,qty)
- for cell in range(initialCells):
- y = random.randrange(1, grid.height)
- x = random.randrange(1, grid.width)
- while grid.grid[x][y].alive == True:
- y = random.randrange(1, grid.height)
- x = random.randrange(1, grid.width)
- grid.grid[x][y].arise()
- def drawMap(screen, grid: Grid):
- for x in range(grid.width):
- for y in range(grid.height):
- if grid.grid[x][y].alive == True:
- drawCell(screen, y, x)
- def drawCell(screen, y, x, sign="x"):
- screen.addstr(y, x, "x")
- if __name__ == "__main__":
- curses.wrapper(main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement