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
This commit is contained in:
MaciejkaG 2024-03-09 22:12:36 +01:00
parent 284c74b746
commit 44f13469cf
2 changed files with 3 additions and 4 deletions

View File

@ -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);
}
});
}

View File

@ -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;
}
});