Package Helper

Class Position


  • public class Position
    extends java.lang.Object
    The Position class represents a position on a game board with X and Y coordinates. It provides methods to check the validity of the position, get possible moves for a player, and access the X and Y coordinates.
    Since:
    2023-12-01
    Version:
    1.0
    Author:
    Laamiri Ouail & Hajar Sadik
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int X  
      private int Y  
    • Constructor Summary

      Constructors 
      Constructor Description
      Position​(int x, int y)
      Constructs a new Position object with the specified X and Y coordinates.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      java.util.List<Position> getPossibleMove​(byte player, Button[][] btns, java.lang.String defaultColor)
      Gets a list of valid positions representing possible moves for the specified player at the current position on a game board.
      int getX()
      Gets the X coordinate of the position.
      int getY()
      Gets the Y coordinate of the position.
      int hashCode()  
      boolean isIn​(java.util.List<Position> positions)
      Checks if the current position is present in the given list of positions.
      boolean isValid()
      Checks if the current position is valid on the game board.
      java.lang.String toString()
      Returns a string representation of the Position object.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • X

        private int X
      • Y

        private int Y
    • Constructor Detail

      • Position

        public Position​(int x,
                        int y)
        Constructs a new Position object with the specified X and Y coordinates.
        Parameters:
        x - The X coordinate.
        y - The Y coordinate.
    • Method Detail

      • isValid

        public boolean isValid()
        Checks if the current position is valid on the game board.
        Returns:
        True if the position is valid, false otherwise.
      • getPossibleMove

        public java.util.List<Position> getPossibleMove​(byte player,
                                                        Button[][] btns,
                                                        java.lang.String defaultColor)
        Gets a list of valid positions representing possible moves for the specified player at the current position on a game board.
        Parameters:
        player - The player identifier (1 or 2).
        btns - A 2D array of Button objects representing the game board.
        defaultColor - The default background color to check against when determining valid moves.
        Returns:
        A list of Position objects representing possible moves.
      • getX

        public int getX()
        Gets the X coordinate of the position.
        Returns:
        The X coordinate.
      • getY

        public int getY()
        Gets the Y coordinate of the position.
        Returns:
        The Y coordinate.
      • isIn

        public boolean isIn​(java.util.List<Position> positions)
        Checks if the current position is present in the given list of positions.
        Parameters:
        positions - A list of Position objects to check against.
        Returns:
        True if the position is in the list, false otherwise.
      • toString

        public java.lang.String toString()
        Returns a string representation of the Position object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of the form "Position{X=x, Y=y}".
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object