Package battleship.model.player
Class AbstractPlayer
java.lang.Object
battleship.model.player.AbstractPlayer
- All Implemented Interfaces:
Player
public abstract class AbstractPlayer extends java.lang.Object implements Player
Abstract player class see
Player
to know more about this code organisation-
Field Summary
Fields Modifier and Type Field Description int
id
(package private) java.util.ArrayList<Triplet<java.lang.Integer,java.lang.Integer,java.lang.Boolean>>
moves
reference every shot on the opponent board, left and middle side of the Triplet reference the coordinates and the right side if this move hit or not an opponent ship(package private) java.util.ArrayList<Ship>
ships
-
Constructor Summary
Constructors Constructor Description AbstractPlayer()
-
Method Summary
Modifier and Type Method Description void
addMove(Triplet<java.lang.Integer,java.lang.Integer,java.lang.Boolean> move)
addmove
to themoves
listboolean
areValid(int x, int y)
check if coordinates fromView.chooseMove(Player)
are in valids positionint
getId()
java.util.ArrayList<Triplet<java.lang.Integer,java.lang.Integer,java.lang.Boolean>>
getMoves()
java.util.ArrayList<Ship>
getShips()
void
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 playerships
list and returntrue
if validfalse
otherwisejava.lang.String
toString()
java.util.ArrayList<Pair<java.lang.Integer,java.lang.Integer>>
validMoves()
give a list of the player possible moves, used inPlayer.chooseMove()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface battleship.model.player.Player
chooseMove, placeShips
-
Field Details
-
ships
-
moves
reference every shot on the opponent board, left and middle side of the Triplet reference the coordinates and the right side if this move hit or not an opponent ship -
id
public int id
-
-
Constructor Details
-
AbstractPlayer
public AbstractPlayer()
-
-
Method Details
-
setShips
Description copied from interface:Player
check if ship position and direction are valides and does not overlap on other vessels add the ship to playerships
list and returntrue
if validfalse
otherwise -
addMove
addmove
to themoves
list -
validMoves
Description copied from interface:Player
give a list of the player possible moves, used inPlayer.chooseMove()
- Specified by:
validMoves
in interfacePlayer
- Returns:
- a list of playable move
-
areValid
public boolean areValid(int x, int y)Description copied from interface:Player
check if coordinates fromView.chooseMove(Player)
are in valids position -
setId
public void setId(int i) -
getId
public int getId() -
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
getShips
-
getMoves
public java.util.ArrayList<Triplet<java.lang.Integer,java.lang.Integer,java.lang.Boolean>> getMoves()
-