From d8167ba250844315059879ec4b7702d4bb444613 Mon Sep 17 00:00:00 2001 From: GabrielMagnus Date: Thu, 16 Apr 2020 12:34:54 +0200 Subject: [PATCH 01/19] =?UTF-8?q?Lager=20hjelpemetoder=20for=20=C3=A5=20sj?= =?UTF-8?q?ekke=20roboter=20via=20board?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fiasko/roborally/objects/Board.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 75d85b0..4dad6af 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -756,4 +756,31 @@ public class Board { particles.setElement(positionX, positionY, new Particle(type, laserDirection)); } + /** + * Gets the int corresponding to the flag a robot has last visited + * @param robotID The robot to be checked + * @return The flag last visited in a number + */ + public int getLastFlagVisitedFromRobotID(RobotID robotID) { + return robots.get(robotID).getLastFlagVisited(); + } + + /** + * Sets a boolean for if the robot has touched a flag this turn + * @param robotID The robot to be checked + * @param hasTouched If the robot has touched a flag this turn + */ + public void setHasTouchedFlagThisTurnFromRobotID(RobotID robotID, boolean hasTouched) { + robots.get(robotID).setHasTouchedFlagThisTurn(hasTouched); + } + + /** + * Checks a boolean for if the robot has touched a flag this turn + * @param robotID The robot to be checked + * @return If the robot has touched a flag this turn + */ + public boolean isHasTouchedFlagThisTurnFromRobotID(RobotID robotID) { + return robots.get(robotID).isHasTouchedFlagThisTurn(); + } + } \ No newline at end of file From 4ddc2a1a8346239da5c15cec8b5755699a339250 Mon Sep 17 00:00:00 2001 From: GabrielMagnus Date: Thu, 16 Apr 2020 12:36:33 +0200 Subject: [PATCH 02/19] =?UTF-8?q?Endrer=20checkAllFlags=20til=20=C3=A5=20b?= =?UTF-8?q?ruke=20hjelpemetoder=20fra=20Board?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roborally/objects/RoboRallyGame.java | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 5cbd62f..9b536f1 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -554,31 +554,46 @@ public class RoboRallyGame implements IRoboRallyGame { TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4); for (BoardElementContainer flag:listOfFlags) { Position flagPosition = flag.getPosition(); - if (gameBoard.hasRobotOnPosition(flagPosition)) { - RobotID robotID = gameBoard.getRobotOnPosition(flagPosition); - for (Robot robot : gameBoard.getAliveRobots()) { - if (robot.getRobotId() != robotID || robot.isHasTouchedFlagThisTurn()) { - continue; - } - gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType()); - robot.setHasTouchedFlagThisTurn(true); - if (victoryCheck(robot.getLastFlagVisited(), listOfFlags.size())) { - for (Player player : playerList) { - if (player.getRobotID() != robotID) { - continue; - } - setWinningPlayerName(player.getName()); - setGameState(GameState.GAME_IS_WON); - } - } + if (!gameBoard.hasRobotOnPosition(flagPosition)) { + continue; + } + RobotID robotID = gameBoard.getRobotOnPosition(flagPosition); + if (gameBoard.isHasTouchedFlagThisTurnFromRobotID(robotID)) { + continue; + } + gameBoard.updateFlagOnRobot(robotID, flag.getElement().getTileType()); + gameBoard.setHasTouchedFlagThisTurnFromRobotID(robotID,true); + checkIfPlayerWon(robotID, listOfFlags.size()); + } + } + + /** + * Checks if the player won, and shows the victory screen + * @param robotID The robot to be checked + * @param numberOfFlags The number of flags on the map + */ + private void checkIfPlayerWon(RobotID robotID, int numberOfFlags) { + if (victoryCheck(gameBoard.getLastFlagVisitedFromRobotID(robotID), numberOfFlags)) { + for (Player player : playerList) { + if (player.getRobotID() != robotID) { + continue; } + setWinningPlayerName(player.getName()); + setGameState(GameState.GAME_IS_WON); } } } + /** + * Checks if last flag visited is the last flag + * @param lastFlagVisited The last flag a robot visited + * @param lastFlag The last flag on the map + * @return If the robot won + */ private boolean victoryCheck(int lastFlagVisited, int lastFlag) { return (lastFlagVisited == lastFlag); } + /** * Fires all lasers on the game board */ From 560419d546575d7ca82a2af4311170c37b9caf2a Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:49:28 +0200 Subject: [PATCH 03/19] added classes to kryo --- .../inf112/fiasko/roborally/utility/NetworkUtil.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java b/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java index 55bd52a..863790d 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/NetworkUtil.java @@ -5,12 +5,16 @@ import inf112.fiasko.roborally.elementproperties.Action; import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.networking.containers.ErrorResponse; import inf112.fiasko.roborally.networking.containers.GameStartInfo; +import inf112.fiasko.roborally.networking.containers.PowerdownContainer; +import inf112.fiasko.roborally.networking.containers.ProgamsContainer; +import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; import inf112.fiasko.roborally.objects.IDeck; import inf112.fiasko.roborally.objects.Player; import inf112.fiasko.roborally.objects.ProgrammingCard; import inf112.fiasko.roborally.objects.ProgrammingCardDeck; import java.util.ArrayList; +import java.util.HashMap; /** * This class helps with networking tasks @@ -31,5 +35,11 @@ public final class NetworkUtil { kryo.register(RobotID.class); kryo.register(ProgrammingCardDeck.class); kryo.register(Action.class); + kryo.register(ProgramAndPowerdownRequest.class); + kryo.register(ProgamsContainer.class); + kryo.register(PowerdownContainer.class); + kryo.register(HashMap.class); + + } } From e2928e8f1764bdabbdebcb4bc221f263ef526b37 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:50:45 +0200 Subject: [PATCH 04/19] added ekstra hlper functions --- .../roborally/objects/RoboRallyGame.java | 69 ++++++++++++++++--- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 5cbd62f..7430425 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -9,6 +9,8 @@ import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.elementproperties.TileType; import inf112.fiasko.roborally.networking.RoboRallyClient; import inf112.fiasko.roborally.networking.RoboRallyServer; +import inf112.fiasko.roborally.networking.containers.PowerdownContainer; +import inf112.fiasko.roborally.networking.containers.ProgamsContainer; import inf112.fiasko.roborally.utility.BoardLoaderUtil; import inf112.fiasko.roborally.utility.DeckLoaderUtil; @@ -37,8 +39,24 @@ public class RoboRallyGame implements IRoboRallyGame { private final RoboRallyClient client; private RoboRallyServer server; private String winningPlayerName; + private List program; + private ProgrammingCardDeck playerHand; + public ProgrammingCardDeck getPlayerHand() { + return playerHand; + } + public void setPlayerHand(ProgrammingCardDeck playerHand) { + this.playerHand = playerHand; + } + + public List getProgram() { + return program; + } + + public void setProgram(List program) { + this.program = program; + } public String getPlayerName() { return playerName; @@ -228,6 +246,14 @@ public class RoboRallyGame implements IRoboRallyGame { return null; } + public int getProgramSize(){ + Player player = getPlayerFromName(playerName); + if (player != null) { + return Math.min(5, 5 - gameBoard.getRobotDamage(player.getRobotID()) + 4); + } + return -1; + } + /** * Runs all the steps of one turn in the game * @throws InterruptedException If interrupted while trying to sleep @@ -270,18 +296,40 @@ public class RoboRallyGame implements IRoboRallyGame { } } } - setGameState(GameState.CHOOSING_CARDS); + setGameState(GameState.JUST_BEFORE_CHOOSING_CARDS); + // TODO: Make program for this player, if not in power down // TODO: Ask player for new power down // Run the phases of the game - while (getGameState()==GameState.CHOOSING_CARDS) { - //loops waiting for the player to be done choosing their cards + + + // TODO: If this player is in power down, ask if it shall continue + // Respawn dead robots, as long as they have more lives left + } + + public void recivedStayInPowerdown(PowerdownContainer powerdowns){ + for (Player player:playerList) { + player.setPowerDownNextRound(powerdowns.getPowerdown().get(player.getName())); } - runPhase(1); - runPhase(2); - runPhase(3); - runPhase(4); - runPhase(5); + respawnRobots(); + resetHasTouchedFlagThisTurnForAllRobots(); + } + + public void reciveAllProgrammes(ProgamsContainer programs) throws InterruptedException { + Map> progs = programs.getProgram(); + Map powerdown = programs.getPowerdown(); + String playername; + for (Player player:playerList) { + playername = player.getName(); + player.setInProgram(progs.get(playername)); + player.setPowerDownNextRound(powerdown.get(playername)); + } + setGameState(GameState.RUNNING_PROGRAMS); + runPhase(1); + runPhase(2); + runPhase(3); + runPhase(4); + runPhase(5); // Repair robots on repair tiles repairAllRobotsOnRepairTiles(); @@ -290,9 +338,8 @@ public class RoboRallyGame implements IRoboRallyGame { removeNonLockedProgrammingCardsFromPlayers(); } // TODO: If this player is in power down, ask if it shall continue - // Respawn dead robots, as long as they have more lives left - respawnRobots(); - resetHasTouchedFlagThisTurnForAllRobots(); + + } private void sendAllDeadPlayersToServer() { From a1fba2da881ef91c5974b6ae2cedf941dcd3a8c2 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:51:16 +0200 Subject: [PATCH 05/19] added no args construktor --- .../inf112/fiasko/roborally/objects/ProgrammingCard.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java index d46c688..38acd24 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java +++ b/src/main/java/inf112/fiasko/roborally/objects/ProgrammingCard.java @@ -7,8 +7,8 @@ import inf112.fiasko.roborally.elementproperties.Action; */ public class ProgrammingCard implements Comparable { - private final int cardPriority; - private final Action cardAction; + private int cardPriority; + private Action cardAction; /** * Initializes the priority and the action of the card @@ -20,6 +20,10 @@ public class ProgrammingCard implements Comparable { this.cardAction = cardAction; } + public ProgrammingCard(){ + + } + /** * Gets the priority of the programming card * @return The programming card priority From 6773bc0977aa5c522d85f3e8ee983bc9e9e5ca22 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:51:42 +0200 Subject: [PATCH 06/19] added ekstra functons to the interface --- .../roborally/objects/IInteractableGame.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/inf112/fiasko/roborally/objects/IInteractableGame.java b/src/main/java/inf112/fiasko/roborally/objects/IInteractableGame.java index 29742a8..91ee231 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/IInteractableGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/IInteractableGame.java @@ -1,6 +1,10 @@ package inf112.fiasko.roborally.objects; import inf112.fiasko.roborally.elementproperties.GameState; +import inf112.fiasko.roborally.networking.containers.PowerdownContainer; +import inf112.fiasko.roborally.networking.containers.ProgamsContainer; + +import java.util.List; /** * This interface describes @@ -23,4 +27,21 @@ public interface IInteractableGame { * @return A string of the player name */ String getWinningPlayerName(); + + void reciveAllProgrammes(ProgamsContainer programs) throws InterruptedException; + + void recivedStayInPowerdown(PowerdownContainer powerdowns); + + List getProgram(); + + int getProgramSize(); + + void setPlayerHand(ProgrammingCardDeck playerHand); + + ProgrammingCardDeck getPlayerHand(); + + void setProgram(List program); + + + } From fdc3564265c476ca0ea80178a6b0ae6eb860fbea Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:52:25 +0200 Subject: [PATCH 07/19] added new cases for the server lister and some new function --- .../networking/RoboRallyServerListener.java | 71 +++++++++++++++++-- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java index e8dd3f7..ab0bb2b 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServerListener.java @@ -5,12 +5,17 @@ import com.esotericsoftware.kryonet.Connection; import com.esotericsoftware.kryonet.Listener; import inf112.fiasko.roborally.elementproperties.RobotID; import inf112.fiasko.roborally.networking.containers.ErrorResponse; +import inf112.fiasko.roborally.networking.containers.PowerdownContainer; +import inf112.fiasko.roborally.networking.containers.ProgamsContainer; +import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; +import inf112.fiasko.roborally.objects.ProgrammingCard; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; /** * This listener handles all sending and responses for the server @@ -20,15 +25,19 @@ class RoboRallyServerListener extends Listener { private final Map clients; private final Map playerNames; private final List deadPlayers; + private Map StayInPowerdown = new HashMap<>(); + private Map programs = new HashMap<>(); + private RoboRallyServer server; /** * Instantiates a new Robo Rally server listener */ - RoboRallyServerListener() { + RoboRallyServerListener(RoboRallyServer server) { super(); clients = new HashMap<>(); playerNames = new HashMap<>(); deadPlayers = new ArrayList<>(); + this.server = server; } /** @@ -64,16 +73,64 @@ class RoboRallyServerListener extends Listener { @Override public void received (Connection connection, Object object) { if (object instanceof String) { - String playerName = (String) object; - if (playerNames.containsValue(playerName)) { - String errorMessage = "The player name send is already taken."; - connection.sendTCP(new ErrorResponse(errorMessage, new IllegalArgumentException(errorMessage))); - } else { - playerNames.put(connection, playerName); + System.out.println((String) object); + recivedString(connection,(String) object); + } + else if(object instanceof Boolean){ + recivedContinuePowerdown(connection,(Boolean) object); + } + else if(object instanceof ProgramAndPowerdownRequest){ + reciveProgamAndPowerdownRequest(connection,(ProgramAndPowerdownRequest) object); + } + + } + + private void recivedString(Connection connection,String name){ + String playerName = name; + if (playerNames.containsValue(playerName)) { + String errorMessage = "The player name send is already taken."; + connection.sendTCP(new ErrorResponse(errorMessage, new IllegalArgumentException(errorMessage))); + } else { + playerNames.put(connection, playerName); + } + + } + + private void recivedContinuePowerdown(Connection connection,Boolean bool){ + StayInPowerdown.put(connection,bool); + if(recivedDataFromAllConnections(StayInPowerdown)){ + Map powerdowns = new HashMap<>(); + for (Connection connected:StayInPowerdown.keySet()) { + powerdowns.put(playerNames.get(connected),StayInPowerdown.get(connected)); } + server.sendToAllClients(new PowerdownContainer(powerdowns)); + StayInPowerdown = new HashMap<>(); } } + private void reciveProgamAndPowerdownRequest(Connection connection,ProgramAndPowerdownRequest request){ + programs.put(connection,request); + if(recivedDataFromAllConnections(programs)){ + Map powerdown = new HashMap<>(); + Map> program = new HashMap<>(); + + for (Connection connected:programs.keySet()) { + powerdown.put(playerNames.get(connected),programs.get(connected).getPowerdown()); + program.put(playerNames.get(connected),programs.get(connected).getProgram()); + + } + server.sendToAllClients(new ProgamsContainer(program,powerdown)); + programs = new HashMap<>(); + + } + } + private boolean recivedDataFromAllConnections(Map data){ + Set connections = clients.keySet(); + connections.removeAll(deadPlayers); + return connections.containsAll(data.keySet()) && data.keySet().containsAll(connections); + } + + @Override public void connected(Connection connection) { //The first client to connect is assumed to be the host From 8f73c043bd945f814c3196b7bc2c91cd0422d816 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:54:13 +0200 Subject: [PATCH 08/19] gave the listner a server in the construktor --- .../inf112/fiasko/roborally/networking/RoboRallyServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java index dc35570..ac58c85 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyServer.java @@ -24,7 +24,7 @@ public class RoboRallyServer { server.start(); NetworkUtil.registerClasses(server.getKryo()); server.bind(54555, 54777); - listener = new RoboRallyServerListener(); + listener = new RoboRallyServerListener(this); server.addListener(listener); } From 0c3a8739e11d8cee9f916a78a3b01fa34440ad0f Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:55:59 +0200 Subject: [PATCH 09/19] added some new cases new cases for the listner --- .../networking/RoboRallyClientListener.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java index 2cf7019..8a9ff01 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java @@ -2,13 +2,18 @@ package inf112.fiasko.roborally.networking; import com.esotericsoftware.kryonet.Connection; import com.esotericsoftware.kryonet.Listener; +import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.screens.CardChoiceScreen; import inf112.fiasko.roborally.networking.containers.ErrorResponse; import inf112.fiasko.roborally.networking.containers.GameStartInfo; +import inf112.fiasko.roborally.networking.containers.PowerdownContainer; +import inf112.fiasko.roborally.networking.containers.ProgamsContainer; import inf112.fiasko.roborally.objects.ProgrammingCardDeck; import inf112.fiasko.roborally.objects.RoboRallyGame; +import java.util.concurrent.TimeUnit; + /** * This listener handles all receiving from the server */ @@ -33,11 +38,22 @@ class RoboRallyClientListener extends Listener { GameStartInfo info = (GameStartInfo) object; wrapper.roboRallyGame = new RoboRallyGame(info.getPlayerList(), info.getBoardName(), wrapper.server != null, info.getPlayerName(), wrapper.client, wrapper.server); - wrapper.setScreen(wrapper.screenManager.getLoadingScreen(wrapper)); } else if(object instanceof ProgrammingCardDeck){ - wrapper.setScreen(new CardChoiceScreen(wrapper,(ProgrammingCardDeck) object)); + wrapper.roboRallyGame.setGameState(GameState.CHOOSING_CARDS); + wrapper.roboRallyGame.setPlayerHand((ProgrammingCardDeck) object); } + else if(object instanceof ProgamsContainer){ + try { + wrapper.roboRallyGame.reciveAllProgrammes((ProgamsContainer) object); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + else if (object instanceof PowerdownContainer){ + wrapper.roboRallyGame.recivedStayInPowerdown((PowerdownContainer) object); + } + } } From a8d755a812e93adac03b9a3f0100828a8d2ace9b Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:57:01 +0200 Subject: [PATCH 10/19] added catch exeption to send function --- .../fiasko/roborally/networking/RoboRallyClient.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java index 4572d42..57be1a1 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClient.java @@ -30,9 +30,10 @@ public class RoboRallyClient { * Sends something to the server * @param object The object to send to the server */ - public void sendElement(Object object) { - client.sendTCP(object); - } + public void sendElement(Object object) {try{ + client.sendTCP(object);} + catch(Exception e){e.printStackTrace();} + } } From 19e8c104db09ff6dbc85dbedab07c2f9f6e6f5d5 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:58:01 +0200 Subject: [PATCH 11/19] added card choice screen --- .../fiasko/roborally/gamewrapper/ScreenManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/ScreenManager.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/ScreenManager.java index c697f18..45b892a 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/ScreenManager.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/ScreenManager.java @@ -14,6 +14,15 @@ public class ScreenManager { private IPAddressScreen ipAddressScreen; private LobbyScreen lobbyScreen; private WinnerScreen winnerScreen; + private CardChoiceScreen cardChoiceScreen; + + + public synchronized CardChoiceScreen getCardChoiceScreen(RoboRallyWrapper roboRallyWrapper) { + if (this.cardChoiceScreen == null) { + this.cardChoiceScreen = new CardChoiceScreen(roboRallyWrapper); + } + return cardChoiceScreen; + } /** * Gets an instance of the winner screen From 198a21a5a43f670f7cb8682bbc657ce83ae4034a Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:58:42 +0200 Subject: [PATCH 12/19] added sending information to the server --- .../gamewrapper/screens/PowerDownScreen.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) 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 9390bee..7c0b4b3 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/PowerDownScreen.java @@ -9,8 +9,15 @@ import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.Viewport; +import inf112.fiasko.roborally.elementproperties.Action; +import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.SimpleButton; +import inf112.fiasko.roborally.networking.containers.ProgramAndPowerdownRequest; +import inf112.fiasko.roborally.objects.ProgrammingCard; + +import java.util.ArrayList; +import java.util.List; /** * This screen is used for asking players whether they want to power down @@ -42,8 +49,8 @@ public class PowerDownScreen extends AbstractScreen { powerDownButton.addListener(new InputListener() { @Override public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { - roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(roboRallyWrapper)); - return true;//her we do stuff + sendPowerdownStatus(true); + return true; } }); } @@ -68,10 +75,29 @@ public class PowerDownScreen extends AbstractScreen { stage.draw(); if (elapsedTime > 10) { - roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper)); + sendPowerdownStatus( false); } } + public void sendPowerdownStatus (boolean bool){ + if(roboRallyWrapper.roboRallyGame.getGameState()== GameState.CHOOSING_STAY_IN_POWER_DOWN){ + roboRallyWrapper.roboRallyGame.setGameState(GameState.TURN_CLEANUP); + roboRallyWrapper.client.sendElement(bool); + } + else if (roboRallyWrapper.roboRallyGame.getGameState()==GameState.CHOOSING_POWER_DOWN){ + + roboRallyWrapper.roboRallyGame.setGameState(GameState.LOADING); + + roboRallyWrapper.client.sendElement(new ProgramAndPowerdownRequest(bool, + roboRallyWrapper.roboRallyGame.getProgram())); + + } + + + roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper)); + + } + @Override public void resize(int width, int height) { viewport.update(width, height); From c552ef028bed6f8f77271080a8eb5e26b80e8299 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 14:59:20 +0200 Subject: [PATCH 13/19] la til flere cases og endret hvilket screens som blir vist --- .../gamewrapper/screens/LoadingScreen.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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 0c9f506..447d061 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/LoadingScreen.java @@ -43,19 +43,26 @@ public class LoadingScreen extends AbstractScreen { roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Loading...", applicationWidth/2f-380/2f, applicationHeight / 2f,380, 1, true); roboRallyWrapper.batch.end(); - long time = System.currentTimeMillis(); - //TODO: Allow to set any condition and next screen - if (roboRallyWrapper.roboRallyGame != null && roboRallyWrapper.roboRallyGame.getGameState() != initialGameState) { + + //if (roboRallyWrapper.roboRallyGame != null){ + // System.out.println(roboRallyWrapper.roboRallyGame.getGameState()); + //} + if (roboRallyWrapper.roboRallyGame != null && roboRallyWrapper.roboRallyGame.getGameState() != GameState.LOADING) { handleScreenChange(); } } private void handleScreenChange() { - switch (initialGameState) { - case SENDING_CARDS: + switch (roboRallyWrapper.roboRallyGame.getGameState()) { + case RUNNING_PROGRAMS: roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getBoardActiveScreen(this.roboRallyWrapper)); break; - } + case INITIAL_SETUP: + roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getLoadingScreen(this.roboRallyWrapper)); + break; + case CHOOSING_CARDS: + roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getCardChoiceScreen(this.roboRallyWrapper)); + break; } } @Override From 7a14526e8e8ccb32dfe12fbf838fa64d1fb4e8fb Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 15:00:10 +0200 Subject: [PATCH 14/19] =?UTF-8?q?la=20til=20begrensninger=20p=C3=A5=20hvor?= =?UTF-8?q?=20mange=20kort=20som=20blir=20tildelt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gamewrapper/screens/CardChoiceScreen.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/CardChoiceScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/CardChoiceScreen.java index 06081a5..949472c 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/CardChoiceScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/CardChoiceScreen.java @@ -15,6 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.Viewport; +import inf112.fiasko.roborally.elementproperties.GameState; import inf112.fiasko.roborally.gamewrapper.RoboRallyWrapper; import inf112.fiasko.roborally.gamewrapper.SimpleButton; import inf112.fiasko.roborally.objects.IDeck; @@ -51,8 +52,8 @@ public class CardChoiceScreen extends InputAdapter implements Screen { * Instantiates a new card choice screen * @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen */ - public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper, ProgrammingCardDeck deck) { - this.deck = deck; + public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) { + this.deck = roboRallyWrapper.roboRallyGame.getPlayerHand(); this.roboRallyWrapper = roboRallyWrapper; camera = new OrthographicCamera(); int applicationWidth = 600; @@ -66,12 +67,13 @@ public class CardChoiceScreen extends InputAdapter implements Screen { inputMultiplexer = new InputMultiplexer(); try { - generateCards(); + generateCards(deck); } catch (IOException e) { e.printStackTrace(); } this.chosenCards = new ArrayList<>(); - this.maxCards = 5; + + this.maxCards = roboRallyWrapper.roboRallyGame.getProgramSize(); stage = new Stage(); TextButton confirmCards = new SimpleButton("Confirm cards", roboRallyWrapper.font).getButton(); @@ -83,7 +85,10 @@ public class CardChoiceScreen extends InputAdapter implements Screen { @Override public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { if (chosenCards.size() == maxCards) { - System.out.println("Lock cards!"); + + roboRallyWrapper.roboRallyGame.setProgram(getCards()); + roboRallyWrapper.roboRallyGame.setGameState(GameState.CHOOSING_POWER_DOWN); + roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper)); return true; } return false; @@ -93,16 +98,19 @@ public class CardChoiceScreen extends InputAdapter implements Screen { inputMultiplexer.addProcessor(this); inputMultiplexer.addProcessor(stage); } + private List getCards(){ + List program = new ArrayList<>(); + chosenCards.forEach((cardRectangle -> program.add(cardRectangle.card))); + return program; + } /** * Generates some placeholder cards for testing * @throws IOException If programming cards cannot be loaded */ - private void generateCards() throws IOException { - IDeck deck = DeckLoaderUtil.loadProgrammingCardsDeck(); - deck.shuffle(); + private void generateCards(ProgrammingCardDeck deck) throws IOException { //Get 9 programming cards - List cardList = deck.getCards().subList(0, 9); + List cardList = deck.getCards(); float cardWidth = viewport.getWorldWidth() / 3; float cardHeight = (viewport.getWorldHeight() - 30) / 3; for (int i = 0; i < 9; i++) { From 5d5b221de4c6b5bdf0f62e52d4e9cc863a1bd9a3 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 15:01:35 +0200 Subject: [PATCH 15/19] =?UTF-8?q?endret=20hvilket=20screen=20den=20g=C3=A5?= =?UTF-8?q?r=20til?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roborally/gamewrapper/screens/BoardActiveScreen.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java index 70671b8..0f846d0 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java @@ -80,6 +80,9 @@ public class BoardActiveScreen extends AbstractScreen implements InputProcessor if (roboRallyWrapper.roboRallyGame.getGameState() == GameState.GAME_IS_WON) { roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getWinnerScreen(roboRallyWrapper)); } + else if (roboRallyWrapper.roboRallyGame.getGameState() == GameState.CHOOSING_STAY_IN_POWER_DOWN){ + roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getPowerDownScreen(roboRallyWrapper)); + } } @Override From 62f492490c9786625eadfed65fcae6e5485240fa Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 15:03:04 +0200 Subject: [PATCH 16/19] la til flere enums --- .../fiasko/roborally/elementproperties/GameState.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java b/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java index 3a091f6..ef0ab07 100644 --- a/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java +++ b/src/main/java/inf112/fiasko/roborally/elementproperties/GameState.java @@ -22,5 +22,10 @@ public enum GameState { //Indicates that the user is in the process of sending their cards to the server SENDING_CARDS, //Indicates that the game is won by a player - GAME_IS_WON + GAME_IS_WON, + + JUST_BEFORE_CHOOSING_CARDS, + + LOADING + } From 0d68f3a8f792ddd276d2d89c0209f71ec0a0de75 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 15:03:56 +0200 Subject: [PATCH 17/19] =?UTF-8?q?lagde=20en=20klasse=20som=20sender=20blir?= =?UTF-8?q?=20brukt=20til=20=C3=A5=20sende=20information=20til=20serveren?= =?UTF-8?q?=20om=20programmet=20til=20alle=20spillerene=20og=20dere=20powe?= =?UTF-8?q?rdown=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProgramAndPowerdownRequest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java new file mode 100644 index 0000000..28b66b0 --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgramAndPowerdownRequest.java @@ -0,0 +1,24 @@ +package inf112.fiasko.roborally.networking.containers; + +import inf112.fiasko.roborally.objects.ProgrammingCard; + +import java.util.List; + +public class ProgramAndPowerdownRequest { + private Boolean powerdown; + private List program; + + public ProgramAndPowerdownRequest(){} + public ProgramAndPowerdownRequest(Boolean powerdown, List program) { + this.program=program; + this.powerdown = powerdown; + } + + public List getProgram() { + return program; + } + + public Boolean getPowerdown() { + return powerdown; + } +} From 3cac5d204da789c557a8786fc862281ef87b2dc6 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 15:05:23 +0200 Subject: [PATCH 18/19] lagde en classe som inneholder information om programmet til spilleren som blir sendt til serveren --- .../containers/ProgamsContainer.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java new file mode 100644 index 0000000..610a205 --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/networking/containers/ProgamsContainer.java @@ -0,0 +1,24 @@ +package inf112.fiasko.roborally.networking.containers; + +import inf112.fiasko.roborally.objects.ProgrammingCard; + +import java.util.List; +import java.util.Map; + +public class ProgamsContainer { + private Map> program; + private Map powerdown; + + public ProgamsContainer(){} + public ProgamsContainer(Map> program, Map powerdown) { + this.program = program; + this.powerdown = powerdown; + } + + public Map> getProgram() { + return program; + } + public Map getPowerdown() { + return powerdown; + } +} From 581e048646dc4735176d6bbbb6b4fe22d0cb3180 Mon Sep 17 00:00:00 2001 From: Tobydrama Date: Thu, 16 Apr 2020 15:05:57 +0200 Subject: [PATCH 19/19] lagde en classe som ineholder information om powerdown statusen til spilleren som blir sendt til serveren --- .../networking/containers/PowerdownContainer.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/inf112/fiasko/roborally/networking/containers/PowerdownContainer.java diff --git a/src/main/java/inf112/fiasko/roborally/networking/containers/PowerdownContainer.java b/src/main/java/inf112/fiasko/roborally/networking/containers/PowerdownContainer.java new file mode 100644 index 0000000..2b0413b --- /dev/null +++ b/src/main/java/inf112/fiasko/roborally/networking/containers/PowerdownContainer.java @@ -0,0 +1,15 @@ +package inf112.fiasko.roborally.networking.containers; + +import java.util.Map; + +public class PowerdownContainer { + private Map powerdown; + + public PowerdownContainer(Map powerdown) { + this.powerdown = powerdown; + } + + public Map getPowerdown() { + return powerdown; + } +}