From 3c0806bcdbf8bd6c405dcc424cc905c42e04c348 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 5 May 2020 15:30:16 +0200 Subject: [PATCH] Fikser noen feil rapportert av IntelliJ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gjør privat det som kan gjøres privat Legger til final der mulig Endrer kode slik at interfaces blir brukt der mulig --- .../inf112/fiasko/roborally/objects/Board.java | 4 ++-- .../roborally/objects/InteractableGame.java | 11 +++++++++++ .../inf112/fiasko/roborally/objects/Phase.java | 7 +++++-- .../fiasko/roborally/objects/RoboRallyGame.java | 14 ++++---------- .../inf112/fiasko/roborally/ui/RoboRallyUI.java | 3 ++- .../fiasko/roborally/ui/RoboRallyWrapper.java | 3 ++- .../roborally/ui/screens/CardChoiceScreen.java | 15 +++++++++------ .../inf112/fiasko/roborally/objects/FakeGame.java | 10 ++++++++++ 8 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 44bf07d..c1807de 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -463,7 +463,7 @@ public class Board { * * @param robot The robot to re-spawn */ - public void respawnRobot(Robot robot) { + private void respawnRobot(Robot robot) { Position backupPosition = robot.getBackupPosition(); int startX = backupPosition.getXCoordinate(); int startY = backupPosition.getYCoordinate(); @@ -499,7 +499,7 @@ public class Board { * @param direction The direction of the face of the square to check * @return Whether the robot was re-spawned */ - public boolean tryRobotRespawn(Robot robot, int size, int startX, int startY, Direction direction) { + private boolean tryRobotRespawn(Robot robot, int size, int startX, int startY, Direction direction) { int axis; for (int i = 1; i <= size; i++) { if (direction == Direction.NORTH || direction == Direction.SOUTH) { diff --git a/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java b/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java index a5ec132..42fd0ac 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java @@ -102,4 +102,15 @@ public interface InteractableGame { */ void setProgram(List program); + /** + * Starts a turn in the game + */ + void runTurn(); + + /** + * Gets the power down status of the client playing this instance of the game + * + * @return Whether this player's robot is in power down + */ + boolean getRobotPowerDown(); } diff --git a/src/main/java/inf112/fiasko/roborally/objects/Phase.java b/src/main/java/inf112/fiasko/roborally/objects/Phase.java index e5b4d7c..183dd31 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Phase.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Phase.java @@ -62,10 +62,13 @@ public class Phase { fireAllLasers(); checkAllFlags(); - updateRobotRespawn(); + updateRobotBackups(); } - public void updateRobotRespawn() { + /** + * Updates backups for all robots standing on a repair tile + */ + private void updateRobotBackups() { gameBoard.updateRobotBackups(); } diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 7ac6ebd..463b34d 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -34,7 +34,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { private List program; private ProgrammingCardDeck playerHand; private ProgrammingCardDeck extraCards; - private Boolean testingMode; + private final Boolean testingMode; /** * Instantiates a new Robo Rally game @@ -55,12 +55,8 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { initializeGame(boardName); } - /** - * Gets the power down status of the client playing this instance of the game - * - * @return Whether this player's robot is in power down - */ - public Boolean getRobotPowerDown() { + @Override + public boolean getRobotPowerDown() { Player player = getPlayerFromName(this.playerName); if (player != null) { return gameBoard.getPowerDown(player.getRobotID()); @@ -279,9 +275,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { } } - /** - * Starts a turn in the game - */ + @Override public void runTurn() { // Sets the power down status to true on robots that have players who planned one this turn. // Resets players power down for next turn to false. diff --git a/src/main/java/inf112/fiasko/roborally/ui/RoboRallyUI.java b/src/main/java/inf112/fiasko/roborally/ui/RoboRallyUI.java index fd3fe4a..8165311 100644 --- a/src/main/java/inf112/fiasko/roborally/ui/RoboRallyUI.java +++ b/src/main/java/inf112/fiasko/roborally/ui/RoboRallyUI.java @@ -1,6 +1,7 @@ package inf112.fiasko.roborally.ui; import inf112.fiasko.roborally.networking.RoboRallyServer; +import inf112.fiasko.roborally.objects.InteractableGame; import inf112.fiasko.roborally.objects.RoboRallyGame; /** @@ -12,7 +13,7 @@ public interface RoboRallyUI { * * @return The game used by the UI */ - RoboRallyGame getGame(); + InteractableGame getGame(); /** * Sets the robo rally game being rendered by the UI diff --git a/src/main/java/inf112/fiasko/roborally/ui/RoboRallyWrapper.java b/src/main/java/inf112/fiasko/roborally/ui/RoboRallyWrapper.java index 92eeae3..eb83a6e 100644 --- a/src/main/java/inf112/fiasko/roborally/ui/RoboRallyWrapper.java +++ b/src/main/java/inf112/fiasko/roborally/ui/RoboRallyWrapper.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import inf112.fiasko.roborally.networking.RoboRallyClient; import inf112.fiasko.roborally.networking.RoboRallyServer; +import inf112.fiasko.roborally.objects.InteractableGame; import inf112.fiasko.roborally.objects.RoboRallyGame; /** @@ -37,7 +38,7 @@ public class RoboRallyWrapper extends Game implements RoboRallyUI { } @Override - public RoboRallyGame getGame() { + public InteractableGame getGame() { return roboRallyGame; } diff --git a/src/main/java/inf112/fiasko/roborally/ui/screens/CardChoiceScreen.java b/src/main/java/inf112/fiasko/roborally/ui/screens/CardChoiceScreen.java index bd46f68..da42f69 100644 --- a/src/main/java/inf112/fiasko/roborally/ui/screens/CardChoiceScreen.java +++ b/src/main/java/inf112/fiasko/roborally/ui/screens/CardChoiceScreen.java @@ -13,6 +13,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.viewport.FitViewport; import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; +import inf112.fiasko.roborally.objects.InteractableGame; import inf112.fiasko.roborally.objects.ProgrammingCard; import inf112.fiasko.roborally.objects.ProgrammingCardDeck; import inf112.fiasko.roborally.objects.properties.GameState; @@ -39,6 +40,7 @@ public class CardChoiceScreen extends InteractiveScreen { private final List chosenCards; private final int maxCards; private long timerStarted; + private final InteractableGame game; /** * Instantiates a new card choice screen @@ -46,9 +48,10 @@ public class CardChoiceScreen extends InteractiveScreen { * @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen */ public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) { - ProgrammingCardDeck deck = roboRallyWrapper.roboRallyGame.getPlayerHand(); + game = roboRallyWrapper.getGame(); + ProgrammingCardDeck deck = game.getPlayerHand(); this.roboRallyWrapper = roboRallyWrapper; - maxCards = roboRallyWrapper.roboRallyGame.getProgramSize(); + maxCards = game.getProgramSize(); if (maxCards == -1) { throw new IllegalArgumentException("This player should not be able to choose any cards at this point in " + "time."); @@ -125,8 +128,8 @@ public class CardChoiceScreen extends InteractiveScreen { roboRallyWrapper.shouldHurry = false; List newProgram = getChosenAndLockedCards(); //Save the program to get locked cards later - roboRallyWrapper.roboRallyGame.setProgram(newProgram); - roboRallyWrapper.roboRallyGame.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS); + game.setProgram(newProgram); + game.setGameState(GameState.WAITING_FOR_OTHER_PLAYERS_PROGRAMS); roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper)); roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(requestPowerDown, newProgram)); } else { @@ -182,9 +185,9 @@ public class CardChoiceScreen extends InteractiveScreen { * @return The player's old program */ private List getOldProgram() { - List oldProgram = roboRallyWrapper.roboRallyGame.getProgram(); + List oldProgram = game.getProgram(); if (oldProgram != null && oldProgram.size() == 0) { - oldProgram = roboRallyWrapper.roboRallyGame.getExtraCards().getCards(); + oldProgram = game.getExtraCards().getCards(); int nulls = 5 - oldProgram.size(); for (int i = 0; i < nulls; i++) { oldProgram.add(0, null); diff --git a/src/test/java/inf112/fiasko/roborally/objects/FakeGame.java b/src/test/java/inf112/fiasko/roborally/objects/FakeGame.java index 413e26c..60b8a16 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/FakeGame.java +++ b/src/test/java/inf112/fiasko/roborally/objects/FakeGame.java @@ -76,4 +76,14 @@ public class FakeGame implements InteractableGame { public void setProgram(List program) { //Not needed for testing } + + @Override + public void runTurn() { + //Not needed for testing + } + + @Override + public boolean getRobotPowerDown() { + return false; + } }