Coder Social home page Coder Social logo

exercise-battleship-vanillajs's Introduction

Battleship In Vanilla.js

Write a battleship game using Vanilla.js

Demonstration of Battleship

🌱 How to start this project

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.

📝Instructions

  1. Create your HTML/CSS. First, we recomend using a parent div with display:flex and flex-wrap: wrap (to allow multiple rows), the container must have 100 divs inside.
  2. After your HTML/CSS looks good, start thinking on how to make it dynamic using JS.
  3. 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]
];
  1. Add one onClick to every <div> and call the fireTorpedo function with the coordinates of the div.
  2. Replace the value on the gameBoard and render the board again.

😎 Feeling confident?

  • Try implementing a "showShips" function that shows the ship positions when clicked.

exercise-battleship-vanillajs's People

Contributors

alesanchezr avatar elviraqdp avatar mortegac avatar tommygonzaleza avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.