diff --git a/src/games/battleships.ts b/src/games/battleships.ts index a30e9aad8c0775be250fae872ed32eba742b6c91..8b29d3c55b2ccc9177e1474dbf07d49748082daf 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"); }