From 0c8b9f47d92373ca022699b984439550c3e4adb0 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 7 Apr 2020 15:13:33 +0200 Subject: [PATCH] Forbedring av kodekvalitet og flere kommentarer --- .../game_wrapper/screens/StartMenuScreen.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/game_wrapper/screens/StartMenuScreen.java b/src/main/java/inf112/fiasko/roborally/game_wrapper/screens/StartMenuScreen.java index 1862adf..6fbd292 100644 --- a/src/main/java/inf112/fiasko/roborally/game_wrapper/screens/StartMenuScreen.java +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/screens/StartMenuScreen.java @@ -16,25 +16,28 @@ import inf112.fiasko.roborally.networking.RoboRallyServer; import java.io.IOException; +/** + * This screen is the first screen shown to a player + */ public class StartMenuScreen extends AbstractScreen { private final RoboRallyWrapper roboRallyWrapper; private final OrthographicCamera camera; private final Viewport viewport; private final Stage stage; - private final int applicationWidth = 600; - private final int applicationHeight = 800; - private TextButton serverButton; - private TextButton clientButton; - private TextButton quitButton; + + /** + * Instantiates a new start menu screen + * @param roboRallyWrapper The Robo Rally wrapper which is parent of this screen + */ public StartMenuScreen(final RoboRallyWrapper roboRallyWrapper) { camera = new OrthographicCamera(); viewport = new FitViewport(applicationWidth, applicationHeight, camera); stage = new Stage(); - serverButton = new SimpleButton("Create", roboRallyWrapper.font).getButton(); + TextButton serverButton = new SimpleButton("Create", roboRallyWrapper.font).getButton(); stage.addActor(serverButton); - serverButton.setY(applicationHeight/2f); - serverButton.setX(applicationWidth/2f); + serverButton.setY(applicationHeight / 2f); + serverButton.setX(applicationWidth / 2f); this.roboRallyWrapper = roboRallyWrapper; camera.setToOrtho(false, applicationWidth, applicationHeight); Gdx.input.setInputProcessor(stage); @@ -48,36 +51,38 @@ public class StartMenuScreen extends AbstractScreen { roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getUsernameScreen(roboRallyWrapper)); } catch (IOException e) { e.printStackTrace(); + //Hard fail + System.exit(1); } - return true; // Here do stuff + return true; } }); - clientButton = new SimpleButton("Join", roboRallyWrapper.font).getButton(); + TextButton clientButton = new SimpleButton("Join", roboRallyWrapper.font).getButton(); stage.addActor(clientButton); - clientButton.setY(applicationHeight/2f); - clientButton.setX(applicationWidth/2f+serverButton.getWidth()+20); + clientButton.setY(applicationHeight / 2f); + clientButton.setX(applicationWidth / 2f + serverButton.getWidth() + 20); camera.setToOrtho(false, applicationWidth, applicationHeight); Gdx.input.setInputProcessor(stage); clientButton.addListener(new InputListener() { @Override public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { roboRallyWrapper.setScreen(roboRallyWrapper.screenManager.getIPAddressScreen(roboRallyWrapper)); - return true;// Here we do stuff + return true; } }); - quitButton = new SimpleButton("Quit", roboRallyWrapper.font).getButton(); + TextButton quitButton = new SimpleButton("Quit", roboRallyWrapper.font).getButton(); stage.addActor(quitButton); - quitButton.setY(applicationHeight/2f); - quitButton.setX(applicationWidth/2f+serverButton.getWidth()+40+clientButton.getWidth()); + quitButton.setY(applicationHeight / 2f); + quitButton.setX(applicationWidth / 2f + serverButton.getWidth() + 40 + clientButton.getWidth()); camera.setToOrtho(false, applicationWidth, applicationHeight); Gdx.input.setInputProcessor(stage); quitButton.addListener(new InputListener() { @Override public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { System.exit(0); - return true;//her we do stuff + return true; } }); } @@ -91,7 +96,8 @@ public class StartMenuScreen extends AbstractScreen { roboRallyWrapper.batch.begin(); roboRallyWrapper.font.draw(roboRallyWrapper.batch, "RoboRally", - applicationWidth/2f-380/2f,applicationHeight/2f +100,380, 1, true); + applicationWidth / 2f - 380 / 2f,applicationHeight / 2f + 100,380, 1, + true); roboRallyWrapper.batch.end(); stage.draw(); }