add: loud buzzer

This commit is contained in:
Namonay 2024-03-25 14:53:38 +01:00 committed by AdrienLSH
parent 630f59055a
commit 8d6272c85d
3 changed files with 28 additions and 14 deletions

View File

@ -27,6 +27,7 @@ class MatchMaking
return null;
this.gamemode = gamemode
let url = `${window.location.protocol[4] === 's' ? 'wss' : 'ws'}://${window.location.host}/ws/matchmaking/${mode}`;
this._socket = new WebSocket(url);

View File

@ -19,16 +19,36 @@ class TicTacToe
init()
{
this.canvas.addEventListener("mousedown", (event) => { this.onClick(event) }, false);
this.canvas.addEventListener("mousedown", (event, morpion = this) => this.onClick(event, morpion));
}
uninit()
{
this.canvas.removeEventListener("mousedown", this.onClick, false);
this.canvas.addEventListener("mousedown", (event, morpion = this) => this.onClick(event, morpion));
}
onClick(event)
onClick(event, morpion)
{
let x = event.offsetX;
let y = event.offsetY;
let targetMorpion, targetCase;
function checkCase(targetMorpion, targetCase)
{
console.log("TargetMorpion :" + targetMorpion + " targetCase :" + targetCase);
return (morpion.game[targetMorpion][targetCase] == -1);
}
function incorrectCase()
{
console.log("bozo");
}
function sendCase(targetMorpion, targetCase)
{
// send to backend (stp camille code bien)
}
function findPlace(x, morpion)
{
if (x <= morpion.gap || x >= morpion.gap + morpion.rectsize * 9)
@ -53,22 +73,15 @@ class TicTacToe
return -1;
}
let x = event.offsetX;
let y = event.offsetY;
let targetMorpion, targetCase;
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;
console.log("TargetMorpion :" + targetMorpion + " targetCase :" + targetCase);
// if (sendCase(targetCase, targetMorpion)) // si la case est disponible
// putCase(targetCase, targetMorpion); // print the case
// else
// return ;
if (checkCase(targetMorpion, targetCase))
sendCase(targetMorpion, targetCase);
else
incorrectCase();
}
DrawSuperMorpion()

Binary file not shown.