merge Development into test #27

Merged
j23f0712 merged 14 commits from development into dev/test 2024-12-01 21:56:50 +01:00
15 changed files with 327 additions and 114 deletions
Showing only changes of commit 1d8eff8ea9 - Show all commits

View File

@@ -58,6 +58,12 @@ public void setPieceOnBoard(int index, Piece piece) {
infield[index].setOccupant(piece); infield[index].setOccupant(piece);
} }
/**
* This method returns the index of a specific piece on the board
*
* @param piece the piece to be searched for
* @return the index of the piece
*/
public int getInfieldIndexOfPiece(Piece piece) { public int getInfieldIndexOfPiece(Piece piece) {
for (int i = 0; i < infield.length; i++) { for (int i = 0; i < infield.length; i++) {
if (infield[i].getOccupant() == piece) { if (infield[i].getOccupant() == piece) {

View File

@@ -1,8 +1,23 @@
package pp.mdga.game; package pp.mdga.game;
/**
* Enum representing the different types of bonus cards.
*/
public enum BonusCard { public enum BonusCard {
/**
* The hidden bonus card.
*/
HIDDEN, HIDDEN,
/**
* The shield bonus card.
*/
SHIELD, SHIELD,
/**
* The turbo bonus card.
*/
TURBO, TURBO,
/**
* The swap bonus card.
*/
SWAP SWAP
} }

View File

@@ -1,20 +1,7 @@
package pp.mdga.game; package pp.mdga.game;
/**
* This class represents a BonusNode
*/
public class BonusNode extends Node { public class BonusNode extends Node {
public BonusNode() {}
/**
* This method is used to set a new Occupant
*
* @param occupant the new occupant of the node
*/
@Override
public void setOccupant(Piece occupant) {
if (occupant.isSuppressed()){
occupant.setShield(ShieldState.NONE);
}
//Draw Card Event
this.occupant = occupant;
}
} }

View File

@@ -26,16 +26,33 @@ public enum Color {
*/ */
NONE; NONE;
/**
* This method will be used to return a Color enumeration depending on the given index parameter.
*
* @param index as the index of the color inside the values as an Integer.
* @return a Color enumeration.
*/
public static Color getColorByIndex(int index) {
if (index < 0 || index >= values().length) {
throw new IllegalArgumentException("");
}
return values()[index];
}
/** /**
* This method will be used to calculate the next color inside the sequence. * This method will be used to calculate the next color inside the sequence.
* *
* @return color as a Color Enumeration. * @return color as a Color Enumeration.
*/ */
public Color next() { public Color next() {
if (this.next() == NONE) { Color[] colors = values();
return AIRFORCE; int nextIndex = (this.ordinal() + 1) % colors.length;
if (colors[nextIndex] == NONE) {
nextIndex = (nextIndex + 1) % colors.length;
} }
return values()[(ordinal() + 1) % values().length]; return colors[nextIndex];
} }
} }

View File

@@ -0,0 +1,133 @@
package pp.mdga.game;
import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory;
/**
* This class represents a simple die with the possibilities to shuffle and return the roll result.
* An important fact, the sum of ZERO_EYE, NORMAL_EYE and DOUBLE_EYE have to be 1.0;
*/
public class Die {
/**
* The maximum number of eyes on the die.
*/
public static final int MAXIMUM_EYES = 6;
/**
* The probability of rolling a zero eye.
*/
public static final double ZERO_EYE = 0.2;
/**
* The probability of rolling a normal eye.
*/
public static final double NORMAL_EYE = 0.2;
/**
* The probability of rolling a double eye.
*/
public static final double DOUBLE_EYE = 0.6;
/**
* The modifier applied to the die roll.
*/
private int dieModifier = 1;
/**
* The random number generator used for die rolls.
*/
private final RandomGenerator random;
/**
* The result of the last die roll.
*/
private int lastNumberOfDice;
/**
* This constructor is used to create a new Die object with a random seed.
*/
public Die() {
this.random = RandomGeneratorFactory.of("Random").create();
}
/**
* This constructor is used to create a new Die object with a given seed.
*
* @param seed the seed for the random number generator
*/
public Die(long seed) {
this.random = RandomGeneratorFactory.of("Random").create(seed);
}
/**
* This method will be used to return a random number generated by the random attribute of Die class.
*
* @return lastNumberOfDice as an Integer.
*/
public int shuffle() {
this.lastNumberOfDice = this.random.nextInt(MAXIMUM_EYES) + 1;
return this.lastNumberOfDice;
}
/**
* This method will be used to return the given roll parameter.
* It will be used for test cases.
*
* @param roll as the roll result which will be returned as an Integer.
* @return lastNumberOfDice as an Integer.
*/
public int shuffle(int roll) {
this.lastNumberOfDice = roll;
return this.lastNumberOfDice;
}
/**
* This method will be used to modify the value of dieModifier attribute of Die class.
*/
public void modify() {
float randomFloat = this.random.nextFloat();
if (randomFloat < ZERO_EYE) {
this.dieModifier = 0;
} else if (ZERO_EYE <= randomFloat && randomFloat < ZERO_EYE + NORMAL_EYE) {
this.dieModifier = 1;
} else if (ZERO_EYE + NORMAL_EYE <= randomFloat && randomFloat < ZERO_EYE + NORMAL_EYE + DOUBLE_EYE) {
this.dieModifier = 2;
}
}
/**
* This method will be used to reset all values of the Die class to its origins.
*/
public void reset() {
this.dieModifier = 1;
}
/**
* This method will be used to return dieModifier attribute of Die class.
*
* @return dieModifier as an Integer.
*/
public int getDieModifier() {
return this.dieModifier;
}
/**
* This method will be used return lastNumberOfDice attribute of Die class.
*
* @return lastNumberOfDice as an Integer.
*/
public int getLastNumberOfDice() {
return this.lastNumberOfDice;
}
/**
* This method will be used to set dieModifier attribute of Die class to the given dieModifier parameter.
*
* @param dieModifier as the new value of dieModifier as an Integer.
*/
public void setDieModifier(int dieModifier) {
this.dieModifier = dieModifier;
}
}

View File

@@ -9,25 +9,43 @@
*/ */
public class Game { public class Game {
/** /**
* Constants. * The number of turbo cards available in the game.
*/ */
public static final int AMOUNT_OF_TURBO_CARDS = 16; public static final int AMOUNT_OF_TURBO_CARDS = 16;
public static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12;
/** /**
* Attributes. * The number of shield and swap cards available in the game.
*/ */
public static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12;
// The modifier applied to the dice roll.
private int diceModifier = 1; private int diceModifier = 1;
// The number of eyes shown on the dice.
private int diceEyes; private int diceEyes;
// A map of player IDs to Player objects.
private Map<Integer, Player> players = new HashMap<>(); private Map<Integer, Player> players = new HashMap<>();
// The statistics of the game.
private Statistic gameStatistics; private Statistic gameStatistics;
// The pile of bonus cards available for drawing.
private List<BonusCard> drawPile; private List<BonusCard> drawPile;
// The pile of bonus cards that have been discarded.
private List<BonusCard> discardPile = new ArrayList<>(); private List<BonusCard> discardPile = new ArrayList<>();
// The game board.
private Board board; private Board board;
// The die used in the game.
private Die die;
// The color of the active player.
private Color activeColor; private Color activeColor;
private final ArrayList<Observer> observers = new ArrayList<>();
private boolean allRanked = false; // A flag indicating whether all players are ready.
private boolean movablePieces = false;
private boolean allReady = false; private boolean allReady = false;
/** /**
@@ -66,27 +84,10 @@ public void removePlayer(int id) {
} }
/** /**
* This method adds an observer to the game. * This method updates the active state of a player.
* *
* @param observer the observer to be added * @param id the id of the player
*/ * @param active the new active state
public void addObserver(Observer observer) {
observers.add(observer);
}
/**
* This method removes an observer from the game.
*
* @param observer the observer to be removed
*/
public void removeObserver(Observer observer) {
observers.remove(observer);
}
/**
*
* @param id
* @param active
*/ */
public void updatePlayerActiveState(int id, boolean active) { public void updatePlayerActiveState(int id, boolean active) {
this.players.get(id).setActive(active); this.players.get(id).setActive(active);
@@ -139,7 +140,7 @@ public int getNumberOfActivePlayers() {
* *
* @return the piece specified by the UUID * @return the piece specified by the UUID
*/ */
public Piece getPieceThroughUUID(UUID pieceId){ public Piece getPieceThroughUUID(UUID pieceId) {
for (var playerData : board.getPlayerData().values()) { for (var playerData : board.getPlayerData().values()) {
for (var piece : playerData.getPieces()) { for (var piece : playerData.getPieces()) {
if (piece.getUuid().equals(pieceId)) { if (piece.getUuid().equals(pieceId)) {
@@ -150,15 +151,6 @@ public Piece getPieceThroughUUID(UUID pieceId){
return null; return null;
} }
/**
* This method notifies the observers.
*/
public void notifyObservers() {
for (Observer observer : new ArrayList<>(observers)) {
//TODO: observer.update();
}
}
/** /**
* This method returns the dice modifier. * This method returns the dice modifier.
* *
@@ -231,15 +223,6 @@ public Color getActiveColor() {
return activeColor; return activeColor;
} }
/**
* 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 dice modifier. * This method sets the dice modifier.
* *
@@ -312,35 +295,6 @@ public void setActiveColor(Color activeColor) {
this.activeColor = activeColor; this.activeColor = activeColor;
} }
/**
* This method sets the game interruption state.
*
* @param movablePieces the new game interruption state
*/
public void setMovablePieces(Boolean movablePieces) {
this.movablePieces = movablePieces;
if (Boolean.FALSE.equals(movablePieces)) 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 (Boolean.TRUE.equals(allRanked)) notifyObservers();
}
/** /**
* This method returns the all ready state. * This method returns the all ready state.
* *
@@ -357,6 +311,5 @@ public Boolean allReady() {
*/ */
public void setAllReady(Boolean allReady) { public void setAllReady(Boolean allReady) {
this.allReady = allReady; this.allReady = allReady;
if (Boolean.TRUE.equals(allReady)) notifyObservers();
} }
} }

View File

@@ -1,6 +1,7 @@
package pp.mdga.game; package pp.mdga.game;
/**
* Represents a home node.
*/
public class HomeNode extends Node { public class HomeNode extends Node {
public HomeNode() {}
} }

View File

@@ -6,8 +6,6 @@
public class Node { public class Node {
protected Piece occupant; protected Piece occupant;
public Node() {}
/** /**
* This method is used to get an occupant of the Node. * This method is used to get an occupant of the Node.
* *
@@ -23,7 +21,7 @@ public Piece getOccupant() {
* @param occupant the new occupant of the node * @param occupant the new occupant of the node
*/ */
public void setOccupant(Piece occupant) { public void setOccupant(Piece occupant) {
if (occupant.isSuppressed()){ if (occupant.isSuppressed()) {
occupant.setShield(ShieldState.NONE); occupant.setShield(ShieldState.NONE);
} }
this.occupant = occupant; this.occupant = occupant;

View File

@@ -6,9 +6,24 @@
* This class will be used to hold all Piece relevant data. * This class will be used to hold all Piece relevant data.
*/ */
public class Piece { public class Piece {
/**
* The shield state of the piece.
*/
private ShieldState shield; private ShieldState shield;
/**
* The current state of the piece.
*/
private PieceState state; private PieceState state;
/**
* The color of the piece.
*/
private final Color color; private final Color color;
/**
* The unique identifier of the piece.
*/
private final UUID uuid = UUID.randomUUID(); private final UUID uuid = UUID.randomUUID();
/** /**

View File

@@ -1,8 +1,23 @@
package pp.mdga.game; package pp.mdga.game;
/**
* Represents the state of a piece.
*/
public enum PieceState { public enum PieceState {
/**
* The piece is active.
*/
ACTIVE, ACTIVE,
/**
* The piece is waiting.
*/
WAITING, WAITING,
/**
* The piece is in the home.
*/
HOME, HOME,
/**
* The piece is finished.
*/
HOMEFINISHED HOMEFINISHED
} }

View File

@@ -6,11 +6,34 @@
* This class will be used to handle general PlayerData * This class will be used to handle general PlayerData
*/ */
public class Player { public class Player {
/**
* The name of the player.
*/
private String name; private String name;
/**
* The statistics of the player.
*/
private Statistic playerStatistic; private Statistic playerStatistic;
/**
* The hand cards of the player.
*/
private ArrayList<BonusCard> handCards; private ArrayList<BonusCard> handCards;
/**
* The color of the player.
*/
private Color color = Color.NONE; private Color color = Color.NONE;
/**
* Indicates if the player is ready.
*/
private boolean isReady; private boolean isReady;
/**
* Indicates if the player is active.
*/
private boolean active = true; private boolean active = true;
/** /**
@@ -72,7 +95,7 @@ public ArrayList<BonusCard> getHandCards() {
* *
* @param card the card to be added to the players hand * @param card the card to be added to the players hand
*/ */
public void addHandCards(BonusCard card) { public void addHandCard(BonusCard card) {
handCards.add(card); handCards.add(card);
} }

View File

@@ -4,9 +4,24 @@
* This class is used to represent PlayerData related to the board * This class is used to represent PlayerData related to the board
*/ */
public class PlayerData { public class PlayerData {
/**
* An array of HomeNode objects representing the home nodes of the player.
*/
private HomeNode[] homeNodes; private HomeNode[] homeNodes;
/**
* The index of the start node for the player.
*/
private int startNodeIndex; private int startNodeIndex;
/**
* An array of Piece objects representing the waiting area of the player.
*/
private Piece[] waitingArea; private Piece[] waitingArea;
/**
* An array of Piece objects representing all the pieces of the player.
*/
private Piece[] pieces; private Piece[] pieces;
/** /**
@@ -75,7 +90,7 @@ public Piece[] getPieces() {
* @param piece the piece to be added to the waiting area * @param piece the piece to be added to the waiting area
*/ */
public void addWaitingPiece(Piece piece) { public void addWaitingPiece(Piece piece) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (waitingArea[i] == null) { if (waitingArea[i] == null) {
waitingArea[i] = piece; waitingArea[i] = piece;
return; return;

View File

@@ -1,7 +1,19 @@
package pp.mdga.game; package pp.mdga.game;
/**
* Represents the state of a piece's shield.
*/
public enum ShieldState { public enum ShieldState {
/**
* The shield is not active.
*/
NONE, NONE,
/**
* The shield is active.
*/
ACTIVE, ACTIVE,
/**
* The shield is suppressed, when the piece is on a start node.
*/
SUPPRESSED SUPPRESSED
} }

View File

@@ -1,24 +1,21 @@
package pp.mdga.game; package pp.mdga.game;
/**
* Represents a start node.
*/
public class StartNode extends Node { public class StartNode extends Node {
/**
public StartNode(Color color) { * The color of the node.
this.color = color; */
}
private Color color; private Color color;
/** /**
* This method is used to set a new Occupant * Creates a new start node with the given color.
* *
* @param occupant the new occupant of the node * @param color the color of the node
*/ */
@Override public StartNode(Color color) {
public void setOccupant(Piece occupant) { this.color = color;
if (occupant.isShielded()){
occupant.setShield(ShieldState.SUPPRESSED);
}
this.occupant = occupant;
} }
/** /**

View File

@@ -4,13 +4,39 @@
* This class will be used to store Statistics during the Game; * This class will be used to store Statistics during the Game;
*/ */
public class Statistic { public class Statistic {
/**
* The number of cards played.
*/
private int cardsPlayed; private int cardsPlayed;
/**
* The number of pieces thrown. (enemy)
*/
private int piecesThrown; private int piecesThrown;
/**
* The number of pieces being thrown. (own pieces)
*/
private int piecesBeingThrown; private int piecesBeingThrown;
/**
* The number of times a 6 was diced.
*/
private int diced6; private int diced6;
/**
* The number of nodes traveled.
*/
private int traveledNodes; private int traveledNodes;
/**
* The number of bonus nodes activated.
*/
private int activatedBonusNodes; private int activatedBonusNodes;
/**
* Constructs a new Statistic object with all values initialized to 0.
*/
public Statistic() { public Statistic() {
cardsPlayed = 0; cardsPlayed = 0;
piecesThrown = 0; piecesThrown = 0;