add: tictactoe: Winning screen and backend end of game

This commit is contained in:
Namonay
2024-05-01 16:31:27 +02:00
parent 737b6fc194
commit d0a8d12934
3 changed files with 29 additions and 24 deletions

View File

@ -24,6 +24,8 @@ class TicTacToeGame(AGame):
self._map = [[-1 for _ in range(9)] for _ in range(9)]
self.winner = None
def _everbody_is_here(self):
return len(self.players) == len(self.get_players_connected())
@ -41,21 +43,18 @@ class TicTacToeGame(AGame):
return player
def add(self, newmove, player):
for i in self._map:
print(i)
print(newmove.get("targetMorpion"), newmove.get("targetCase"), newmove.get("sign"))
if (self.checkMove(newmove, player)):
if (self.checkMove(newmove, player) and self.checkWin() == False):
self._map[newmove.get("targetMorpion")][newmove.get("targetCase")] = newmove.get("sign")
player.currentMorpion = int(newmove.get("targetCase"))
self.turn = newmove.get("sign")
self.changeTurn()
return True
return False
def changeTurn(self):
self.turn = 'x' if (self.turn == 'o') else 'o'
def checkMove(self, newmove, player):
print(int(newmove.get("targetMorpion")), player.currentMorpion)
if (int(newmove.get("targetMorpion")) != player.currentMorpion or newmove.get("sign") != self.turn):
return False
@ -68,7 +67,7 @@ class TicTacToeGame(AGame):
for tab in self._map:
for i in range(3):
if tab[i] != -1 and tab[i] == tab[i + 3] and tab[i + 3] == tab[i + 6]:
return tab[i]
return
for i in range(0, 9, 3):
if tab[i] != -1 and tab[i] == tab[i + 1] and tab[i + 1] == tab[i + 2]:
return tab[i]