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

@ -36,20 +36,18 @@ class TicTacToe
async onReceive(messageData)
{
console.log(messageData)
switch (messageData.detail)
{
case 'x':
case 'o':
this.sign = messageData.detail;
this.turn = messageData.detail == "x";
if (this.turn)
if (this.turn && this.game.started == false)
this.setOutline(4, false);
break;
case 'game_start':
this.game.started = true;
this.game.finished = false;
break;
case 'game_move':
@ -63,6 +61,20 @@ class TicTacToe
this.canvas.removeEventListener("mousedown", (event, morpion = this) => this.onClick(event, morpion));
this.printWin(messageData.winning_sign);
break;
case 'catchup':
this.map = messageData.morpion;
for (let i = 0; i < 9; i++)
{
for (let j = 0; j < 9; j++)
{
if (this.map[i][j] != -1)
this.printSign(i, j, this.map[i][j])
}
}
this.turn = (messageData.turn == this.sign);
this.currentMorpion = messageData.currentMorpion;
if (this.turn)
this.setOutline(this.currentMorpion, false);
}
}
@ -98,11 +110,6 @@ class TicTacToe
return -1
}
}
printWin()
{
}
onClick(event, morpion)
{
let x = event.offsetX;
@ -142,9 +149,7 @@ class TicTacToe
this.map[targetMorpion][targetCase] = (this.sign == "x") ? 0 : 1;
this.currentMorpion = targetCase;
this.printSign(targetMorpion, targetCase, this.sign);
console.log(targetMorpion, targetCase)
this.game.send(JSON.stringify({"targetMorpion" : targetMorpion, "targetCase" : targetCase, "sign" : this.sign}));
console.log(this.turn);
this.turn = !this.turn;
}