docs + gomokucell javadoc
This commit is contained in:
@@ -1,40 +1,89 @@
|
||||
import java.util.EnumMap;
|
||||
|
||||
/**
|
||||
* This class is cell of the board of the Gomoku game.
|
||||
*/
|
||||
public class GomokuCell{
|
||||
/** Enumerate neighbor with key in Cardinal direction and key representing the cell in that direction. */
|
||||
private EnumMap<Cardinal,GomokuCell> neighbour;
|
||||
/** The state of the cell represented by the enumerate Color, Nil is empty, white and black for the color of a token */
|
||||
private Color state;
|
||||
|
||||
//------------------Constructors--------------------------
|
||||
|
||||
/**
|
||||
* The constructor of the cell.
|
||||
* @param state The state by default of the cell.
|
||||
*/
|
||||
public GomokuCell(Color state){
|
||||
this.neighbour = new EnumMap<>(Cardinal.class);
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void linkCell(Cardinal car, GomokuCell cell){
|
||||
this.neighbour.put(car, cell);
|
||||
}
|
||||
//------------------Gets--------------------------
|
||||
|
||||
/**
|
||||
* Return one neighbour.
|
||||
* @param car The Cardinal direction.
|
||||
* @return The GomokuCell at the direction.
|
||||
*/
|
||||
public GomokuCell getNeighbour(Cardinal car){
|
||||
return this.neighbour.get(car);
|
||||
}
|
||||
|
||||
public boolean isEmpty(){
|
||||
return this.state == Color.NIL;
|
||||
|
||||
/**
|
||||
* Return neighbour.
|
||||
* @return The EnumMap of neighbour.
|
||||
*/
|
||||
public EnumMap<Cardinal, GomokuCell> getAllNeighbour(){
|
||||
return neighbour;
|
||||
}
|
||||
|
||||
public boolean isPlayed(){
|
||||
return !this.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the state.
|
||||
* @return The state of the current cell with one Color.
|
||||
*/
|
||||
public Color getSate(){
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public EnumMap<Cardinal, GomokuCell> getAllNeighbour(){
|
||||
return neighbour;
|
||||
}
|
||||
|
||||
//------------------Booleans--------------------------
|
||||
|
||||
/**
|
||||
* This method returns if the current cell is empty
|
||||
* @return True if is empty, False if is not.
|
||||
*/
|
||||
public boolean isEmpty(){
|
||||
return this.state == Color.NIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns if the cell has already played.
|
||||
* @return True if the cell is already played, False if is not.
|
||||
*/
|
||||
public boolean isPlayed(){
|
||||
return !this.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the cell is playable.
|
||||
* @return True if the current cell can be played with the condition of the gomoku.
|
||||
*/
|
||||
public boolean isPlayable(){
|
||||
return this.neighbour.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
//------------------Methods--------------------------
|
||||
|
||||
/**
|
||||
* This method link the cell at the Cardinal position on the current cell.
|
||||
* @param car The Cardinal direction of the cell to link.
|
||||
* @param cell The GomokuCell to link.
|
||||
*/
|
||||
public void linkCell(Cardinal car, GomokuCell cell){
|
||||
this.neighbour.put(car, cell);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user