From 44f13469cfa9782099358f4b368472242e6d7a33 Mon Sep 17 00:00:00 2001 From: MaciejkaG Date: Sat, 9 Mar 2024 22:12:36 +0100 Subject: [PATCH] Minor changes - Fixed critical error (undefined value causing a crash when player leaves) - Fixed hit registration ghosting problem causing fake ships to appear to the opponent --- index.js | 2 +- utils/battleships.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 77fc8e8..1d4080a 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,6 @@ const io = new Server(server); const redis = createClient(); redis.on('error', err => console.log('Redis Client Error', err)); await redis.connect(); -// redis.flushDb(); const GInfo = new bships.GameInfo(redis, io); @@ -325,6 +324,7 @@ io.on('connection', async (socket) => { const playerGame = await GInfo.getPlayerGameData(socket); if (playerGame !== null) { AFKEnd(playerGame.id); + await GInfo.resetTimer(playerGame.id); } }); } diff --git a/utils/battleships.js b/utils/battleships.js index 5f4fbb9..136ca2a 100644 --- a/utils/battleships.js +++ b/utils/battleships.js @@ -217,8 +217,7 @@ export function checkHit(ships, posX, posY) { break; } - let l = !ship.type ? ship.type + 1 : ship.type + 2; - for (let i = 0; i < l; i++) { + for (let i = 0; i <= ship.type; i++) { let x = clamp(ship.posX + multips[0] * i, 0, 9); let y = clamp(ship.posY + multips[1] * i, 0, 9); @@ -265,7 +264,7 @@ export function validateShipPosition(ships, type, posX, posY, rot) { break; } - for (let i = 0; i < ship.type + 1; i++) { + for (let i = 0; i <= ship.type; i++) { boardRender[ship.posX + multips[0] * i][ship.posY + multips[1] * i] = true; } });