Write a battleship game using Vanilla.js
Do not clone this repository.
The first step to start coding is cloning the vanillajs boilerplate on your local computer or opening it using gitpod.
a) If using Gitpod (recommended) you can clone the boilerplate by clicking here.
b) If working locally type the following command from your command line:
$ git clone https://github.com/4GeeksAcademy/vanillajs-hello`.
💡 Important: Remember to create a new repository, update the remote (git remote set-url origin <your new url>
), and upload the code to your new repository using add
, commit
and push
.
- Create your HTML/CSS. First, we recomend using a parent div with
display:flex
andflex-wrap: wrap
(to allow multiple rows), the container must have 100 divs inside. - After your HTML/CSS looks good, start thinking on how to make it dynamic using JS.
- To represent the gameBoard you can use a JS matrix like this:
// 0 = empty
// 1 = part of a ship
// 2 = a sunken part of a ship
// 3 = a missed shot
let gameBoard = [
[1,1,1,1,1,0,0,0,0,1],
[0,0,0,0,0,0,0,0,0,1],
[0,0,0,0,0,0,0,0,0,1],
[0,0,0,0,0,0,0,0,0,1],
[0,0,0,0,0,0,0,0,0,0],
[1,0,0,1,1,0,0,0,0,0],
[1,0,0,0,0,0,0,0,0,0],
[1,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[1,1,1,1,0,0,0,0,0,0]
];
- Add one onClick to every
<div>
and call thefireTorpedo
function with the coordinates of the div. - Replace the value on the gameBoard and render the board again.
- Try implementing a "showShips" function that shows the ship positions when clicked.