i created a TicTacToe game. Was my first programming with Phyton. You can find it here https://github.com/danielhuesken/Thumby/blob/main/Games/TicTacToe/TicTacToe.py
Feedback is welcome ;)
Hello, I was looking through your code. Although I haven't had the chance to test it yet. I think that due to the Thumbys very limited storage, these lines become very redundant:
if (postion == 0):
if not playField[6]:
postion = 6
elif not playField[3]:
postion = 3
elif (postion == 6):
if not playField[3]:
postion = 3
elif not playField[0]:
postion = 0
elif (postion == 3):
if not playField[0]:
postion = 0
elif not playField[6]:
postion = 6
elif (postion == 1):
if not playField[7]:
postion = 7
elif not playField[4]:
postion = 4
. elif (postion == 7):
if not playField[4]:
postion = 4
elif not playField[1]:
postion = 1
elif (postion == 4):
if not playField[1]:
postion = 1
elif not playField[7]:
postion = 7
elif (postion == 2):
if not playField[8]:
postion = 8
elif not playField[5]:
postion = 5
elif (postion == 8):
if not playField[5]:
postion = 5
elif not playField[2]:
postion = 2
elif (postion == 5):
if not playField[2]:
postion = 2
elif not playField[8]:
postion = 8
if (thumby.buttonD.justPressed() == True):
if (postion == 0):
if not playField[3]:
postion = 3
elif not playField[6]:
postion = 6
elif (postion == 3):
if not playField[6]:
postion = 6
elif not playField[0]:
postion = 0
elif (postion == 6):
if not playField[0]:
postion = 0
elif not playField[3]:
postion = 3
elif (postion == 1):
if not playField[4]:
postion = 4
elif not playField[7]:
postion = 7
elif (postion == 4):
if not playField[7]:
postion = 7
elif not playField[1]:
postion = 1
elif (postion == 7):
if not playField[1]:
postion = 1
elif not playField[4]:
postion = 4
elif (postion == 2):
if not playField[5]:
postion = 5
elif not playField[8]:
postion = 8
elif (postion == 5):
if not playField[8]:
postion = 8
elif not playField[2]:
postion = 2
elif (postion == 8):
if not playField[2]:
postion = 2
elif not playField[5]:
postion = 5I'd suggest something like:
if thumby.buttonD.justPressed() or thumby.buttonU.justPressed():
for i in range(8):
if postion == i:
if i - 3 > 0 or i+3 > 8:
i -= 3
elif i + 3 < 8 or i - 3 < 0:
i += 3
if not playField[ i ]:
postion = i Note I'm on a cell phone so I haven't compiled this yet, but it or something similar should work.
Also I'd fix some of the misspellings as they make the code hard to read.