Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
commit
201d285a2e
@ -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,14 +200,26 @@ class TicTacToe
|
||||
|
||||
}
|
||||
|
||||
SetOutline(color)
|
||||
setOutline()
|
||||
{
|
||||
if (this.outline)
|
||||
{
|
||||
this.context.beginPath();
|
||||
this.context.strokeStyle = color;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
export { TicTacToe };
|
@ -62,7 +62,7 @@
|
||||
"settingsAvatarDelete": "Décrampté",
|
||||
"settingsAvatarSaved": "Avatar crampté.",
|
||||
"settingsAvatarDeleted": "Avatar décrampté.",
|
||||
"settingsAvatarDeleteError": "Un cramptérreur s'est produite.",
|
||||
"settingsAvatarDeleteError": "Une cramptérreur s'est produite.",
|
||||
"settingsAvatarTooLarge": "L'image est trop crampté",
|
||||
"settingsTitle": "Paramètres de crampté",
|
||||
"settingsUsername": "Nom d'crampté",
|
||||
|
@ -17,8 +17,8 @@ export class TicTacToeOnlineView extends AbstractView
|
||||
{
|
||||
this.Morpion = new TicTacToe(this.height, this.width, 60, 60, document.getElementById("Morpion"));
|
||||
this.Morpion.DrawSuperMorpion();
|
||||
this.Morpion.SetOutline("#43d166");
|
||||
this.Morpion.init();
|
||||
this.Morpion.setOutline();
|
||||
}
|
||||
|
||||
async leavePage()
|
||||
@ -38,7 +38,6 @@ export class TicTacToeOnlineView extends AbstractView
|
||||
<canvas id="Morpion" width="${this.width}" height="${this.height}"></canvas>
|
||||
</div>
|
||||
<h1>Work in progress bozo</h1>
|
||||
<img src="https://cdn.discordapp.com/attachments/1089527100681240716/1219360784224616498/Snapinsta.app_424926392_1109913580191337_8974514051687331181_n_1080.jpg?ex=660b0539&is=65f89039&hm=25dbcab44e50ec8ca3019dab476293a1001c224c6b6312bd9e30fba1f72667b5&">
|
||||
<img src="https://cdn.discordapp.com/attachments/447859443867189250/1221824821680275576/cat-thumbs-up-middle-finger-cat.png?ex=6613fc09&is=66018709&hm=d901ea182d58ce0ab80fbcc119ae0b769f318c448ae55a6500607ddb8b3f6ff8&">
|
||||
<img src="https://cdn.discordapp.com/attachments/447859443867189250/1221824792148316180/thumbs-up-cat.png?ex=6613fc02&is=66018702&hm=16748a2df0cb8e8f111c0817ea456289333aa0f8047821e7ae4ea2e57720e843&">
|
||||
<img src="https://cdn.discordapp.com/attachments/447859443867189250/1221824753686548580/catthumbsup-cat.png?ex=6613fbf9&is=660186f9&hm=94e93b8db9f72fc146942dedf167a3d7476b3dced95ed5c3e80a4ccce8e27f9e&">`;
|
||||
|
Loading…
Reference in New Issue
Block a user