Flytter ansvar for å avslutte spillet over til RoboRallyWrapper

This commit is contained in:
Kristian Knarvik 2020-04-18 10:44:09 +02:00
parent 944f9cd55c
commit 1ec0b1c843
2 changed files with 23 additions and 3 deletions

View File

@ -8,6 +8,9 @@ import inf112.fiasko.roborally.networking.RoboRallyClient;
import inf112.fiasko.roborally.networking.RoboRallyServer;
import inf112.fiasko.roborally.objects.IRoboRallyGame;
/**
* This class acts as a wrapper around the different screens of the game
*/
public class RoboRallyWrapper extends Game {
public SpriteBatch batch;
public BitmapFont font;
@ -24,7 +27,25 @@ public class RoboRallyWrapper extends Game {
this.setScreen(screenManager.getStartMenuScreen(this));
}
@Override
public void dispose() {
batch.dispose();
font.dispose();
}
/**
* Quits the game after logging the input as an error
* @param string The error causing the game to quit
*/
public void quit(String string) {
Gdx.app.error("Critical", string);
Gdx.app.exit();
}
/**
* Quits the game
*/
public void quit() {
Gdx.app.exit();
}
}

View File

@ -50,8 +50,7 @@ public class StartMenuScreen extends AbstractScreen {
} catch (IOException e) {
e.printStackTrace();
//Hard fail
Gdx.app.error("Server error", "Server could not be started");
Gdx.app.exit();
roboRallyWrapper.quit("Server could not be started");
}
return true;
}
@ -77,7 +76,7 @@ public class StartMenuScreen extends AbstractScreen {
quitButton.addListener(new InputListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.exit();
roboRallyWrapper.quit();
return true;
}
});