From c7b65d949a82f216c6d528ff626be15a919c7083 Mon Sep 17 00:00:00 2001 From: Hanno Fleischer Date: Thu, 14 Nov 2024 15:32:27 +0100 Subject: [PATCH] added java docs to model/game and wrote the remaining getter and setter --- .../src/main/java/pp.mdga/game/Board.java | 11 +- .../src/main/java/pp.mdga/game/Game.java | 226 +++++++++++++++++- .../src/main/java/pp.mdga/game/Piece.java | 39 +++ .../src/main/java/pp.mdga/game/StartNode.java | 24 +- 4 files changed, 295 insertions(+), 5 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java b/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java index dfd95a77..8b48d6e4 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/game/Board.java @@ -6,7 +6,7 @@ * This class will be used to hold all Board relevant data. */ public class Board { - private Map playerData; + private Map playerData; private Node[] infield; /** @@ -16,7 +16,12 @@ public Board() { infield = new Node[40]; for (int i = 0; i < 40; i++) { if (i % 10 == 0) { - infield[i] = new StartNode(); + infield[i] = new StartNode( + i == 0 ? Color.ARMY : + i == 10 ? Color.AIRFORCE : + i == 20 ? Color.CYBER : + Color.NAVY + ); } else if (i == 4 || i == 14 || i == 24 || i == 34) { infield[i] = new BonusNode(); } else { @@ -30,7 +35,7 @@ public Board() { * * @return the playerData */ - public Map getPlayerData() { + public Map getPlayerData() { return playerData; } 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 2cc4661e..a038ce4b 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 @@ -5,7 +5,9 @@ import java.util.Map; /** - * This class will be used to handle the data stored in the model + * The Game class represents the game state of the Ludo game. + * It contains all the information needed to play the game. + * The game state is updated by the game logic. */ public class Game { private int diceModifier = 1; @@ -22,6 +24,9 @@ public class Game { private static final int AMOUNT_OF_TURBO_CARDS = 16; private static final int AMOUNT_OF_SHIELD_AND_SWAP_CARDS = 12; + /** + * This constructor creates a new Game object. + */ public Game(){ gameStatistics = new Statistic(); drawPile = new ArrayList<>(); @@ -34,4 +39,223 @@ public Game(){ } board = new Board(); } + + /** + * This method returns the dice modifier. + * + * @return the dice modifier + */ + public int getDiceModifier() { + return diceModifier; + } + + /** + * This method sets the dice modifier. + * + * @param diceModifier the new dice modifier + */ + public void setDiceModifier(int diceModifier) { + this.diceModifier = diceModifier; + } + + /** + * This method returns the dice eyes. + * + * @return the dice eyes + */ + public int getDiceEyes() { + return diceEyes; + } + + /** + * This method sets the dice eyes. + * + * @param diceEyes the new dice eyes + */ + public void setDiceEyes(int diceEyes) { + this.diceEyes = diceEyes; + } + + /** + * This method returns the players. + * + * @return the players + */ + public Map getPlayers() { + return players; + } + + /** + * This method sets the players. + * + * @param players the new players + */ + public void setPlayers(Map players) { + this.players = players; + } + + /** + * This method returns the game statistics. + * + * @return the game statistics + */ + public Statistic getGameStatistics() { + return gameStatistics; + } + + /** + * This method sets the game statistics. + * + * @param gameStatistics the new game statistics + */ + public void setGameStatistics(Statistic gameStatistics) { + this.gameStatistics = gameStatistics; + } + + /** + * This method returns the draw pile. + * + * @return the draw pile + */ + public ArrayList getDrawPile() { + return drawPile; + } + + /** + * This method sets the draw pile. + * + * @param drawPile the new draw pile + */ + public void setDrawPile(ArrayList drawPile) { + this.drawPile = drawPile; + } + + /** + * This method returns the discard pile. + * + * @return the discard pile + */ + public ArrayList getDiscardPile() { + return discardPile; + } + + /** + * This method sets the discard pile. + * + * @param discardPile the new discard pile + */ + public void setDiscardPile(ArrayList discardPile) { + this.discardPile = discardPile; + } + + /** + * This method returns the board. + * + * @return the board + */ + public Board getBoard() { + return board; + } + + /** + * This method sets the board. + * + * @param board the new board + */ + public void setBoard(Board board) { + this.board = board; + } + + /** + * This method returns the active color. + * + * @return the active color + */ + public Color getActiveColor() { + return activeColor; + } + + /** + * This method sets the active color. + * + * @param activeColor the new active color + */ + public void setActiveColor(Color activeColor) { + this.activeColor = activeColor; + } + + /** + * This method returns the order of the players. + * + * @return the order of the players + */ + public LinkedList getOrder() { + return order; + } + + /** + * This method sets the order of the players. + * + * @param order the new order of the players + */ + public void setOrder(LinkedList order) { + this.order = order; + } + + /** + * This method returns the player connection ID. + * + * @return the player connection ID + */ + public Map getPlayerConnectionID() { + return playerConnectionID; + } + + /** + * This method sets the player connection ID. + * + * @param playerConnectionID the new player connection ID + */ + public void setPlayerConnectionID(Map playerConnectionID) { + this.playerConnectionID = playerConnectionID; + } + + /** + * This method sets the player connection ID. + * + * @param color the color of the player + * @param connectionID the new connection ID + */ + public void setPlayerConnectionID(Color color, int connectionID) { + playerConnectionID.put(color, connectionID); + } + + /** + * This method returns the player connection ID. + * + * @param color the color of the player + * @return the player connection ID + */ + public int getPlayerConnectionID(Color color) { + return playerConnectionID.get(color); + } + + /** + * This method adds a player to the game. + * + * @param color the color of the player + * @param player the player to be added + */ + public void addPlayer(Color color, Player player) { + players.put(color, player); + } + + /** + * This method removes a player from the game. + * + * @param color the color of the player + */ + public void removePlayer(Color color) { + players.remove(color); + } } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/game/Piece.java b/Projekte/mdga/model/src/main/java/pp.mdga/game/Piece.java index 47d3041c..e68f3d26 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/game/Piece.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/game/Piece.java @@ -1,36 +1,75 @@ package pp.mdga.game; +/** + * This class will be used to hold all Piece relevant data. + */ public class Piece { private ShieldState shield; private PieceState state; private Color color; + /** + * This constructor is used to create a new Piece + * + * @param color the color of the piece + * @param state the state of the piece + */ public Piece(Color color, PieceState state) { this.color = color; this.state = state; shield = ShieldState.NONE; } + /** + * This method is used to get the color of the piece + * + * @return the color of the piece + */ public void setShield(ShieldState shield) { this.shield = shield; } + /** + * This method is used to get the color of the piece + * + * @return the color of the piece + */ public ShieldState getShield() { return shield; } + /** + * This method is used to get the color of the piece + * + * @param state the state of the piece + */ public void setState(PieceState state) { this.state = state; } + /** + * This method is used to get the color of the piece + * + * @return the color of the piece + */ public PieceState getState() { return state; } + /** + * This method is used to get the color of the piece + * + * @return the color of the piece + */ public boolean isShielded() { return shield == ShieldState.ACTIVE; } + /** + * This method is used to get the color of the piece + * + * @return the color of the piece + */ public boolean isSuppressed() { return shield == ShieldState.SUPPRESSED; } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/game/StartNode.java b/Projekte/mdga/model/src/main/java/pp.mdga/game/StartNode.java index 35130151..85e70cb3 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/game/StartNode.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/game/StartNode.java @@ -2,7 +2,11 @@ public class StartNode extends Node { - public StartNode() {} + public StartNode(Color color) { + this.color = color; + } + + private Color color; /** * This method is used to set a new Occupant @@ -16,4 +20,22 @@ public void setOccupant(Piece occupant) { } this.occupant = occupant; } + + /** + * This method is used to get the color of the node + * + * @return the color of the node + */ + public Color getColor() { + return color; + } + + /** + * This method is used to set the color of the node + * + * @param color the new color of the node + */ + public void setColor(Color color) { + this.color = color; + } }