Design of the Battleship Program
Problem statement
Our aim is to write a program in Java that will play the popular game of Battleship either against the computer, or against another player on a different computer, running a different program.
Problem description
The game is played on two fields, each 10 X 10 squares. The columns are labeled A-J, and the rows are labeled 1-10. Each player's fleet of ships consists of one aircraft carrier, one battleship, one destroyer, one submarine and one cruiser. The size and shape of each ship is as follows:
Before the game starts, each player secretly places their ships anywhere on their own playing field. Ships cannot overlap one another, but may be placed either vertically or horizontally.
The first turn is determined by some random means (throwing a die). Players take turns to try to guess the location of the other's ships by naming a square (e.g. F7). The opponent declares the square to be a hit or a miss, depending on whether there is a ship occupying that square. When all the squares occupied by a particular ship have been guessed, the player must announce that that particular ship is sunk. A player keeps track of the hits and misses on a copy of the opponent's field.
The first player to sink all the other's ships is the winner.
Object analysis
Objects metioned are:
Game, Field, Square, Column, Row, Player, Fleet, Ship, Aircraft carrier, Destroyer, Cruiser, Submarine, Battleship, Size, Shape, Turn, Location, Opponent, Hit, Miss, Winner, Copy
Relationships are:
Game HASA setof Player
Player HASA Field
Player HASA Fleet
Game HASA Turn
Game HASA Winner
Field HASA setof Square
PlayersField ISA Field
OpponentsField ISA Field
Fleet HASA setof Ship
Carrier ISA Ship
Battleship ISA Ship
Cruiser ISA Ship
Destroyer ISA Ship
Submarine ISA Ship
Ship HASA Location
Location HAS Row
Location HAS Column
Square HASA Location
Square HASA Ship
Square HASA Trial
Hit ISA Trial
Miss ISA Trial
Reworking this gives:
Game
Player
Field
Fleet
Ship
Location
Square
Operation analysis
Operations mentioned are:
(the game is) Played
(each player) Places
(ships may not) Overlap
(first turn is ) Determined
(players) Take turns
(players) Guess
(player) Declares
(ship is) Occupying
(all squres for a ship are) Guessed
(players) Announce
(player) Keeps track of
(first player) Sink
Reworked this is:
Game
Player
Field
Ship