From 1784de93d130264b0abb869d538144fa173feb0a Mon Sep 17 00:00:00 2001 From: Alex <atm2g19@soton.ac.uk> Date: Sat, 4 Apr 2020 21:31:43 +0100 Subject: [PATCH] major bugfix : battleships ship sunk when one tile remaining --- src/games/battleships.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/games/battleships.ts b/src/games/battleships.ts index a30e9aa..8b29d3c 100644 --- a/src/games/battleships.ts +++ b/src/games/battleships.ts @@ -266,6 +266,7 @@ const battleships : GameConstructor = class battleships implements Game{ break; } let hits = ship.size-1; + let hit : boolean = false; for(let i = 0; i < ship.size; i++){ let X = ship.x + i*inx; let Y = ship.y + i*iny; @@ -273,14 +274,14 @@ const battleships : GameConstructor = class battleships implements Game{ //check if ship sunk shot.hit = true; console.log(shots); - + hit = true; } for(let shot of shots){ if(shot.x == X && shot.y == Y && shot.hit) hits--; } } - if(hits == 0){ + if(hits == 0 && hit){ player.socket.emit("sunk", ship); console.log("SUNK"); } -- GitLab