Toggle a cell's state between live and dead
(self, y, x)
| 66 | self.state[x, y] = 1 |
| 67 | |
| 68 | def toggle(self, y, x): |
| 69 | """Toggle a cell's state between live and dead""" |
| 70 | if x < 0 or self.X <= x or y < 0 or self.Y <= y: |
| 71 | raise ValueError("Coordinates out of range %i,%i" % (y, x)) |
| 72 | if (x, y) in self.state: |
| 73 | del self.state[x, y] |
| 74 | self.scr.addch(y + 1, x + 1, ' ') |
| 75 | else: |
| 76 | self.state[x, y] = 1 |
| 77 | if curses.has_colors(): |
| 78 | # Let's pick a random color! |
| 79 | self.scr.attrset(curses.color_pair(random.randrange(1, 7))) |
| 80 | self.scr.addch(y + 1, x + 1, self.char) |
| 81 | self.scr.attrset(0) |
| 82 | self.scr.refresh() |
| 83 | |
| 84 | def erase(self): |
| 85 | """Clear the entire board and update the board display""" |