Created
May 8, 2023 14:13
-
-
Save ssaurel/a9efe9e752fa307563d1dac0afbc2617 to your computer and use it in GitHub Desktop.
onclick 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 onclick(self, event): | |
if self.game.solved: | |
self.game.newgame() | |
self.drawboard() | |
return | |
# we get coordinates of the user's click | |
idx = int(event.x) | |
idy = int(event.y) | |
# check if you must flip a column or a row | |
if (idx > 0 and idx < 100 and idy > 100 and idy < 600) or (idx > 600 and idx < 700 and idy > 100 and idy < 600): | |
# we need to flip a row | |
squaresize = 500 / self.game.level | |
row = int((idy - 100) / squaresize) | |
self.game.fliprow(row) | |
elif (idy > 0 and idy < 100 and idx > 100 and idx < 600) or (idy > 600 and idy < 800 and idx > 100 and idx < 600): | |
# we need to flip a col | |
squaresize = 500 / self.game.level | |
col = int((idx - 100) / squaresize) | |
self.game.flipcol(col) | |
self.drawboard() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment