if you score 40 you get to play
This commit is contained in:
@@ -30,6 +30,12 @@ public class GameHandler implements KeyListener {
|
|||||||
private SnakePart apple = new SnakePart();
|
private SnakePart apple = new SnakePart();
|
||||||
private int score;
|
private int score;
|
||||||
|
|
||||||
|
private SnakeGame game;
|
||||||
|
|
||||||
|
public GameHandler(SnakeGame game) {
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
head = new SnakePart();
|
head = new SnakePart();
|
||||||
SnakePart current = head;
|
SnakePart current = head;
|
||||||
@@ -50,7 +56,7 @@ public class GameHandler implements KeyListener {
|
|||||||
SnakeGame.currentRefreshInterval = DEFAULT_REFRESH_INTERVAL;
|
SnakeGame.currentRefreshInterval = DEFAULT_REFRESH_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() throws Exception {
|
||||||
processInput();
|
processInput();
|
||||||
direction = pendingDirection;
|
direction = pendingDirection;
|
||||||
SnakePart newHead = new SnakePart();
|
SnakePart newHead = new SnakePart();
|
||||||
@@ -65,6 +71,9 @@ public class GameHandler implements KeyListener {
|
|||||||
ateApple = true;
|
ateApple = true;
|
||||||
score++;
|
score++;
|
||||||
SnakeGame.currentRefreshInterval = Math.max(50, DEFAULT_REFRESH_INTERVAL - score);
|
SnakeGame.currentRefreshInterval = Math.max(50, DEFAULT_REFRESH_INTERVAL - score);
|
||||||
|
if (score == 40) {
|
||||||
|
game.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ateApple) {
|
if (!ateApple) {
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ import java.awt.Graphics;
|
|||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import net.runelite.client.RuneLite;
|
||||||
|
|
||||||
public class SnakeGame {
|
public class SnakeGame {
|
||||||
|
public static String[] arguments;
|
||||||
public static final int FRAME_WIDTH = 800;
|
public static final int FRAME_WIDTH = 800;
|
||||||
public static final int FRAME_HEIGHT = 608;
|
public static final int FRAME_HEIGHT = 608;
|
||||||
public static long currentRefreshInterval = 100;
|
public static long currentRefreshInterval = 100;
|
||||||
@@ -15,6 +18,7 @@ public class SnakeGame {
|
|||||||
private final Object redrawLock = new Object();
|
private final Object redrawLock = new Object();
|
||||||
private Component component;
|
private Component component;
|
||||||
private Image imageBuffer;
|
private Image imageBuffer;
|
||||||
|
private boolean running = true;
|
||||||
|
|
||||||
public void start(Component component) {
|
public void start(Component component) {
|
||||||
this.component = component;
|
this.component = component;
|
||||||
@@ -25,9 +29,20 @@ public class SnakeGame {
|
|||||||
thread.start();
|
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() {
|
private void runGameLoop() {
|
||||||
// update the game repeatedly
|
// update the game repeatedly
|
||||||
while (true) {
|
while (running) {
|
||||||
long durationMs = redraw();
|
long durationMs = redraw();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(Math.max(0, currentRefreshInterval - durationMs));
|
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();
|
long t = System.currentTimeMillis();
|
||||||
|
|
||||||
@@ -62,7 +77,7 @@ public class SnakeGame {
|
|||||||
return System.currentTimeMillis() - t;
|
return System.currentTimeMillis() - t;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateModel() {
|
private void updateModel() throws Exception {
|
||||||
gameHandler.update();
|
gameHandler.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,11 +130,12 @@ public class SnakeGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
arguments = args;
|
||||||
java.awt.EventQueue.invokeLater(() -> {
|
java.awt.EventQueue.invokeLater(() -> {
|
||||||
SnakeGame game = new SnakeGame();
|
SnakeGame game = new SnakeGame();
|
||||||
SnakeComponent component = new SnakeComponent(game);
|
SnakeComponent component = new SnakeComponent(game);
|
||||||
|
|
||||||
gameHandler = new GameHandler();
|
gameHandler = new GameHandler(game);
|
||||||
|
|
||||||
component.setPreferredSize(new java.awt.Dimension(FRAME_WIDTH, FRAME_HEIGHT));
|
component.setPreferredSize(new java.awt.Dimension(FRAME_WIDTH, FRAME_HEIGHT));
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ public class RuneLite
|
|||||||
if (!ArrayUtils.contains(args, BYPASS_ARG))
|
if (!ArrayUtils.contains(args, BYPASS_ARG))
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(null,
|
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 + "\"")),
|
"unknown".equals(RuneLiteProperties.getLauncherVersion()) ? BYPASS_ARG : ("--clientargs=\"" + BYPASS_ARG + "\"")),
|
||||||
"OpenOSRS",
|
"OpenOSRS",
|
||||||
JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
@@ -193,13 +193,13 @@ public class RuneLite
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String[] newArgs = Arrays.stream(args).filter(s -> !BYPASS_ARG.equals(s)).toArray(String[]::new);
|
oldMain(args);
|
||||||
oldMain(newArgs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void oldMain(String[] args) throws Exception
|
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);
|
Locale.setDefault(Locale.ENGLISH);
|
||||||
|
|
||||||
final OptionParser parser = new OptionParser(false);
|
final OptionParser parser = new OptionParser(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user