Class Ship
java.lang.Object
Ship
public class Ship
extends java.lang.Object
A Ship is a piece within the Battleship game. It has a name and size and can
be hidden in a unique position on the board.
-
Constructor Summary
Constructors Constructor Description Ship(java.lang.String name, int size)Constructs a Ship with the given name and size. -
Method Summary
Modifier and Type Method Description booleancheckLocation(int row, int col)Checks if this Ship is located at the current location.java.lang.StringgetName()Returns the name of this Ship.intgetSize()Returns the size of this Ship.voidhide(java.util.ArrayList<Ship> allShips)Hides this Ship on the board in a random position that doesn't overlap with any of the existing the ships.java.lang.StringtoString()Returns the String representation of this Ship.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Ship
public Ship(java.lang.String name, int size)Constructs a Ship with the given name and size.- Parameters:
name- the Ship's namesize- the number of spaces the Ship covers on the board
-
-
Method Details
-
checkLocation
public boolean checkLocation(int row, int col)Checks if this Ship is located at the current location.- Parameters:
row- the row to check, value values are in the range 0-9col- the column to check, value values are in the range 0-9- Returns:
- true if the Ship is located at given row and column, false otherwise
-
getName
public java.lang.String getName()Returns the name of this Ship.- Returns:
- the Ship's name
-
getSize
public int getSize()Returns the size of this Ship.- Returns:
- the Ship's size
-
hide
Hides this Ship on the board in a random position that doesn't overlap with any of the existing the ships.- Parameters:
allShips- a list of the other ships that may have already been hidden on the board
-
toString
public java.lang.String toString()Returns the String representation of this Ship.- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-