Show different death messages for different deaths (closes #17)

This commit is contained in:
Lonami Exo 2017-03-10 20:33:08 +01:00
parent 759f787cd0
commit 0506898bb5
5 changed files with 19 additions and 11 deletions

View file

@ -72,8 +72,9 @@ public class Band extends Actor {
}
// Once game over is set on the menu, it cannot be reverted
public void setGameOver() {
infoLabel.setText("no moves left");
public void setMessage(final String message) {
if (!message.equals(""))
infoLabel.setText(message);
}
//endregion

View file

@ -92,6 +92,8 @@ public abstract class BaseScorer implements BinSerializable {
abstract public boolean isGameOver();
abstract protected boolean isNewRecord();
public String gameOverReason() { return ""; }
abstract public void saveScore();
public void draw(SpriteBatch batch) {

View file

@ -96,6 +96,9 @@ public class TimeScorer extends BaseScorer implements BinSerializable {
return TimeUtils.nanoTime() > deadTime;
}
@Override
public String gameOverReason() { return "time is up"; }
@Override
public void saveScore() {
if (isNewRecord()) {

View file

@ -121,12 +121,12 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
return true;
}
private void doGameOver() {
private void doGameOver(String gameOverReason) {
if (!gameOverDone) {
gameOverDone = true;
holder.enabled = false;
pauseMenu.show(true);
pauseMenu.showGameOver(gameOverReason);
if (Klooni.soundsEnabled())
gameOverSound.play();
@ -157,7 +157,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
Klooni.addMoneyFromScore(newMoneyScore);
// Show the pause menu
pauseMenu.show(false);
pauseMenu.show();
save();
}
@ -172,7 +172,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (scorer.isGameOver() && !pauseMenu.isShown()) {
doGameOver();
doGameOver(scorer.gameOverReason());
}
batch.begin();
@ -227,7 +227,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
// After the piece was put, check if it's game over
if (isGameOver()) {
doGameOver();
doGameOver("no moves left");
}
}
return true;

View file

@ -128,7 +128,7 @@ class PauseMenuStage extends Stage {
//region Package local methods
// Shows the pause menu, indicating whether it's game over or not
void show(final boolean gameOver) {
void show() {
scorer.pause();
scorer.saveScore();
@ -138,13 +138,15 @@ class PauseMenuStage extends Stage {
shown = true;
hiding = false;
if (gameOver)
band.setGameOver();
addAction(Actions.moveTo(0, Gdx.graphics.getHeight()));
addAction(Actions.moveTo(0, 0, 0.75f, Interpolation.swingOut));
}
void showGameOver(final String gameOverReason) {
band.setMessage(gameOverReason);
show();
}
boolean isShown() {
return shown;
}