From 154efccf316ba8ccfc6fb033b8a8de226a39aaae Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Thu, 5 Dec 2024 04:52:59 +0100 Subject: [PATCH] Updated 'Game' class. Updated the 'Game' class by adjusting the JavaDocs and rewriting the constructor for maintainability and readability. --- .../src/main/java/pp/mdga/game/Game.java | 113 ++++++++---------- 1 file changed, 52 insertions(+), 61 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java index 3752c00f..498a9a8d 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java @@ -3,7 +3,7 @@ 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. * 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; /** - * 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 players = new HashMap<>(); - // The statistics of the game. + /** + * The statistics of the game. + */ private Statistic gameStatistics; - // The pile of bonus cards available for drawing. - private List drawPile; + /** + * The pile of bonus cards available for drawing. + */ + private List drawPile = new ArrayList<>(); - // The pile of bonus cards that have been discarded. + /** + * The pile of bonus cards that have been discarded. + */ private List discardPile = new ArrayList<>(); - // The game board. + /** + * The game board. + */ private Board board; - // The die used in the game. + /** + * The die used in the game. + */ private Die die; - // The host of this game + /** + * The host of this game + */ private int host = -1; - // The color of the active player. + /** + * The color of the active player. + */ private Color activeColor; /** @@ -53,18 +68,30 @@ public class Game { */ public Game() { gameStatistics = new Statistic(); - drawPile = new ArrayList<>(); - 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); - } + initializeDrawPile(); board = new Board(); 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. * @@ -244,24 +271,6 @@ public boolean isHost() { 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. * @@ -334,24 +343,6 @@ public int getHost() { 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. *