This is just a fun project creating a game of battleship. Experimenting with functional programming and ES6 features.
A relatively recent version is running at https: //joshuaheagle.com/battleship/
- actions :
Object
All methods exported from this module are encapsulated within gameActions.
- functions
A reference to all functions to be used globally / exported
- layout :
Object
A reference to all functions to be used globally / exported
- main
A reference to all functions to be used globally / exported
- pieces
A reference to all functions to be used globally / exported
- setup
A reference to all functions to be used globally / exported
All methods exported from this module are encapsulated within gameActions.
- actions :
Object
- ~noConflict() ⇒
gameActions
- ~setShip(matrix, point, view)
- ~updatePlayer(player, playAgain, sunkShip)
- ~attackFleet(target) ⇒
*
- ~attackListener(e, target) ⇒
*
- ~computerAttack(player, players)
- ~functionalHelpers :
*
|module:functionalHelpers
- ~jsonDom :
*
|module:json-dom
- ~gameLayout :
*
|layout
- ~gamePieces :
*
|pieces
- ~gameUtils :
*
|functions
- ~noConflict() ⇒
Return a reference to this library while preserving the original same-named library
Kind: inner method of actions
Set a specified point to be part of a ship
Kind: inner method of actions
Param |
---|
matrix |
point |
view |
Track player stats such as attacks and turns
Kind: inner method of actions
Param |
---|
player |
playAgain |
sunkShip |
Perform attack on an enemy board / cell
Kind: inner method of actions
Param |
---|
target |
Kind: inner method of actions
Param |
---|
e |
target |
Main AI logic for computer to attack, selects a target then performs attack function.
Kind: inner method of actions
Param |
---|
player |
players |
Verify availability of functional-helpers
Kind: inner typedef of actions
Verify availability of json-dom
Kind: inner typedef of actions
actions~gameLayout : *
| layout
Verify availability of gameLayout
Kind: inner typedef of actions
actions~gamePieces : *
| pieces
Verify availability of gamePieces
Kind: inner typedef of actions
actions~gameUtils : *
| functions
Verify availability of gameUtils
Kind: inner typedef of actions
A reference to all functions to be used globally / exported
- functions
- ~noConflict() ⇒
gameUtils
- ~checkIfShipCell(pnt, matrix) ⇒
boolean
- ~checkIfHitCell(pnt, matrix) ⇒
boolean
- ~getAllNonHitCells(matrix) ⇒
Array
- ~getAdjEdgeNonHitCells(pnt, matrix) ⇒
Array
- ~getALowStatusItem(items) ⇒
Array
- ~getLowStatusItems(items) ⇒
Array
- ~getBrokenItems(items) ⇒
Array
- ~getBrokenShipsPlayers(players) ⇒
Array
- ~numDamagedParts(total, status) ⇒
number
- ~filterAdjacentPoints(pnt) ⇒
boolean
- ~jsonDom :
*
|module:json-dom
- ~noConflict() ⇒
Return a reference to this library while preserving the original same-named library
Kind: inner method of functions
Return the hasShip tile boolean at the specified point.
Kind: inner method of functions
Param |
---|
pnt |
matrix |
Return the isHit tile boolean at the specified point.
Kind: inner method of functions
Param |
---|
pnt |
matrix |
Get all points which were not yet hit in the matrix.
Kind: inner method of functions
Param |
---|
matrix |
Get the points which have same edges with the provided point and are not hit.
Kind: inner method of functions
Param |
---|
pnt |
matrix |
Given an array of items, return the item with the lowest status property (at the end of the array)
Kind: inner method of functions
Param |
---|
items |
Given an array of items, return all items which have the lowest status property
Kind: inner method of functions
Param |
---|
items |
Given an array of items, return all of the items which have a status less than 100, but more than 0
Kind: inner method of functions
Param |
---|
items |
Return all of the players which have broken ships.
Kind: inner method of functions
Param |
---|
players |
Return the number of damaged ship parts. Performs math on the number of parts vs the damaged status.
Kind: inner method of functions
Param |
---|
total |
status |
Used to generate 'checkerboard' style attack by only attacking every non-edge-touching cell
Kind: inner method of functions
Param |
---|
pnt |
Verify availability of jsonDom
Kind: inner typedef of functions
A reference to all functions to be used globally / exported
- layout :
Object
- ~noConflict() ⇒
gameLayout
- ~mainMenu() ⇒
module:jDom/core/dom/objects.DomItem
- ~boards([players]) ⇒
module:jDom/core/dom/objects.DomItem
- ~finalScore(players) ⇒
module:jDom/core/dom/objects.DomItem
- ~jsonDom :
*
|module:json-dom
- ~noConflict() ⇒
Return a reference to this library while preserving the original same-named library
Kind: inner method of layout
This will be the main menu for the game.
Kind: inner method of layout
Wrapper div for player data / boards
Kind: inner method of layout
Param | Type | Default |
---|---|---|
[players] | Array |
[] |
Display the final scores after a game has ended and have a button to restart.
Kind: inner method of layout
Param | Type |
---|---|
players | Array |
Verify availability of jsonDom
Kind: inner typedef of layout
A reference to all functions to be used globally / exported
- main
- ~noConflict() ⇒
gameMain
- ~jsonDom :
*
|module:json-dom
- ~gameActions :
*
|actions
- ~gameStart :
*
|setup
- ~documentItem :
module:json-dom.documentItem
- ~noConflict() ⇒
Return a reference to this library while preserving the original same-named library
Kind: inner method of main
Verify availability of jsonDom
Kind: inner typedef of main
main~gameActions : *
| actions
Verify availability of gameActions
Kind: inner typedef of main
main~gameStart : *
| setup
Verify availability of gameStart
Kind: inner typedef of main
Create new private reference to the document
Kind: inner typedef of main
A reference to all functions to be used globally / exported
- pieces
- ~noConflict() ⇒
gamePieces
- ~waterTile() ⇒
Object
- ~shipTile() ⇒
Object
- ~ship(name) ⇒
Object
- ~hitTile() ⇒
Object
- ~playerSet(board, name) ⇒
Object
- ~playerStats([player], [status=]) ⇒
Object
- ~functionalHelpers :
*
|module:functionalHelpers
- ~jsonDom :
*
|module:json-dom
- ~noConflict() ⇒
Return a reference to this library while preserving the original same-named library
Kind: inner method of pieces
Set the style for tiles representing water.
Kind: inner method of pieces
Set status and custom properties for tiles that have a ship
Kind: inner method of pieces
Store properties of a ship which includes an array of all associated ship tiles.
Kind: inner method of pieces
Param | Type |
---|---|
name | string |
Set the status of the tile to hit.
Kind: inner method of pieces
Store the player attributes.
Kind: inner method of pieces
Param | Type |
---|---|
board | Object |
name | string |
The defined attributes for each player
Kind: inner method of pieces
Param | Type | Default |
---|---|---|
[player] | Object |
{} |
[status=] | Object |
Verify availability of functional-helpers
Kind: inner typedef of pieces
Verify availability of jsonDom
Kind: inner typedef of pieces
A reference to all functions to be used globally / exported
- setup
- ~noConflict() ⇒
gameStart
- ~beginRound(e, mainForm) ⇒
boolean
- ~main(parent) ⇒
module:jDom/core/dom/objects.documentItem
- ~restart(e, button)
- ~functionalHelpers :
*
|module:functionalHelpers
- ~jsonDom :
*
|module:json-dom
- ~gameLayout :
*
|layout
- ~gamePieces :
*
|pieces
- ~gameUtils :
*
|functions
- ~gameActions :
*
|actions
- ~noConflict() ⇒
Return a reference to this library while preserving the original same-named library
Kind: inner method of setup
Logic for setting up and starting a new round (selects random start player and calls computer attack if it is AI starting)
Kind: inner method of setup
Param |
---|
e |
mainForm |
The entry function
Kind: inner method of setup
Param |
---|
parent |
Kind: inner method of setup
Param |
---|
e |
button |
Verify availability of functional-helpers
Kind: inner typedef of setup
Verify availability of jsonDom
Kind: inner typedef of setup
setup~gameLayout : *
| layout
Verify availability of gameLayout
Kind: inner typedef of setup
setup~gamePieces : *
| pieces
Verify availability of gamePieces
Kind: inner typedef of setup
setup~gameUtils : *
| functions
Verify availability of gameUtils
Kind: inner typedef of setup
setup~gameActions : *
| actions
Verify availability of gameActions
Kind: inner typedef of setup