- this project implements the classic game 'Battleship', that has 2 players, ruled grid on which each player's fleet of warships are marked. The locations of the fleets are concealed from the other player. Players alternate turns calling "shots" at the other player's ships, and the objective of the game is to destroy the opposing player's fleet.
- initially, I wanted to use images for
ship
andshot
but those can be placed on the gameboard table only withappendChild
inside the square cell, which made it a bit complicated, since my focus was on building the battleship logic and ai, so I have finally switched to only usebackground-color
property; the most difficult part
of this project was definitely rendering the2D Array
into the a table directly. Maybe my goal was set too high but I actually made it and it works smooth. (This stackOverflow helped me lots StackOverflow by Vishnu Shenoy). Additional to it I have used an object for the parameters since I have more than two parameters to keep it organized. Thanks to Carlos for the tip!
- node output in the terminal of the
2D Array
, with 2 placed ships( 1 horizontally and 1 vertically), "x" marking thefired shot
at that ship's square
(ship is showing 10x10 array but was too long to add everything in single picture)