add: tictactoe: timers on catchup
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { client, lang } from "../../../index.js";
|
||||
import { client, lang, navigateTo } from "../../../index.js";
|
||||
|
||||
import { AGame } from "../AGame.js";
|
||||
|
||||
@ -50,7 +50,7 @@ class TicTacToe
|
||||
this.game.finished = false;
|
||||
if (this.turn)
|
||||
this.setOutline(4, false);
|
||||
this.printTimer();
|
||||
this.printTimer(20);
|
||||
break;
|
||||
|
||||
case 'game_move':
|
||||
@ -59,7 +59,7 @@ class TicTacToe
|
||||
this.map[messageData.targetMorpion][messageData.targetCase] = (this.sign == "x") ? 1 : 0;
|
||||
this.printSign(messageData.targetMorpion, messageData.targetCase, (this.sign == "x") ? "o" : "x");
|
||||
this.setOutline(this.currentMorpion, false);
|
||||
this.printTimer();
|
||||
this.printTimer(20);
|
||||
break;
|
||||
|
||||
case 'game_end':
|
||||
@ -68,6 +68,7 @@ class TicTacToe
|
||||
this.printWin(messageData.winning_sign);
|
||||
break;
|
||||
case 'catchup':
|
||||
this.game.finished = messageData.finished
|
||||
this.map = messageData.morpion;
|
||||
for (let i = 0; i < 9; i++)
|
||||
{
|
||||
@ -81,6 +82,7 @@ class TicTacToe
|
||||
this.currentMorpion = messageData.currentMorpion;
|
||||
if (this.turn)
|
||||
this.setOutline(this.currentMorpion, false);
|
||||
this.printTimer(Math.floor(messageData.timer));
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,10 +98,15 @@ class TicTacToe
|
||||
this.context.fillText((winning_sign == "o") ? lang.get("morpionWin") + "O" : lang.get("morpionWin") + "X", this.width / 2 - 85, this.height - this.gap / 2 + 10, 180);
|
||||
}
|
||||
|
||||
printTimer()
|
||||
printTimer(sec)
|
||||
{
|
||||
let sec = 20;
|
||||
let turn = this.turn
|
||||
let turn = this.turn;
|
||||
|
||||
if (sec <= 0)
|
||||
{
|
||||
this.game.send(JSON.stringify({"timerIsDue" : this.sign}))
|
||||
return;
|
||||
}
|
||||
if (this.turn)
|
||||
{
|
||||
this.context.beginPath();
|
||||
@ -115,10 +122,10 @@ class TicTacToe
|
||||
this.context.fillStyle = "#1a1a1d";
|
||||
this.context.fillRect(this.width / 2 - 40, 0, this.width / 2 + 40, this.gap - 10)
|
||||
this.context.closePath();
|
||||
if (sec == 0 || turn != this.turn || this.game.finished)
|
||||
if (sec <= 0 || turn != this.turn || this.game.finished)
|
||||
{
|
||||
clearInterval(id);
|
||||
if (sec == 0 && !this.turn && this.game.finished == false)
|
||||
if (sec <= 0 && this.game.finished == false)
|
||||
this.game.send(JSON.stringify({"timerIsDue" : this.sign}))
|
||||
return;
|
||||
}
|
||||
@ -175,7 +182,7 @@ class TicTacToe
|
||||
{
|
||||
morpion.setOutline(this.currentMorpion, true);
|
||||
morpion.sendCase(targetMorpion, targetCase);
|
||||
morpion.printTimer()
|
||||
morpion.printTimer(20)
|
||||
}
|
||||
else
|
||||
morpion.incorrectCase();
|
||||
@ -221,7 +228,7 @@ class TicTacToe
|
||||
this.context.strokeStyle = "red";
|
||||
targetX += this.rectsize / 2;
|
||||
targetY += this.rectsize / 2;
|
||||
this.context.arc(targetX, targetY, 15, 0, 2 * Math.PI);
|
||||
this.context.arc(targetX, targetY, this.rectsize / 2 - 7, 0, 2 * Math.PI);
|
||||
this.context.stroke();
|
||||
this.context.closePath();
|
||||
}
|
||||
|
Reference in New Issue
Block a user