The Battleship Service provides helpful utilities for building a distributed game of battleship.
Like regular Battleship, the Battleship service has two states: placing ships and shooting at ships. During placement, it expects each role to place each ship on his/her board and will not allow the game to proceed to the shooting phase until each role has placed all his/her ships. Placement, firing and starting blocks will return true if successful or an error message if it fails.
place <ship> at <row> <column> facing <direction>- Places a ship on your board with the front at the given row and column facing the given direction. Returns
trueif placed successfully (eg, on the board and not overlapping another ship). Also, placing a ship twice results in a move (not duplicates).
start game- Try to start the game. If both users have all their ships placed, it should return true and send
startmessages to all roles. Otherwise, it will return with a message saying that it is waiting on a specific role.
fire at <row> <column>- This block allows the user to try to fire at the given row and column. It returns
trueif it was a valid move; otherwise it will return an error message like
it's not your turn!. On a successful move, the server will send either a
missmessage to everyone in the room. Then it will send a
your turnmessage to the player to play next.
active ships for <role>- This block returns a list of all ships that are still afloat for the given role. If no role is specified, it defaults to the sender’s role.
all ships- Returns a list of all ship names. Useful in programmatically placing ships.
ship length <ship>- Returns the length of the given ship.
restart game- Restarts the given game (all boards, etc)
start- Received when
start gamefinishes successfully for any role. After game has officially started, users can no longer move ships.
your turn- Received when the given role’s turn starts.
roleis the owner of the ship that has been hit.
shipis the name of the ship that has been hit, and
columnprovide the location on the board where it was hit.
sunkprovides a true/false value for if the ship was sunk.
roleis the owner of the board receiving the shot and
columncorrespond to the board location or the shot.
Get list of ship types
fire(row: BoundedNumber<1, 100>, column: BoundedNumber<1, 100>)¶
Fire a shot at the board
row: BoundedNumber<1, 100>(BoundedNumber) - Row to fire at
column: BoundedNumber<1, 100>(BoundedNumber) - Column to fire at
Boolean(Boolean) - If ship was hit
placeShip(ship: String, row: BoundedNumber<1, 100>, column: BoundedNumber<1, 100>, facing: String)¶
Place a ship on the board
ship: String(String) - Ship type to place
row: BoundedNumber<1, 100>(BoundedNumber) - Row to place ship in
column: BoundedNumber<1, 100>(BoundedNumber) - Column to place ship in
facing: String(String) - Direction to face
Boolean(Boolean) - If piece was placed
Get number of remaining ships of a role
roleID: String(String) - Name of role to use
Integer(Integer) - Number of remaining ships
Resets the game by clearing the board and reverting to the placing phase
Boolean(Boolean) - If game was reset
Get length of a ship type
ship: String(String) - Type of ship
Integer(Integer) - Length of ship type