Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created May 8, 2023 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/2ad2f00f22aa9a4118685e628aa94984 to your computer and use it in GitHub Desktop.
Save ssaurel/2ad2f00f22aa9a4118685e628aa94984 to your computer and use it in GitHub Desktop.
drawboard method for a Flipping Bits Game on the SSaurel's Blog
def drawboard(self):
# we clean the canvas
self.canvas.delete("all")
squaresize = 500 / self.game.level
targetsize = squaresize / 10
for i in range(self.game.level):
x = 100 + i * squaresize
for j in range(self.game.level):
y = 100 + j * squaresize
value = self.game.board[i][j]
self.canvas.create_rectangle(x, y, x + squaresize, y + squaresize, fill = ("blue", "yellow")[value == 0])
# draw the target on the top left
target = self.game.target[i][j]
self.canvas.create_rectangle(x + 10, y + 10, x + 10 + targetsize, y + 10 + targetsize, fill = ("blue", "yellow")[target == 0])
if self.game.issolved():
self.canvas.create_text(200, 750, text = "Solved. Click to start a new game", font = ("Helvetica", "20", "bold"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment