From b408ee7a7ab3e54422e3bf3d9f484e1ec4c56689 Mon Sep 17 00:00:00 2001 From: ThatGamerBlue Date: Thu, 23 Jun 2022 15:15:15 +0100 Subject: [PATCH] if you score 40 you get to play --- .../com/thatgamerblue/snake/GameHandler.java | 11 ++++++++- .../com/thatgamerblue/snake/SnakeGame.java | 24 +++++++++++++++---- .../java/net/runelite/client/RuneLite.java | 6 ++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/runelite-client/src/main/java/com/thatgamerblue/snake/GameHandler.java b/runelite-client/src/main/java/com/thatgamerblue/snake/GameHandler.java index e2b136db58..597830431c 100644 --- a/runelite-client/src/main/java/com/thatgamerblue/snake/GameHandler.java +++ b/runelite-client/src/main/java/com/thatgamerblue/snake/GameHandler.java @@ -30,6 +30,12 @@ public class GameHandler implements KeyListener { private SnakePart apple = new SnakePart(); private int score; + private SnakeGame game; + + public GameHandler(SnakeGame game) { + this.game = game; + } + public void reset() { head = new SnakePart(); SnakePart current = head; @@ -50,7 +56,7 @@ public class GameHandler implements KeyListener { SnakeGame.currentRefreshInterval = DEFAULT_REFRESH_INTERVAL; } - public void update() { + public void update() throws Exception { processInput(); direction = pendingDirection; SnakePart newHead = new SnakePart(); @@ -65,6 +71,9 @@ public class GameHandler implements KeyListener { ateApple = true; score++; SnakeGame.currentRefreshInterval = Math.max(50, DEFAULT_REFRESH_INTERVAL - score); + if (score == 40) { + game.stop(); + } } if (!ateApple) { diff --git a/runelite-client/src/main/java/com/thatgamerblue/snake/SnakeGame.java b/runelite-client/src/main/java/com/thatgamerblue/snake/SnakeGame.java index 1a362364ee..0ff49333ef 100644 --- a/runelite-client/src/main/java/com/thatgamerblue/snake/SnakeGame.java +++ b/runelite-client/src/main/java/com/thatgamerblue/snake/SnakeGame.java @@ -6,8 +6,11 @@ import java.awt.Graphics; import java.awt.Image; import javax.swing.JFrame; import javax.swing.JPanel; +import lombok.SneakyThrows; +import net.runelite.client.RuneLite; public class SnakeGame { + public static String[] arguments; public static final int FRAME_WIDTH = 800; public static final int FRAME_HEIGHT = 608; public static long currentRefreshInterval = 100; @@ -15,6 +18,7 @@ public class SnakeGame { private final Object redrawLock = new Object(); private Component component; private Image imageBuffer; + private boolean running = true; public void start(Component component) { this.component = component; @@ -25,9 +29,20 @@ public class SnakeGame { thread.start(); } + public void stop() throws Exception { + running = false; + Component c = component; + while (c != null) { + c.setVisible(false); + c = c.getParent(); + } + RuneLite.oldMain(arguments); + } + + @SneakyThrows private void runGameLoop() { // update the game repeatedly - while (true) { + while (running) { long durationMs = redraw(); try { Thread.sleep(Math.max(0, currentRefreshInterval - durationMs)); @@ -36,7 +51,7 @@ public class SnakeGame { } } - private long redraw() { + private long redraw() throws Exception { long t = System.currentTimeMillis(); @@ -62,7 +77,7 @@ public class SnakeGame { return System.currentTimeMillis() - t; } - private void updateModel() { + private void updateModel() throws Exception { gameHandler.update(); } @@ -115,11 +130,12 @@ public class SnakeGame { } public static void main(String[] args) { + arguments = args; java.awt.EventQueue.invokeLater(() -> { SnakeGame game = new SnakeGame(); SnakeComponent component = new SnakeComponent(game); - gameHandler = new GameHandler(); + gameHandler = new GameHandler(game); component.setPreferredSize(new java.awt.Dimension(FRAME_WIDTH, FRAME_HEIGHT)); JFrame frame = new JFrame(); diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLite.java b/runelite-client/src/main/java/net/runelite/client/RuneLite.java index 4343ca71ef..6892d5bd13 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLite.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLite.java @@ -185,7 +185,7 @@ public class RuneLite if (!ArrayUtils.contains(args, BYPASS_ARG)) { JOptionPane.showMessageDialog(null, - String.format("If you want to actually use the client despite the risks add\n%s\nto your launch arguments", + String.format("If you want to actually use the client despite the risks add\n%s\nto your launch arguments.\n\nOr score 40 and the client opens anyway.\nI'm not your dad.", "unknown".equals(RuneLiteProperties.getLauncherVersion()) ? BYPASS_ARG : ("--clientargs=\"" + BYPASS_ARG + "\"")), "OpenOSRS", JOptionPane.INFORMATION_MESSAGE); @@ -193,13 +193,13 @@ public class RuneLite } else { - String[] newArgs = Arrays.stream(args).filter(s -> !BYPASS_ARG.equals(s)).toArray(String[]::new); - oldMain(newArgs); + oldMain(args); } } public static void oldMain(String[] args) throws Exception { + args = Arrays.stream(args).filter(s -> !BYPASS_ARG.equals(s)).toArray(String[]::new); Locale.setDefault(Locale.ENGLISH); final OptionParser parser = new OptionParser(false);