Forbedring av kodekvalitet og flere kommentarer

This commit is contained in:
Kristian Knarvik 2020-04-07 15:13:33 +02:00
parent 9fa8f04ef7
commit 0c8b9f47d9

View File

@ -16,22 +16,25 @@ 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);
@ -48,12 +51,14 @@ 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);
@ -63,11 +68,11 @@ public class StartMenuScreen extends AbstractScreen {
@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());
@ -77,7 +82,7 @@ public class StartMenuScreen extends AbstractScreen {
@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();
}