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 the move in the AbstractPlayer.moves list
    boolean areValid​(int x, int y)
    check if coordinates from View.chooseMove(Player)are in valids position
    Pair<java.lang.Integer,​java.lang.Integer> chooseMove()
    Used by computer only
    int getId()  
    java.util.ArrayList<Triplet<java.lang.Integer,​java.lang.Integer,​java.lang.Boolean>> getMoves()  
    java.util.ArrayList<Ship> getShips()  
    void placeShips()
    Used by Computer instances to place ships
    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 AbstractPlayer.ships list and return true if valid false otherwise
    java.util.ArrayList<Pair<java.lang.Integer,​java.lang.Integer>> validMoves()
    give a list of the player possible moves, used in chooseMove()
  • 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

      boolean setShips​(Ship ship)
      check if ship position and direction are valides and does not overlap on other vessels add the ship to player AbstractPlayer.ships list and return true if valid false otherwise
      Parameters:
      ship - the ship instance we check
      Returns:
      true if ship data are valids, false otherwise
    • getId

      int getId()
    • addMove

      void addMove​(Triplet<java.lang.Integer,​java.lang.Integer,​java.lang.Boolean> move)
      Adds coordinates of the move in the AbstractPlayer.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 in chooseMove()
      Returns:
      a list of playable move
    • placeShips

      void placeShips()
      Used by Computer instances to place ships
    • areValid

      boolean areValid​(int x, int y)
      check if coordinates from View.chooseMove(Player)are in valids position
      Parameters:
      x - the x-axis of the coordinates
      y - 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()