login
sign up
forgot your
password?
By clicking on the squares try to convert all squares to black.
Lights Out |
|
0 1 2 3 4 5 6 |
rectangle1 = rectangle(x=4, y=4, width=4, height=4, fillColor=color.yellow)
def onClick(event, cell): '''Reverses the given cell's and its neighbors' colors. If all cells are black you win.''' for square in cell.neighbors + [cell]: if square.fillColor == color.yellow: square.fillColor = color.black else: square.fillColor = color.yellow redraw() if color.yellow in [c.fillColor for c in board.cells]: return messageBox('Congratulations') rectangle1.bind(LEFTDOWN, onClick) board = Grid(rows=5, cols=5, obj=rectangle1) def reset(event=None): '''Sets all cells' color to yellow''' for cell in board.cells: cell.fillColor = color.yellow redraw() button1 = button(pos=(40, 16), size=(80, 24), label="Reset", onClick=reset) system.box.active = False messageBox("To start, toggle interactive mode (Gear shaped icon)") ... ... |