From adc3dd5e2c504cca081a207648c2421cebf8eee2 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 5 May 2020 20:04:08 +0200 Subject: [PATCH] Rydder opp i koden og forbedrer visning av noen feilmeldinger --- .../fiasko/roborally/objects/RoboRallyGame.java | 10 +++++----- .../fiasko/roborally/ui/RoboRallyWrapper.java | 13 +++++++------ .../roborally/ui/screens/CardChoiceScreen.java | 2 +- .../roborally/ui/screens/IPAddressScreen.java | 3 ++- .../fiasko/roborally/ui/screens/UsernameScreen.java | 2 +- .../fiasko/roborally/utility/DeckLoaderUtil.java | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 463b34d..0ef18da 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -25,6 +25,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { private final boolean host; private final String playerName; private final RoboRallyServer server; + private final Boolean testingMode; private Phase phase; private Board gameBoard; private List> repairTiles; @@ -34,15 +35,14 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { private List program; private ProgrammingCardDeck playerHand; private ProgrammingCardDeck extraCards; - private final Boolean testingMode; /** * Instantiates a new Robo Rally game * - * @param playerList A list of all the players participating in the game - * @param boardName The playerName of the board to use - * @param playerName The name of the player of this instance of the game - * @param server The server if this player is host. Should be null otherwise + * @param playerList A list of all the players participating in the game + * @param boardName The playerName of the board to use + * @param playerName The name of the player of this instance of the game + * @param server The server if this player is host. Should be null otherwise * @param testingMode Whether the game should use the test deck rather than the proper deck */ public RoboRallyGame(List playerList, String boardName, String playerName, diff --git a/src/main/java/inf112/fiasko/roborally/ui/RoboRallyWrapper.java b/src/main/java/inf112/fiasko/roborally/ui/RoboRallyWrapper.java index eb83a6e..82cdef7 100644 --- a/src/main/java/inf112/fiasko/roborally/ui/RoboRallyWrapper.java +++ b/src/main/java/inf112/fiasko/roborally/ui/RoboRallyWrapper.java @@ -4,10 +4,12 @@ import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.utils.Disposable; import inf112.fiasko.roborally.networking.RoboRallyClient; import inf112.fiasko.roborally.networking.RoboRallyServer; import inf112.fiasko.roborally.objects.InteractableGame; import inf112.fiasko.roborally.objects.RoboRallyGame; +import inf112.fiasko.roborally.utility.TextureConverterUtil; /** * This class acts as a wrapper around the different screens of the game @@ -35,6 +37,9 @@ public class RoboRallyWrapper extends Game implements RoboRallyUI { public void dispose() { batch.dispose(); font.dispose(); + for (Disposable disposable : TextureConverterUtil.getDisposableElements()) { + disposable.dispose(); + } } @Override @@ -47,14 +52,10 @@ public class RoboRallyWrapper extends Game implements RoboRallyUI { this.roboRallyGame = game; } - /** - * Quits the game after logging the input as an error - * - * @param string The error causing the game to quit - */ + @Override public void quit(String string) { Gdx.app.error("Critical", string); - Gdx.app.exit(); + quit(); } @Override 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 da42f69..aeed900 100644 --- a/src/main/java/inf112/fiasko/roborally/ui/screens/CardChoiceScreen.java +++ b/src/main/java/inf112/fiasko/roborally/ui/screens/CardChoiceScreen.java @@ -39,8 +39,8 @@ public class CardChoiceScreen extends InteractiveScreen { private final ShapeRenderer shapeRenderer; private final List chosenCards; private final int maxCards; - private long timerStarted; private final InteractableGame game; + private long timerStarted; /** * Instantiates a new card choice screen diff --git a/src/main/java/inf112/fiasko/roborally/ui/screens/IPAddressScreen.java b/src/main/java/inf112/fiasko/roborally/ui/screens/IPAddressScreen.java index e348bfe..a4ed368 100644 --- a/src/main/java/inf112/fiasko/roborally/ui/screens/IPAddressScreen.java +++ b/src/main/java/inf112/fiasko/roborally/ui/screens/IPAddressScreen.java @@ -77,7 +77,8 @@ public class IPAddressScreen extends AbstractScreen { roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper)); } catch (IOException | NumberFormatException ex) { JOptionPane.showMessageDialog(null, "Could not connect to the server." - + " Please make sure the ip address you typed is correct, and that the server is online."); + + " Please make sure the ip address you typed is correct, and that the server is online.", + "Error", JOptionPane.ERROR_MESSAGE); } } }); diff --git a/src/main/java/inf112/fiasko/roborally/ui/screens/UsernameScreen.java b/src/main/java/inf112/fiasko/roborally/ui/screens/UsernameScreen.java index fa70b67..f0bf907 100644 --- a/src/main/java/inf112/fiasko/roborally/ui/screens/UsernameScreen.java +++ b/src/main/java/inf112/fiasko/roborally/ui/screens/UsernameScreen.java @@ -42,7 +42,7 @@ public class UsernameScreen extends AbstractScreen { public void touchUp(InputEvent e, float x, float y, int point, int button) { if (nameInvalid(textInput.getText())) { JOptionPane.showMessageDialog(null, "Username must be unique, not " + - "empty and less than 21 characters."); + "empty and less than 21 characters.", "Error", JOptionPane.ERROR_MESSAGE); return; } if (roboRallyWrapper.server == null) { diff --git a/src/main/java/inf112/fiasko/roborally/utility/DeckLoaderUtil.java b/src/main/java/inf112/fiasko/roborally/utility/DeckLoaderUtil.java index c291057..5b0e363 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/DeckLoaderUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/DeckLoaderUtil.java @@ -39,7 +39,7 @@ public final class DeckLoaderUtil { * Loads programming cards from a file * * @param cardFile The file containing the cards to load - * @return A deck of programming cards + * @return A deck of programming cards * @throws IOException If the programming cards file is invalid */ private static ProgrammingCardDeck loadProgrammingCardsDeck(String cardFile) throws IOException {