A JavaScript game based on a classic "Battleship" game, implemented to practice Test Driven Development.
This project is created to practice Test Driven Development(TDD) in JavaScript by creating a Battleship game using Jest(JS Testing Framework). Babel and Webpack are also used in this project :cityscape: Feel free to reach me at Twitter 🥏
- Jest
- Babel Loader
- Webpack
- Test Driven Development(TDD)
- Source Maps
- Html Webpack Plugin
- Css/Asset Resource Loader
-
Compile on your machine
Run Dev Server (Port 5500)
npm installnpx webpack --watch //Clientsidenpm test // run tests -
Pre-Compiled(Easy to use)
Just open
index.htmlin dist folder
-
- Install NPM using
npm init -yto skip questions. - Install Webpack using
npm install webpack webpack-cli --save-dev. - Add a
webpack.config.jsfile and setup project directory. - Run
npx webpack --watchcommand to make sure webpack setup is successful. - Install Babel using
npm install --save-dev babel-jest @babel/core @babel preset-envcommand. Configure Babel by creating ababel.config.jsfile. - Install Jest using
npm install --save-dev jestcommand. - Create a sample test using Jest documentation. Configure Jest by adding
"test": "jest"line topackage.jsonfile. - Run
npm testcommand to make sure the mock test passes and everything is configured correctly so far(PASSED). - Use source maps.
- Load Assets.
- CSS
- Images
- Setup HtmlWebpackPlugin
- Clean up the
/distfolder - Setup template.html
- Setup favicon
- Clean up the
- Update
webpack.config.jsfile to finish environment setup. - Make sure it compiles the bundle successfully.
- Install NPM using
-
- Create DOM elements and cache them in
DOMInterfacemodule - Create
ships.jsmodule which containsshipModulefactory function-
ships()method - is an array of objects which include ship's name, length and it's direction
-
- Create
gameboard.jsmodule which containsgameboardfactory function-
gameGrid()method - is an array of 100 elements
-
- Create DOM elements and cache them in
-
- Test
ships.jsmodule- Test
shipsTestMethod()method inships.test.jswhich should return array of objects
- Test
- Test
gameboard.jsmodule- Test
gridTest()method, it should return array of 100 elements
- Test
- Test
-
- Make sure all tests pass.
-
- Update template.html for any changes
- Style HTML page(create style.css)
- Add Images and Fonts
-
- Allow users to place their ships.
- Implement drag/drop of ships.
- Make game responsive.
-
The Odin Project
-
YouTube
-
Jest
-
Design Inspiration
-
Webpack
-
Others
-
Polish the intelligence of computer and allow it to place adjacent slots after getting a
hit. -
Create a 2 player option ->
- Let users take turn by passing the device back and forth.
- implement a
pass devicescreen so players don't see each other's boards!
-
Reduce tight coupling of code in
gameLogic.jsand divide code into smaller modules. -
Improve testing by reducing mocking.
-
Add a button to Auto-Place ships.
“It always seems impossible until it's done.”
— Nelson Mandela
🚢 🎯 🎆

