I am trying to make a Tic Tac Toe game in Python using the Zellegraphics module. I want to use getMouse for mouse input but I am unable to figure out how to make getMouse to work on one cell of the board. I defined 9 different squares and what I want to do is that if the user clicks on one certain square, I want to draw the X or the O there. I can’t figure out how to do that, because as far as I know, getMouse only acts on the whole window.
I am trying to make a Tic Tac Toe game in Python using the
Share
If you have some X and Y coordinates in the window (let’s call them, say,
window_xandwindow_y) and you want to get the coordinates on a grid (let’s call themgrid_x, andgrid_y), and each grid cell has a width and height ofgrid_size, it is relatively easy to calculategrid_xandgrid_y: simply integer divide (round down; in Python, that would be the//operator)window_xbygrid_sizeto getgrid_x. You can probably figure outgrid_y.