Skip to content

This is just a fun project creating a game of battleship. Experimenting with functional programming.

License

Notifications You must be signed in to change notification settings

jheagle/battleship

Repository files navigation

battleship

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/

Modules

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

actions : Object

All methods exported from this module are encapsulated within gameActions.

actions~noConflict() ⇒ gameActions

Return a reference to this library while preserving the original same-named library

Kind: inner method of actions

actions~setShip(matrix, point, view)

Set a specified point to be part of a ship

Kind: inner method of actions

Param
matrix
point
view

actions~updatePlayer(player, playAgain, sunkShip)

Track player stats such as attacks and turns

Kind: inner method of actions

Param
player
playAgain
sunkShip

actions~attackFleet(target) ⇒ *

Perform attack on an enemy board / cell

Kind: inner method of actions

Param
target

actions~attackListener(e, target) ⇒ *

Kind: inner method of actions

Param
e
target

actions~computerAttack(player, players)

Main AI logic for computer to attack, selects a target then performs attack function.

Kind: inner method of actions

Param
player
players

actions~functionalHelpers : * | module:functionalHelpers

Verify availability of functional-helpers

Kind: inner typedef of actions

actions~jsonDom : * | module:json-dom

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

functions

A reference to all functions to be used globally / exported

functions~noConflict() ⇒ gameUtils

Return a reference to this library while preserving the original same-named library

Kind: inner method of functions

functions~checkIfShipCell(pnt, matrix) ⇒ boolean

Return the hasShip tile boolean at the specified point.

Kind: inner method of functions

Param
pnt
matrix

functions~checkIfHitCell(pnt, matrix) ⇒ boolean

Return the isHit tile boolean at the specified point.

Kind: inner method of functions

Param
pnt
matrix

functions~getAllNonHitCells(matrix) ⇒ Array

Get all points which were not yet hit in the matrix.

Kind: inner method of functions

Param
matrix

functions~getAdjEdgeNonHitCells(pnt, matrix) ⇒ Array

Get the points which have same edges with the provided point and are not hit.

Kind: inner method of functions

Param
pnt
matrix

functions~getALowStatusItem(items) ⇒ Array

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

functions~getLowStatusItems(items) ⇒ Array

Given an array of items, return all items which have the lowest status property

Kind: inner method of functions

Param
items

functions~getBrokenItems(items) ⇒ Array

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

functions~getBrokenShipsPlayers(players) ⇒ Array

Return all of the players which have broken ships.

Kind: inner method of functions

Param
players

functions~numDamagedParts(total, status) ⇒ number

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

functions~filterAdjacentPoints(pnt) ⇒ boolean

Used to generate 'checkerboard' style attack by only attacking every non-edge-touching cell

Kind: inner method of functions

Param
pnt

functions~jsonDom : * | module:json-dom

Verify availability of jsonDom

Kind: inner typedef of functions

layout : Object

A reference to all functions to be used globally / exported

layout~noConflict() ⇒ gameLayout

Return a reference to this library while preserving the original same-named library

Kind: inner method of layout

layout~mainMenu() ⇒ module:jDom/core/dom/objects.DomItem

This will be the main menu for the game.

Kind: inner method of layout

layout~boards([players]) ⇒ module:jDom/core/dom/objects.DomItem

Wrapper div for player data / boards

Kind: inner method of layout

Param Type Default
[players] Array []

layout~finalScore(players) ⇒ module:jDom/core/dom/objects.DomItem

Display the final scores after a game has ended and have a button to restart.

Kind: inner method of layout

Param Type
players Array

layout~jsonDom : * | module:json-dom

Verify availability of jsonDom

Kind: inner typedef of layout

main

A reference to all functions to be used globally / exported

main~noConflict() ⇒ gameMain

Return a reference to this library while preserving the original same-named library

Kind: inner method of main

main~jsonDom : * | module:json-dom

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

main~documentItem : module:json-dom.documentItem

Create new private reference to the document

Kind: inner typedef of main

pieces

A reference to all functions to be used globally / exported

pieces~noConflict() ⇒ gamePieces

Return a reference to this library while preserving the original same-named library

Kind: inner method of pieces

pieces~waterTile() ⇒ Object

Set the style for tiles representing water.

Kind: inner method of pieces

pieces~shipTile() ⇒ Object

Set status and custom properties for tiles that have a ship

Kind: inner method of pieces

pieces~ship(name) ⇒ Object

Store properties of a ship which includes an array of all associated ship tiles.

Kind: inner method of pieces

Param Type
name string

pieces~hitTile() ⇒ Object

Set the status of the tile to hit.

Kind: inner method of pieces

pieces~playerSet(board, name) ⇒ Object

Store the player attributes.

Kind: inner method of pieces

Param Type
board Object
name string

pieces~playerStats([player], [status=]) ⇒ Object

The defined attributes for each player

Kind: inner method of pieces

Param Type Default
[player] Object {}
[status=] Object

pieces~functionalHelpers : * | module:functionalHelpers

Verify availability of functional-helpers

Kind: inner typedef of pieces

pieces~jsonDom : * | module:json-dom

Verify availability of jsonDom

Kind: inner typedef of pieces

setup

A reference to all functions to be used globally / exported

setup~noConflict() ⇒ gameStart

Return a reference to this library while preserving the original same-named library

Kind: inner method of setup

setup~beginRound(e, mainForm) ⇒ boolean

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

setup~main(parent) ⇒ module:jDom/core/dom/objects.documentItem

The entry function

Kind: inner method of setup

Param
parent

setup~restart(e, button)

Kind: inner method of setup

Param
e
button

setup~functionalHelpers : * | module:functionalHelpers

Verify availability of functional-helpers

Kind: inner typedef of setup

setup~jsonDom : * | module:json-dom

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

About

This is just a fun project creating a game of battleship. Experimenting with functional programming.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages