diff --git a/businesses/Room.js b/businesses/Room.js index b15e4ca..50aec61 100644 --- a/businesses/Room.js +++ b/businesses/Room.js @@ -43,12 +43,12 @@ class Room { if (playedCase.isPlayed === false) { this.players.find((p) => p.id === this.ennemy).grid.cases[move.col][move.row].isPlayed = true; + ret = {isMove: true, players: this.players, isHit: playedCase.isShip, + isWin: this.checkWin(), player: this.actualPlayer} + let tmp = this.actualPlayer; this.actualPlayer = this.ennemy; this.ennemy = tmp; - - ret = {isMove: true, players: this.players, isHit: playedCase.isShip, - isWin: this.checkWin(), player: this.actualPlayer} } return ret diff --git a/index.js b/index.js index db02723..7474630 100644 --- a/index.js +++ b/index.js @@ -187,9 +187,20 @@ io.on("connection", (socket) => { }); }); - socket.on("ask for room", (roomId, id) => { + socket.on("ask for room", (roomId, id, callack) => { let room = rooms.find((r) => r.id === roomId); + if (room == null) { + callack({ + status: false + }) + return + } + + callack({ + status: true + }) + room.addPlayer(players.find((p) => p.id === id)); room.validBoards(); diff --git a/public/assets/style.css b/public/assets/style.css index 09b8cb0..7f27a19 100644 --- a/public/assets/style.css +++ b/public/assets/style.css @@ -34,6 +34,11 @@ background-color: rgba(0,0,0,0.4); } +#errorHandler { + margin-top: 3%; + color: red; +} + #opponentLeftModalContent { background-color: #fefefe; margin: 15% auto; diff --git a/public/pages/gameView.html b/public/pages/gameView.html index 4b5243f..8449290 100644 --- a/public/pages/gameView.html +++ b/public/pages/gameView.html @@ -33,6 +33,8 @@ + +
diff --git a/public/scripts/app.js b/public/scripts/app.js index 8a1c8f2..0e632dd 100644 --- a/public/scripts/app.js +++ b/public/scripts/app.js @@ -43,7 +43,6 @@ socket.on("play", () => { }); socket.on("played move", (isHit, isWin) => { - console.log("test") const hitNotification = document.querySelector("#hit_notification"); const winNotification = document.querySelector("#win_notification"); @@ -98,12 +97,20 @@ function onJoinRoom() { const loader = document.querySelector("#loader"); const roomKey = document.querySelector("#roomKey").value; const roomkeyHolder = document.querySelector("#roomkeyHolder"); - - loader.classList.add("hidden-element"); + const errorHolder = document.querySelector("#errorHandler") roomId = roomKey; - roomkeyHolder.innerHTML += `Your room key is : ` + roomId + ``; - socket.emit("ask for room", roomKey, socket.id); + + socket.emit("ask for room", roomKey, socket.id, (response) => { + if (response.status !== true) { + if (errorHolder.textContent == "") { + errorHolder.append("Error : Room Id don't exist") + } + } else { + loader.classList.add("hidden-element"); + roomkeyHolder.innerHTML += `Your room key is : ` + roomId + ``; + } + }); }; return handler;