From 7c5720cb9d6d0c7b34d44b90976ac1b67d43ae42 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Sun, 24 Nov 2024 23:06:30 +0100 Subject: [PATCH] fixed sonarlint errors and deleted map playerConnectionID --- .../src/main/java/pp.mdga/game/Game.java | 71 +++++-------------- 1 file changed, 16 insertions(+), 55 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 427ea384..01a178cb 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 @@ -12,16 +12,15 @@ public class Game { private int diceModifier = 1; private int diceEyes; - private Map players = new HashMap(); + private Map players = new EnumMap<>(Color.class); private Statistic gameStatistics; - private ArrayList drawPile; - private ArrayList discardPile = new ArrayList<>(); + private List drawPile; + private List discardPile = new ArrayList<>(); private Board board; private Color activeColor; - private LinkedList order; - private Map playerConnectionID; + private List order; - private ArrayList observers = new ArrayList<>(); + private final ArrayList observers = new ArrayList<>(); private Player startPlayer; private Boolean gameHasStarted = false; private Boolean playerHasDisconnected = false; @@ -127,7 +126,7 @@ public void setGameStatistics(Statistic gameStatistics) { * * @return the draw pile */ - public ArrayList getDrawPile() { + public List getDrawPile() { return drawPile; } @@ -136,7 +135,7 @@ public ArrayList getDrawPile() { * * @param drawPile the new draw pile */ - public void setDrawPile(ArrayList drawPile) { + public void setDrawPile(List drawPile) { this.drawPile = drawPile; } @@ -145,7 +144,7 @@ public void setDrawPile(ArrayList drawPile) { * * @return the discard pile */ - public ArrayList getDiscardPile() { + public List getDiscardPile() { return discardPile; } @@ -154,7 +153,7 @@ public ArrayList getDiscardPile() { * * @param discardPile the new discard pile */ - public void setDiscardPile(ArrayList discardPile) { + public void setDiscardPile(List discardPile) { this.discardPile = discardPile; } @@ -199,7 +198,7 @@ public void setActiveColor(Color activeColor) { * * @return the order of the players */ - public LinkedList getOrder() { + public List getOrder() { return order; } @@ -208,48 +207,10 @@ public LinkedList getOrder() { * * @param order the new order of the players */ - public void setOrder(LinkedList order) { + public void setOrder(List 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. * @@ -321,7 +282,7 @@ public Boolean playerHasDisconnected() { */ public void setGameIsInterrupted(Boolean gameIsInterrupted) { this.gameIsInterrupted = gameIsInterrupted; - if (!gameIsInterrupted) notifyObservers(); + if (Boolean.FALSE.equals(gameIsInterrupted)) notifyObservers(); } /** @@ -349,7 +310,7 @@ public Boolean getMovablePieces() { */ public void setMovablePieces(Boolean movablePieces) { this.movablePieces = movablePieces; - if (!movablePieces) notifyObservers(); + if (Boolean.FALSE.equals(movablePieces)) notifyObservers(); } /** @@ -359,7 +320,7 @@ public void setMovablePieces(Boolean movablePieces) { */ public void setPlayerHasDisconnected(Boolean playerHasDisconnected) { this.playerHasDisconnected = playerHasDisconnected; - if (playerHasDisconnected) notifyObservers(); + if (Boolean.TRUE.equals(playerHasDisconnected)) notifyObservers(); } /** @@ -378,7 +339,7 @@ public Boolean allRanked() { */ public void setAllRanked(Boolean allRanked) { this.allRanked = allRanked; - if (allRanked) notifyObservers(); + if (Boolean.TRUE.equals(allRanked)) notifyObservers(); } /** @@ -415,7 +376,7 @@ public Boolean allReady() { */ public void setAllReady(Boolean allReady) { this.allReady = allReady; - if (allReady) notifyObservers(); + if (Boolean.TRUE.equals(allReady)) notifyObservers(); } /**