Fixed winx and win0 in tictactoe
This commit is contained in:
parent
d293185a28
commit
6f89e4a3e1
2 changed files with 14 additions and 1 deletions
|
|
@ -74,7 +74,17 @@ async function handleTTT(): Promise<RouteHandlerReturn> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'win') {
|
if (type === 'win') {
|
||||||
const youWin = (curGame?.playerX === user.id);
|
let youWin: boolean;
|
||||||
|
switch(player) {
|
||||||
|
case 'X':
|
||||||
|
youWin = (curGame?.playerX === user.id);
|
||||||
|
break ;
|
||||||
|
case 'O':
|
||||||
|
youWin = (curGame?.playerO === user.id);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (youWin)
|
if (youWin)
|
||||||
showSuccess('You won the game !');
|
showSuccess('You won the game !');
|
||||||
else
|
else
|
||||||
|
|
@ -118,7 +128,9 @@ async function handleTTT(): Promise<RouteHandlerReturn> {
|
||||||
|
|
||||||
cells?.forEach(function(c, idx) {
|
cells?.forEach(function(c, idx) {
|
||||||
c.addEventListener("click", () => {
|
c.addEventListener("click", () => {
|
||||||
|
if (socket) {
|
||||||
socket.emit("gameMove", { index: idx });
|
socket.emit("gameMove", { index: idx });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ export class StateI {
|
||||||
socket.on('debugInfo', () => this.debugSocket(socket));
|
socket.on('debugInfo', () => this.debugSocket(socket));
|
||||||
|
|
||||||
socket.on('gameMove', (e) => this.gameMove(socket, e));
|
socket.on('gameMove', (e) => this.gameMove(socket, e));
|
||||||
|
if (socket) {console.log('Socket:', socket.id);};
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateClient(socket: SSocket): void {
|
private updateClient(socket: SSocket): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue