Package battleship.model.player
Interface Player
- All Known Implementing Classes:
AbstractPlayer
,Computer
,Human
,Random
public interface Player
Player interface, used as an API.
This model (interface -> abstract class(es) -> concrete classes) prevent hard code.
This is the only object which interact with other object
Allows an outside person from the project to easily change the code or to add a view easily without modifying
existing classes
- See Also:
AbstractPlayer
,Computer
,Human
,Random
-
Field Summary
Fields Modifier and Type Field Description static int[]
shipSize
-
Method Summary
Modifier and Type Method Description void
addMove(Triplet<java.lang.Integer,java.lang.Integer,java.lang.Boolean> move)
Adds coordinates of themove
in theAbstractPlayer.moves
listboolean
areValid(int x, int y)
check if coordinates fromView.chooseMove(Player)
are in valids positionPair<java.lang.Integer,java.lang.Integer>
chooseMove()
Used by computer onlyint
getId()
java.util.ArrayList<Triplet<java.lang.Integer,java.lang.Integer,java.lang.Boolean>>
getMoves()
java.util.ArrayList<Ship>
getShips()
void
placeShips()
Used byComputer
instances to place shipsvoid
setId(int i)
boolean
setShips(Ship ship)
check if ship position and direction are valides and does not overlap on other vessels add the ship to playerAbstractPlayer.ships
list and returntrue
if validfalse
otherwisejava.util.ArrayList<Pair<java.lang.Integer,java.lang.Integer>>
validMoves()
give a list of the player possible moves, used inchooseMove()
-
Field Details
-
shipSize
static final int[] shipSize
-
-
Method Details
-
chooseMove
Pair<java.lang.Integer,java.lang.Integer> chooseMove()Used by computer only- Returns:
- coords in its opponent grid to play a move
- See Also:
Random.chooseMove()
-
setShips
check if ship position and direction are valides and does not overlap on other vessels add the ship to playerAbstractPlayer.ships
list and returntrue
if validfalse
otherwise- Parameters:
ship
- the ship instance we check- Returns:
true
if ship data are valids,false
otherwise
-
getId
int getId() -
addMove
Adds coordinates of themove
in theAbstractPlayer.moves
list- Parameters:
move
- the move chosen by the player
-
setId
void setId(int i) -
validMoves
java.util.ArrayList<Pair<java.lang.Integer,java.lang.Integer>> validMoves()give a list of the player possible moves, used inchooseMove()
- Returns:
- a list of playable move
-
placeShips
void placeShips()Used byComputer
instances to place ships -
areValid
boolean areValid(int x, int y)check if coordinates fromView.chooseMove(Player)
are in valids position- Parameters:
x
- the x-axis of the coordinatesy
- the y-axis of the coordinates- Returns:
true
if valid,false
otherwise
-
getShips
java.util.ArrayList<Ship> getShips() -
getMoves
java.util.ArrayList<Triplet<java.lang.Integer,java.lang.Integer,java.lang.Boolean>> getMoves()
-