Skip to content

Commit 8b650f8

Browse files
authored
Merge pull request RobertoIA#16 from BaeGayeon/dev
feat: Add restart function
2 parents 69bdcd1 + d9a06fc commit 8b650f8

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/engine/DrawManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,19 @@ public void drawMenu(final Screen screen, final int option) {
345345
*/
346346
public void drawPause(final Screen screen, final int option) {
347347
String goMenuString = "Go to Menu";
348-
String restartString = "Go to Restart";
348+
String restartString = "Restart";
349349

350-
if (option == 1)
350+
if (option == 7)
351351
backBufferGraphics.setColor(Color.GREEN);
352352
else
353353
backBufferGraphics.setColor(Color.WHITE);
354-
drawCenteredRegularString(screen, goMenuString,
354+
drawCenteredRegularString(screen, restartString,
355355
screen.getHeight() / 3 * 2);
356-
if (option == 7)
356+
if (option == 1)
357357
backBufferGraphics.setColor(Color.GREEN);
358358
else
359359
backBufferGraphics.setColor(Color.WHITE);
360-
drawCenteredRegularString(screen, restartString, screen.getHeight()
360+
drawCenteredRegularString(screen, goMenuString, screen.getHeight()
361361
/ 3 * 2 + fontRegularMetrics.getHeight() * 2);
362362
}
363363

src/screen/GameScreen.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public class GameScreen extends Screen {
3737
private static final int SCREEN_CHANGE_INTERVAL = 1500;
3838
/** Height of the interface separation line. */
3939
private static final int SEPARATION_LINE_HEIGHT = 40;
40+
/** Difficulty settings for level 1. */
41+
private static final GameSettings RESTART_SETTING =
42+
new GameSettings(5, 4, 60, 2000);
4043

4144
/** Current game difficulty settings. */
4245
private GameSettings gameSettings;
@@ -72,7 +75,7 @@ public class GameScreen extends Screen {
7275
private boolean bonusLife;
7376
/** Pause Screen */
7477
private Screen pausescreen;
75-
78+
/** Title Screen */
7679
private Screen titlescreen;
7780
/** Check if game is pause */
7881
private boolean isPause;
@@ -304,15 +307,26 @@ private void draw() {
304307

305308
if (this.returnCode == 1) {
306309
return;
307-
308310
}
309-
310-
if (this.inputManager.isKeyDown(KeyEvent.VK_ESCAPE)){
311+
312+
else if (this.returnCode == 7) {
313+
this.level = 1;
314+
this.score = 0;
315+
this.lives = 3;
316+
this.bulletsShot = 0;
317+
this.shipsDestroyed = 0;
318+
this.gameSettings = RESTART_SETTING;
319+
initialize();
320+
this.logger.info("Restart");
321+
this.isPause = false;
322+
this.returnCode = 2;
323+
}
324+
325+
if (this.inputManager.isKeyDown(KeyEvent.VK_ESCAPE)){
311326
if (this.escCooldown.checkFinished()){
312327
this.escCooldown.reset();
313328
this.isPause = false;
314329
this.returnCode = 2;
315-
// System.out.println("Asdfasfd");
316330
}
317331
}
318332

src/screen/PauseScreen.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class PauseScreen extends Screen {
2525
*/
2626
public PauseScreen(final int width, final int height, final int fps) {
2727
super(width, height, fps);
28-
this.returnCode = 1;
28+
this.returnCode = 7;
2929
this.selectionCooldown = Core.getCooldown(SELECTION_TIME);
3030
this.selectionCooldown.reset();
3131
}
@@ -78,8 +78,8 @@ protected final void update() {
7878
}
7979

8080
private void nextMenuItem() {
81-
if (this.returnCode == 1) {
82-
this.returnCode = 7;
81+
if (this.returnCode == 7) {
82+
this.returnCode = 1;
8383
}
8484

8585
}
@@ -88,8 +88,8 @@ private void nextMenuItem() {
8888
* Shifts the focus to the previous menu item.
8989
*/
9090
private void previousMenuItem() {
91-
if (this.returnCode == 7) {
92-
this.returnCode = 1;
91+
if (this.returnCode == 1) {
92+
this.returnCode = 7;
9393
}
9494

9595
}

0 commit comments

Comments
 (0)