merge development into dev/client

This commit is contained in:
Cedric Beck
2024-11-24 10:39:28 +01:00
46 changed files with 1380 additions and 122 deletions

View File

@@ -57,4 +57,13 @@ public Node[] getInfield() {
public void setPieceOnBoard(int index, Piece piece) {
infield[index].setOccupant(piece);
}
public int getInfieldIndexOfPiece(Piece piece) {
for (int i = 0; i < infield.length; i++) {
if (infield[i].getOccupant() == piece) {
return i;
}
}
return -1;
}
}

View File

@@ -22,8 +22,12 @@ public class Game {
private Map<Color, Integer> playerConnectionID;
private ArrayList<Observer> observers = new ArrayList<>();
private Player startPlayer;
private Boolean gameHasStarted = false;
private Boolean playerHasDisconnected = false;
private Boolean gameIsInterrupted = false;
private Boolean allRanked = false;
private Boolean movablePieces = false;
private static final int AMOUNT_OF_TURBO_CARDS = 16;
private static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12;
@@ -297,7 +301,6 @@ public Boolean getGameHasStarted() {
*/
public void setGameHasStarted(Boolean gameHasStarted) {
this.gameHasStarted = gameHasStarted;
if (gameHasStarted) notifyObservers();
}
/**
@@ -309,6 +312,44 @@ public Boolean playerHasDisconnected() {
return playerHasDisconnected;
}
/**
* This method sets the game interruption state.
*
* @param gameIsInterrupted the new game interruption state
*/
public void setGameIsInterrupted(Boolean gameIsInterrupted) {
this.gameIsInterrupted = gameIsInterrupted;
if (!gameIsInterrupted) notifyObservers();
}
/**
* This method returns whether the game is interrupted.
*
* @return true if the game is interrupted, false otherwise
*/
public Boolean gameIsInterrupted() {
return gameIsInterrupted;
}
/**
* This method returns whether the game is interrupted.
*
* @return true if the game is interrupted, false otherwise
*/
public Boolean getMovablePieces() {
return movablePieces;
}
/**
* This method sets the game interruption state.
*
* @param movablePieces the new game interruption state
*/
public void setMovablePieces(Boolean movablePieces) {
this.movablePieces = movablePieces;
if (!movablePieces) notifyObservers();
}
/**
* This method sets the player has disconnected.
*
@@ -316,9 +357,44 @@ public Boolean playerHasDisconnected() {
*/
public void setPlayerHasDisconnected(Boolean playerHasDisconnected) {
this.playerHasDisconnected = playerHasDisconnected;
if (playerHasDisconnected) {
notifyObservers();
}
if (playerHasDisconnected) notifyObservers();
}
/**
* This method returns whether all players have ranked.
*
* @return true if all players have ranked, false otherwise
*/
public Boolean allRanked() {
return allRanked;
}
/**
* This method sets whether all players have ranked.
*
* @param allRanked the new all ranked state
*/
public void setAllRanked(Boolean allRanked) {
this.allRanked = allRanked;
if (allRanked) notifyObservers();
}
/**
* This method returns the start player.
*
* @return the start player
*/
public Player getStartPlayer() {
return startPlayer;
}
/**
* This method sets the start player.
*
* @param startPlayer the new start player
*/
public void setStartPlayer(Player startPlayer) {
this.startPlayer = startPlayer;
}
/**
@@ -329,4 +405,17 @@ public void notifyObservers() {
observer.update();
}
}
/**
* This method returns the piece through its identifier.
*
* @param identifier the identifier of the piece
* @return the piece
*/
public Piece getPieceThroughIdentifier(String identifier) {
String[] parts = identifier.split("-");
Color color = Color.valueOf(parts[0]);
int index = Integer.parseInt(parts[1]);
return board.getPlayerData().get(color).getPieces()[index];
}
}

View File

@@ -6,7 +6,8 @@
public class Piece {
private ShieldState shield;
private PieceState state;
private Color color;
private final Color color;
private final int id;
/**
* This constructor is used to create a new Piece
@@ -14,10 +15,11 @@ public class Piece {
* @param color the color of the piece
* @param state the state of the piece
*/
public Piece(Color color, PieceState state) {
public Piece(Color color, PieceState state, int id) {
this.color = color;
this.state = state;
shield = ShieldState.NONE;
this.id = id;
}
/**
@@ -73,4 +75,22 @@ public boolean isShielded() {
public boolean isSuppressed() {
return shield == ShieldState.SUPPRESSED;
}
/**
* This method is used to get the color of the piece
*
* @return the color of the piece
*/
public Color getColor() {
return color;
}
/**
* This method is used to get the color of the piece
*
* @return the color of the piece
*/
public String getIdentifier() {
return color.toString() + "-" + id;
}
}

View File

@@ -19,7 +19,7 @@ public PlayerData(Color color) {
waitingArea = new Piece[4];
for (int i = 0; i < 4; i++) {
homeNodes[i] = new HomeNode();
pieces[i] = new Piece(color, PieceState.WAITING);
pieces[i] = new Piece(color, PieceState.WAITING, i);
waitingArea[i] = pieces[i];
}
}
@@ -108,4 +108,46 @@ public Piece removePieceFromWaitingArea() {
public void setPieceInHome(int index, Piece piece) {
homeNodes[index].setOccupant(piece);
}
/**
* This method returns the homeNodes
*
* @return the homeNodes
*/
public boolean homeIncludes(Piece piece) {
for (int i = 0; i < 4; i++) {
if (homeNodes[i].getOccupant() == piece) {
return true;
}
}
return false;
}
/**
* This method returns the homeNodes
*
* @return the homeNodes
*/
public int getIndexInHome(Piece piece) {
for (int i = 0; i < 4; i++) {
if (homeNodes[i].getOccupant() == piece) {
return i;
}
}
return -1;
}
/**
* This method returns the homeNodes
*
* @return the homeNodes
*/
public boolean hasPieceInWaitingArea() {
for (Piece piece : waitingArea) {
if (piece != null) {
return true;
}
}
return false;
}
}