Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@ -15,6 +15,8 @@ class TicTacToe
|
||||
this.canvas = canvas
|
||||
this.context = this.canvas.getContext("2d");
|
||||
this.blitz = blitz;
|
||||
this.sign = "cross";
|
||||
this.outline = false;
|
||||
}
|
||||
|
||||
init()
|
||||
@ -24,7 +26,7 @@ class TicTacToe
|
||||
|
||||
uninit()
|
||||
{
|
||||
this.canvas.addEventListener("mousedown", (event, morpion = this) => this.onClick(event, morpion));
|
||||
this.canvas.removeEventListener("mousedown", (event, morpion = this) => this.onClick(event, morpion));
|
||||
}
|
||||
|
||||
onClick(event, morpion)
|
||||
@ -47,6 +49,34 @@ class TicTacToe
|
||||
function sendCase(targetMorpion, targetCase)
|
||||
{
|
||||
// send to backend (stp camille code bien)
|
||||
morpion.game[targetMorpion][targetCase] = (morpion.sign == "cross") ? 0 : 1;
|
||||
}
|
||||
|
||||
function printSign(targetMorpion, targetCase)
|
||||
{
|
||||
let targetX = (morpion.gap + targetMorpion % 3 * morpion.rectsize * 3) + (targetCase % 3 * morpion.rectsize);
|
||||
let targetY = (morpion.gap + Math.floor(targetMorpion / 3) * morpion.rectsize * 3) + (Math.floor(targetCase / 3) * morpion.rectsize);
|
||||
if (morpion.sign == "cross")
|
||||
{
|
||||
morpion.context.beginPath();
|
||||
morpion.context.strokeStyle = "green";
|
||||
morpion.context.moveTo(targetX + 15, targetY + 15);
|
||||
morpion.context.lineTo(targetX + 45, targetY + 45);
|
||||
morpion.context.moveTo(targetX + 45, targetY + 15);
|
||||
morpion.context.lineTo(targetX + 15, targetY + 45);
|
||||
morpion.context.stroke();
|
||||
morpion.context.closePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
morpion.context.beginPath();
|
||||
morpion.context.strokeStyle = "red";
|
||||
targetX += morpion.rectsize / 2;
|
||||
targetY += morpion.rectsize / 2;
|
||||
morpion.context.arc(targetX, targetY, 20, 0, 2 * Math.PI);
|
||||
morpion.context.stroke();
|
||||
morpion.context.closePath();
|
||||
}
|
||||
}
|
||||
|
||||
function findPlace(x, morpion)
|
||||
@ -73,13 +103,38 @@ class TicTacToe
|
||||
return -1;
|
||||
}
|
||||
|
||||
function setOutline()
|
||||
{
|
||||
if (morpion.outline)
|
||||
{
|
||||
morpion.context.beginPath();
|
||||
morpion.context.strokeStyle = (morpion.sign == "cross") ? "green" : "red";
|
||||
morpion.context.roundRect(0, 0, morpion.canvas.width, morpion.canvas.height, 25);
|
||||
morpion.context.stroke();
|
||||
morpion.context.closePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
morpion.context.beginPath();
|
||||
morpion.context.strokeStyle = "#1a1a1d";
|
||||
morpion.context.roundRect(0, 0, morpion.canvas.width, morpion.canvas.height, 25);
|
||||
morpion.context.stroke();
|
||||
morpion.context.closePath();
|
||||
}
|
||||
morpion.outline = !morpion.outline;
|
||||
}
|
||||
|
||||
targetMorpion = findPlace(x, this) + findPlace(y, this) * 3;
|
||||
if (findPlace(x, this) < 0 || findPlace(y, this) < 0)
|
||||
return -1;
|
||||
targetCase = findSquare(x, this.rectsize * 3 * findPlace(x, this) + this.gap, this) + findSquare(y, this.rectsize * 3 * findPlace(y, this) + this.gap, this) * 3;
|
||||
|
||||
if (checkCase(targetMorpion, targetCase))
|
||||
{
|
||||
sendCase(targetMorpion, targetCase);
|
||||
printSign(targetMorpion, targetCase);
|
||||
setOutline();
|
||||
}
|
||||
else
|
||||
incorrectCase();
|
||||
}
|
||||
@ -145,13 +200,25 @@ class TicTacToe
|
||||
|
||||
}
|
||||
|
||||
SetOutline(color)
|
||||
setOutline()
|
||||
{
|
||||
this.context.beginPath();
|
||||
this.context.strokeStyle = color;
|
||||
this.context.roundRect(0, 0, this.canvas.width, this.canvas.height, 25);
|
||||
this.context.stroke();
|
||||
this.context.closePath();
|
||||
if (this.outline)
|
||||
{
|
||||
this.context.beginPath();
|
||||
this.context.strokeStyle = (this.sign == "cross") ? "green" : "red";
|
||||
this.context.roundRect(0, 0, this.canvas.width, this.canvas.height, 25);
|
||||
this.context.stroke();
|
||||
this.context.closePath();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.context.beginPath();
|
||||
this.context.strokeStyle = "#1a1a1d";
|
||||
this.context.roundRect(0, 0, this.canvas.width, this.canvas.height, 25);
|
||||
this.context.stroke();
|
||||
this.context.closePath();
|
||||
}
|
||||
this.outline = !this.outline;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user