Created
May 8, 2023 14:12
-
-
Save ssaurel/2ad2f00f22aa9a4118685e628aa94984 to your computer and use it in GitHub Desktop.
drawboard method for a Flipping Bits Game on the SSaurel's Blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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