Skip to content

Commit a3c800a

Browse files
committed
feat : Add GameScreen and Core file interworking
INVADER-75
1 parent eebe731 commit a3c800a

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/engine/Core.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ public static void main(final String[] args) {
141141
bonusLife, width, height, FPS);
142142
LOGGER.info("Starting " + WIDTH + "x" + HEIGHT
143143
+ " game screen at " + FPS + " fps.");
144-
frame.setScreen(currentScreen);
144+
returnCode = frame.setScreen(currentScreen);
145+
145146
LOGGER.info("Closing game screen.");
146-
147+
if(returnCode != 1) break;
147148
gameState = ((GameScreen) currentScreen).getGameState();
148149

149150
gameState = new GameState(gameState.getLevel() + 1,
@@ -161,16 +162,18 @@ public static void main(final String[] args) {
161162
+ gameState.getLivesRemaining() + " lives remaining, "
162163
+ gameState.getBulletsShot() + " bullets shot and "
163164
+ gameState.getShipsDestroyed() + " ships destroyed.");
164-
currentScreen = new ScoreScreen(width, height, FPS, gameState);
165-
returnCode = frame.setScreen(currentScreen);
166-
LOGGER.info("Closing score screen.");
165+
if(returnCode == 2) {
166+
currentScreen = new ScoreScreen(width, height, FPS, gameState);
167+
returnCode = frame.setScreen(currentScreen);
168+
LOGGER.info("Closing score screen.");
169+
}
167170
break;
168171
case 3:
169172
// High scores.
170173
currentScreen = new HighScoreScreen(width, height, FPS);
171174
LOGGER.info("Starting " + WIDTH + "x" + HEIGHT
172175
+ " high score screen at " + FPS + " fps.");
173-
returnCode = frame.setScreen(currentScreen);
176+
returnCode = frame.setScreen(currentScreen);
174177
LOGGER.info("Closing high score screen.");
175178
break;
176179
case 4:
@@ -188,7 +191,7 @@ public static void main(final String[] args) {
188191
LOGGER.info("Starting " + WIDTH + "x" + HEIGHT
189192
+ " Audio screen at " + FPS + " fps.");
190193
returnCode = frame.setScreen(currentScreen);
191-
LOGGER.info("Closing Audio screen.");
194+
LOGGER.info("Closing Audio screen.");
192195
break;
193196
case 6:
194197
// Video Setting? fps? something

src/screen/GameScreen.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public class GameScreen extends Screen {
7272
private boolean bonusLife;
7373
/** Pause Screen */
7474
private Screen pausescreen;
75+
76+
private Screen titlescreen;
7577
/** Check if game is pause */
7678
private boolean isPause;
7779
/** Check ESC Cooldown */
@@ -146,7 +148,7 @@ public final int run() {
146148

147149
this.score += LIFE_SCORE * (this.lives - 1);
148150
this.logger.info("Screen cleared with a score of " + this.score);
149-
151+
150152
return this.returnCode;
151153
}
152154

@@ -228,7 +230,17 @@ else if (this.enemyShipSpecialExplosionCooldown.checkFinished())
228230

229231
if (this.levelFinished && this.screenFinishedCooldown.checkFinished())
230232
this.isRunning = false;
233+
234+
if (this.returnCode == 1) {
235+
this.isPause = false;
236+
237+
this.titlescreen = new screen.TitleScreen(this.width, this.height, this.fps);
238+
returnCode = titlescreen.run();
231239

240+
this.levelFinished = true;
241+
this.screenFinishedCooldown.reset();
242+
this.isRunning = false;
243+
}
232244
}
233245

234246
/**

0 commit comments

Comments
 (0)