asweigart / my_first_tic_tac_toe

My first Tic Tac Toe program. I welcome any code reviews and pull requests!
625 stars 54 forks source link

2D version #16

Open bitbug42 opened 4 years ago

bitbug42 commented 4 years ago

While a console project is cool as a draft, a graphical version would be nice to appeal to a casual audience.

Rendering could be done using a graphic API like this:

screen.set_pixel(0,0, "#000000") # Black border
screen.set_pixel(1,0, "#ffffff") # 1st pixel of the 1st tile
screen.set_pixel(2,0, "#ffffff") # 2nd pixel of the 1st tile

etc...

Then detecting mouse clicks could be done in this way: (set "move" to None if the cursor is not over a clickable cell, or the cell number otherwise)

x, y = get_mouse_position()
if x == 0 and y == 0: move = None
if x == 1 and y == 0: move = 1
if x == 2 and y == 0: move = 1
# ...
if x == 50 and y == 50: move = 5
# ...