Class AbstractPlayer

java.lang.Object
battleship.model.player.AbstractPlayer
All Implemented Interfaces:
Player
Direct Known Subclasses:
Computer, Human

public abstract class AbstractPlayer
extends java.lang.Object
implements Player
Abstract player class see Player to know more about this code organisation
See Also:
Player, Human, Computer, Random
  • 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  

    Fields inherited from interface battleship.model.player.Player

    shipSize
  • 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)
    add move to the moves list
    boolean areValid​(int x, int y)
    check if coordinates from View.chooseMove(Player)are in valids position
    int 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 player ships list and return true if valid false otherwise
    java.lang.String toString()  
    java.util.ArrayList<Pair<java.lang.Integer,​java.lang.Integer>> validMoves()
    give a list of the player possible moves, used in Player.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

      final java.util.ArrayList<Ship> ships
    • moves

      final 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
    • id

      public int id
  • Constructor Details

    • AbstractPlayer

      public AbstractPlayer()
  • Method Details

    • setShips

      public boolean setShips​(Ship ship)
      Description copied from interface: Player
      check if ship position and direction are valides and does not overlap on other vessels add the ship to player ships list and return true if valid false otherwise
      Specified by:
      setShips in interface Player
      Parameters:
      ship - the ship instance we check
      Returns:
      true if ship data are valids, false otherwise
    • addMove

      public void addMove​(Triplet<java.lang.Integer,​java.lang.Integer,​java.lang.Boolean> move)
      add move to the moves list
      Specified by:
      addMove in interface Player
      Parameters:
      move - the move chosen by the player
    • validMoves

      public java.util.ArrayList<Pair<java.lang.Integer,​java.lang.Integer>> validMoves()
      Description copied from interface: Player
      give a list of the player possible moves, used in Player.chooseMove()
      Specified by:
      validMoves in interface Player
      Returns:
      a list of playable move
    • areValid

      public boolean areValid​(int x, int y)
      Description copied from interface: Player
      check if coordinates from View.chooseMove(Player)are in valids position
      Specified by:
      areValid in interface Player
      Parameters:
      x - the x-axis of the coordinates
      y - the y-axis of the coordinates
      Returns:
      true if valid, false otherwise
    • setId

      public void setId​(int i)
      Specified by:
      setId in interface Player
    • getId

      public int getId()
      Specified by:
      getId in interface Player
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getShips

      public java.util.ArrayList<Ship> getShips()
      Specified by:
      getShips in interface Player
    • getMoves

      public java.util.ArrayList<Triplet<java.lang.Integer,​java.lang.Integer,​java.lang.Boolean>> getMoves()
      Specified by:
      getMoves in interface Player