Merge branch 'main' of codeberg.org:adrien-lsh/ft_transcendence

This commit is contained in:
2024-05-05 09:33:10 +02:00
6 changed files with 45 additions and 32 deletions

View File

@ -30,6 +30,11 @@ export class Profile extends AExchangeable
*/
this.avatar = avatar;
/**
* @type {Boolean}
**/
this.online = null;
/**
* @type {Boolean}
*/
@ -58,6 +63,7 @@ export class Profile extends AExchangeable
this.id = response_data.id;
this.username = response_data.username;
this.avatar = response_data.avatar;
this.online = response_data.online
if (!this.client.me || this.client.me.id === this.id)
return;

View File

@ -43,13 +43,12 @@ class TicTacToe
case 'o':
this.sign = messageData.detail;
this.turn = messageData.detail == "x";
if (this.turn)
this.setOutline(4, false);
break;
case 'game_start':
this.game.started = true;
this.game.finished = false;
if (this.turn)
this.setOutline(4, false);
break;
case 'game_move':
@ -63,6 +62,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 +111,6 @@ class TicTacToe
return -1
}
}
printWin()
{
}
onClick(event, morpion)
{
let x = event.offsetX;
@ -142,9 +150,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;
}