- BATTLESHIP simulates the classic battleship game.
- Players can place their ships by dragging/dropping or skip to arrange ships randomly on the game board.
- Players play against computer.
- Players can choose who takes the first turn.
- Human players mode - support playing on mobile device
- AI player
- The project is set up with webpack
- Unit testing - JEST
- Install webpack locally
npm init -y
npm install webpack webpack-cli --save-dev
- Setup directory structure
/dist/index.html
/src/index.js
- Create configuration file
webpack.config.js
. eg:
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};
- Create a bundle
- install dependency locally using
npm install
- import denpendency in the script using
import
statement - load the bundle from html file using
script
tag:<script src="bundle.js"></script>
- Run webpack by running
npx webpack --config webpack.config.js
or by edittingpackage.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
then run
npm run build
npm install --save-dev style-loader css-loader
- Edit config file by adding
style-loader
andcss-loader
to the module configuration - Now we can import css into the script
import './style.css'
- Add rules in config file - see webpack.config.js for example
- import image to script file
- Use source map by adding
devtool: 'inline-source-map',
to config file - Watch mode - add
"watch": "webpack --watch"
to script section ofpackage.json
- Install jest
npm install --save-dev jest
- Add to package.json
{
"scripts": {
"test": "jest"
}
}
- Run
npm test
Make sure dist
folder is not ignored by git
- update
package.json
{
"name": "project name",
"version": "1.0.0",
"repository": {
"url": "git+https://github.com/{USERNAME}/{REPONAME}.git"
},
...
}
- add scripts
{
...
"scripts": {
"build": "webpack --mode=development",
...
"predeploy": "npm run build",
"deploy": "gh-pages -d dist"
},
...
}
npm install --save-dev gh-pages
npm run deploy