Package Helper
Class Position
- java.lang.Object
- 
- Helper.Position
 
- 
 public class Position extends java.lang.ObjectThe 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
 
- 
- 
Constructor SummaryConstructors Constructor Description Position(int x, int y)Constructs a new Position object with the specified X and Y coordinates.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(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.intgetX()Gets the X coordinate of the position.intgetY()Gets the Y coordinate of the position.inthashCode()booleanisIn(java.util.List<Position> positions)Checks if the current position is present in the given list of positions.booleanisValid()Checks if the current position is valid on the game board.java.lang.StringtoString()Returns a string representation of the Position object.
 
- 
- 
- 
Method Detail- 
isValidpublic boolean isValid() Checks if the current position is valid on the game board.- Returns:
- True if the position is valid, false otherwise.
 
 - 
getPossibleMovepublic 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.
 
 - 
getXpublic int getX() Gets the X coordinate of the position.- Returns:
- The X coordinate.
 
 - 
getYpublic int getY() Gets the Y coordinate of the position.- Returns:
- The Y coordinate.
 
 - 
isInpublic 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.
 
 - 
toStringpublic java.lang.String toString() Returns a string representation of the Position object.- Overrides:
- toStringin class- java.lang.Object
- Returns:
- A string representation of the form "Position{X=x, Y=y}".
 
 - 
equalspublic boolean equals(java.lang.Object o) - Overrides:
- equalsin class- java.lang.Object
 
 - 
hashCodepublic int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 
- 
 
-