Python Forum
[PyGame] Got error in Tic Tac Toe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Got error in Tic Tac Toe
#2
You have a few bad habits as well as over-complicated processes.

bad habits:
You should not be using global keyword. You are asking for bugs.

over complicated:
It would be better to have 0 as O and 1 as X as a boolean, or whatever. Even better than that it would be better to have a dictionary or list of the positions and set them and then display them in their position for whatever the position's content is.

problem:
Your draw function is ran every iteration of the loop. This, in conjunction with you using global, means it flips back and forth for everyone, instead of how you intend it. Instead, once you set one save it in a dictionary/list, then simply just draw the entire dictionary/list.

fix with dictionary:
Which if it was a dictionary... key can be position while the value identifies it to be X or O. Set all the keys to be the positions with values set to None in the beginning. Draw the entire dictionary. Those that do not have an X or O value do not draw anything, but still retain the position in advance. When someone clicks on a square assign that position to be X or O only if it has none.
Recommended Tutorials:
Reply


Messages In This Thread
Got error in Tic Tac Toe - by Sahil - Dec-26-2020, 01:51 PM
RE: Got error in Tic Tac Toe - by metulburr - Dec-27-2020, 12:45 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020