diff --git a/frontend/static/js/api/Matchmaking.js b/frontend/static/js/api/Matchmaking.js index 1bbec59..7081c5e 100644 --- a/frontend/static/js/api/Matchmaking.js +++ b/frontend/static/js/api/Matchmaking.js @@ -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); diff --git a/frontend/static/js/api/game/TicTacToeGame.js b/frontend/static/js/api/game/TicTacToeGame.js index 871a465..08ddb78 100644 --- a/frontend/static/js/api/game/TicTacToeGame.js +++ b/frontend/static/js/api/game/TicTacToeGame.js @@ -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() diff --git a/frontend/static/js/api/game/sounds/incorrectbuzzer.mp3 b/frontend/static/js/api/game/sounds/incorrectbuzzer.mp3 new file mode 100644 index 0000000..3df61fd Binary files /dev/null and b/frontend/static/js/api/game/sounds/incorrectbuzzer.mp3 differ