make the game show score after death, popup at 40 to ask to continue

This commit is contained in:
ThatGamerBlue
2022-06-23 17:47:59 +01:00
parent b408ee7a7a
commit 21c2ab36e9
2 changed files with 16 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener; import java.awt.event.KeyListener;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.swing.JOptionPane;
public class GameHandler implements KeyListener { public class GameHandler implements KeyListener {
private static final int DEFAULT_REFRESH_INTERVAL = 100; private static final int DEFAULT_REFRESH_INTERVAL = 100;
@@ -37,6 +38,9 @@ public class GameHandler implements KeyListener {
} }
public void reset() { public void reset() {
if (score != 0) {
JOptionPane.showMessageDialog(null, "You died! Your score: " + score, "OpenOSRS Snake", JOptionPane.INFORMATION_MESSAGE);
}
head = new SnakePart(); head = new SnakePart();
SnakePart current = head; SnakePart current = head;
current.x = MIDDLE_X; current.x = MIDDLE_X;

View File

@@ -5,6 +5,7 @@ import java.awt.Component;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Image; import java.awt.Image;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import net.runelite.client.RuneLite; import net.runelite.client.RuneLite;
@@ -30,6 +31,10 @@ public class SnakeGame {
} }
public void stop() throws Exception { public void stop() throws Exception {
int option = JOptionPane.showConfirmDialog(null,
"You scored 40! Press Yes to launch OpenOSRS, press No to keep playing snake.",
"OpenOSRS Snake", JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.YES_OPTION) {
running = false; running = false;
Component c = component; Component c = component;
while (c != null) { while (c != null) {
@@ -38,6 +43,7 @@ public class SnakeGame {
} }
RuneLite.oldMain(arguments); RuneLite.oldMain(arguments);
} }
}
@SneakyThrows @SneakyThrows
private void runGameLoop() { private void runGameLoop() {