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 // Once game over is set on the menu, it cannot be reverted
public void setGameOver() { public void setMessage(final String message) {
infoLabel.setText("no moves left"); if (!message.equals(""))
infoLabel.setText(message);
} }
//endregion //endregion

View file

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

View file

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

View file

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

View file

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