Updated 'Game' class.

Updated the 'Game' class by adjusting the JavaDocs and rewriting the constructor for maintainability and readability.
This commit is contained in:
Daniel Grigencha
2024-12-05 04:52:59 +01:00
parent f90aed7bbb
commit 154efccf31

View File

@@ -3,7 +3,7 @@
import java.util.*; import java.util.*;
/** /**
* The Game class represents the game state of the Ludo game. * The Game class represents the game state of the game.
* It contains all the information needed to play the game. * It contains all the information needed to play the game.
* The game state is updated by the game logic. * The game state is updated by the game logic.
*/ */
@@ -14,38 +14,53 @@ public class Game {
public static final int AMOUNT_OF_TURBO_CARDS = 16; public static final int AMOUNT_OF_TURBO_CARDS = 16;
/** /**
* The number of shield and swap cards available in the game. * The number of shield cards available in the game.
*/ */
public static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12; public static final int AMOUNT_OF_SHIELD_CARDS = 12;
// The modifier applied to the dice roll. /**
private int diceModifier = 1; * The number of swap cards available in the game.
*/
public static final int AMOUNT_OF_SWAP_CARDS = 12;
// The number of eyes shown on the dice. /**
private int diceEyes; * A map of player IDs to Player objects.
*/
// 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. /**
* The statistics of the game.
*/
private Statistic gameStatistics; private Statistic gameStatistics;
// The pile of bonus cards available for drawing. /**
private List<BonusCard> drawPile; * The pile of bonus cards available for drawing.
*/
private List<BonusCard> drawPile = new ArrayList<>();
// The pile of bonus cards that have been discarded. /**
* The pile of bonus cards that have been discarded.
*/
private List<BonusCard> discardPile = new ArrayList<>(); private List<BonusCard> discardPile = new ArrayList<>();
// The game board. /**
* The game board.
*/
private Board board; private Board board;
// The die used in the game. /**
* The die used in the game.
*/
private Die die; private Die die;
// The host of this game /**
* The host of this game
*/
private int host = -1; private int host = -1;
// The color of the active player. /**
* The color of the active player.
*/
private Color activeColor; private Color activeColor;
/** /**
@@ -53,18 +68,30 @@ public class Game {
*/ */
public Game() { public Game() {
gameStatistics = new Statistic(); gameStatistics = new Statistic();
drawPile = new ArrayList<>(); initializeDrawPile();
for (int i = 0; i < AMOUNT_OF_TURBO_CARDS; i++) {
drawPile.add(BonusCard.TURBO);
}
for (int i = 0; i < AMOUNT_OF_SHIELD_AND_SWAP_CARDS; i++) {
drawPile.add(BonusCard.SWAP);
drawPile.add(BonusCard.SHIELD);
}
board = new Board(); board = new Board();
die = new Die(); die = new Die();
} }
/**
* This method initializes the draw pile with the predefined number of bonus cards.
*/
private void initializeDrawPile() {
addBonusCards(BonusCard.TURBO, AMOUNT_OF_TURBO_CARDS);
addBonusCards(BonusCard.SWAP, AMOUNT_OF_SWAP_CARDS);
addBonusCards(BonusCard.SHIELD, AMOUNT_OF_SHIELD_CARDS);
}
/**
* This method adds a number of bonus cards to the draw pile.
*
* @param card the card to add
* @param count the number of cards to add
*/
private void addBonusCards(BonusCard card, int count) {
drawPile.addAll(Collections.nCopies(count, card));
}
/** /**
* This method adds a player to the game. * This method adds a player to the game.
* *
@@ -244,24 +271,6 @@ public boolean isHost() {
return this.host != -1; return this.host != -1;
} }
/**
* This method returns the dice modifier.
*
* @return the dice modifier
*/
public int getDiceModifier() {
return diceModifier;
}
/**
* This method returns the dice eyes.
*
* @return the dice eyes
*/
public int getDiceEyes() {
return diceEyes;
}
/** /**
* This method returns the players. * This method returns the players.
* *
@@ -334,24 +343,6 @@ public int getHost() {
return this.host; return this.host;
} }
/**
* This method sets the dice modifier.
*
* @param diceModifier the new dice modifier
*/
public void setDiceModifier(int diceModifier) {
this.diceModifier = diceModifier;
}
/**
* This method sets the dice eyes.
*
* @param diceEyes the new dice eyes
*/
public void setDiceEyes(int diceEyes) {
this.diceEyes = diceEyes;
}
/** /**
* This method sets the players. * This method sets the players.
* *