diff --git a/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java b/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java index a7082e1..06ef802 100644 --- a/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java +++ b/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java @@ -44,6 +44,8 @@ public enum GameState { /** * Indicates that the game is no longer running */ - EXITED + EXITED, + + SKIP_POWER_DOWN_SCREEN } diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java index dd8afe4..3c8a526 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java @@ -7,6 +7,9 @@ import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.Viewport; import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; +import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; + +import java.util.ArrayList; /** * This screen is used to wait for something @@ -68,6 +71,14 @@ public class LoadingScreen extends AbstractScreen { case EXITED: roboRallyWrapper.quit("All players died. Cannot continue playing."); break; + case CHOOSING_POWER_DOWN: + roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(this.roboRallyWrapper)); + break; + case SKIP_POWER_DOWN_SCREEN: + roboRallyWrapper.roboRallyGame.setGameState(GameState.LOADING); + roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper)); + roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(false, new ArrayList<>())); + break; default: System.out.println("The loading screen doesn't know what to do with " + gameState); break; diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java index 18b38f0..6e344b4 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java @@ -57,11 +57,18 @@ public class PowerDownScreen extends AbstractScreen { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); roboRallyWrapper.batch.setProjectionMatrix(camera.combined); - + String descriptiontext; + if(roboRallyWrapper.roboRallyGame.getGameState()==GameState.CHOOSING_POWER_DOWN){ + descriptiontext = "click the button to enter powerdown next round"; + } + else{ + descriptiontext = "continue powerdown?"; + } int elapsedTime = (int) Math.floor((System.currentTimeMillis() - startTime) / 1000f); roboRallyWrapper.batch.begin(); - roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to enter Power Down next round", + + roboRallyWrapper.font.draw(roboRallyWrapper.batch, descriptiontext, applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1, true); roboRallyWrapper.font.draw(roboRallyWrapper.batch, String.valueOf(10 - elapsedTime), diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java index df7101b..cc3c189 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java @@ -11,6 +11,8 @@ import inf112.fiasko.roborally.networking.containers.ProgamsContainer; import inf112.fiasko.roborally.objects.ProgrammingCardDeck; import inf112.fiasko.roborally.objects.RoboRallyGame; +import java.util.ArrayList; + /** * This listener handles all receiving from the server */ @@ -40,7 +42,16 @@ class RoboRallyClientListener extends Listener { wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(), wrapper.server != null, info.getPlayerName(), wrapper.server); } else if (object instanceof ProgrammingCardDeck) { - wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS); + if(((ProgrammingCardDeck) object).isEmpty()){ + if (wrapper.roboRallyGame.getRobotPowerdown()){ + wrapper.roboRallyGame.setGameState(GameState.SKIP_POWER_DOWN_SCREEN); + } + else { + wrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN); + } + wrapper.roboRallyGame.setProgram(new ArrayList<>()); + } + else {wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS);} new Thread(() -> wrapper.roboRallyGame.setPlayerHand((ProgrammingCardDeck) object)).start(); } else if (object instanceof ProgamsContainer) { new Thread(() -> { diff --git a/src/main/java/inf112/fiasko/roborally/objects/Player.java b/src/main/java/inf112/fiasko/roborally/objects/Player.java index d29f1ae..c0c1922 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Player.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Player.java @@ -77,7 +77,7 @@ public class Player { * @param cardList list the size of 5 with programing cards */ public void setProgram(List cardList) { - if (cardList.size() != 5) { + if (cardList.size() != 5 && !cardList.isEmpty()) { throw new IllegalArgumentException("The program must contain exactly 5 cards."); } else { program = new ArrayList<>(cardList); diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 22b4492..99ec6cf 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; /** * This class represent a game which is drawable using libgdx @@ -33,6 +34,13 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { private ProgrammingCardDeck playerHand; private Phase phase; + public Boolean getRobotPowerdown(){ + if(getPlayerFromName(this.playerName)!=null){ + return gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID()); + } + return false; + } + /** * Instantiates a new Robo Rally game * @@ -173,19 +181,20 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { removeNonLockedProgrammingCardsFromPlayers(); } - if (gameBoard.getPowerDown(getPlayerFromName(this.playerName).getRobotID())) { + if (gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID())) { setGameState(GameState.CHOOSING_STAY_IN_POWER_DOWN); } else { setGameState(GameState.LOADING); } - //updateRobotPowerDown(); Should this be here? } @Override public void receiveStayInPowerDown(PowerDownContainer powerDowns) { for (Player player : playerList) { - player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName())); + if(gameBoard.getPowerDown(player.getRobotID())) { + player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName())); + } } respawnRobots(); sendAllDeadPlayersToServer();