Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created May 8, 2023 14:13
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/a9efe9e752fa307563d1dac0afbc2617 to your computer and use it in GitHub Desktop.
Save ssaurel/a9efe9e752fa307563d1dac0afbc2617 to your computer and use it in GitHub Desktop.
onclick method for a Flipping Bits Game on the SSaurel's Blog
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