This is a Battleship Game built using HTML, CSS, and JavaScript. It simulates the classic battleship experience where players take turns guessing the location of their opponent’s ships.
0
stars
3
forks
source link
Updates for BattleShip Overlap Detection and Game End Handling #4
This PR addresses two key issues in the Battleship game :
Ship Overlap Detection: Prevents ships from being placed on top of one another.
2 Game End Logic: Disables any further actions once a player wins, ensuring no more squares can be clicked or ships fired upon.
Changes Made
Ship Overlap Detection
Added a check in the generate(ship) function to ensure ships do not overlap with each other when placed randomly on the computer's board.
The logic uses the isTaken check to verify if a square is already occupied by another ship, preventing ships from overlapping.
Game End Handling
Added logic in the gameOver() function to stop the game after someone wins, by removing click events on computerSquares and disabling further interaction.
Modified the click event listener for computerSquares to respect the isGameOver flag, preventing further shots after the game ends.
Testing
Tested the ship placement functionality multiple times to ensure that ships never overlap on the board.
Simulated a full game and verified that once a player wins, no further moves can be made, and all game interactions are disabled.
This PR addresses two key issues in the Battleship game :
Ship Overlap Detection: Prevents ships from being placed on top of one another.
2 Game End Logic: Disables any further actions once a player wins, ensuring no more squares can be clicked or ships fired upon.
Changes Made
Ship Overlap Detection Added a check in the generate(ship) function to ensure ships do not overlap with each other when placed randomly on the computer's board. The logic uses the isTaken check to verify if a square is already occupied by another ship, preventing ships from overlapping.
Game End Handling Added logic in the gameOver() function to stop the game after someone wins, by removing click events on computerSquares and disabling further interaction. Modified the click event listener for computerSquares to respect the isGameOver flag, preventing further shots after the game ends.
Testing Tested the ship placement functionality multiple times to ensure that ships never overlap on the board. Simulated a full game and verified that once a player wins, no further moves can be made, and all game interactions are disabled.