How would one go about implementing a method in which it calls the game to restart by pressing a button after game over?
I have my game class which puts the player in and starts the enemy sequence shown below. I already have my restart button as shown in the code snippet from the mouseinput class below and the problem is I don't know what to put in the area where the question marks are to get the thread to restart, if I'm using the appropriate language or not I'm not sure. I'm new please bare with me.
Thank you. What I'm doing now isn't working because it's glitching and the fps is shaky.
public Game()
{
new Window(1000, 635, "Galaxy Monkeys", this);
start();
handler = new Handler();
camera = new Camera(0, 0);
this.addKeyListener(new KeyInput(handler));
menu = new Menu(this);
BufferedImageLoader loader = new BufferedImageLoader();
sprite_sheet = loader.loadImage("/spritesheet.png");
Enemy enemy = new Enemy(-20, r.nextInt(563), ID.Enemy, handler, this);
Monkey p = new Monkey(500, 250, ID.Player, handler, this);
handler.addObject(p);
for(int i = 0; i < enemy_count; i++)
{
handler.addObject(enemy);
}
this.addMouseListener(new MouseInput(handler, camera, this));
background = loader.loadImage(("/background.jpg"));
INSTANCE = this;
}
Restart event on MouseInput.java:
public void mousePressed(MouseEvent e)
{
int mx = (int) e.getX();
int my = (int) e.getY();
if(Game.state == STATE.GAMEOVER)
{
if(GameOver.restartButton.contains(mx, my))
{
// Pressed Restart Button
Game.setState(Game.STATE.GAME);
Game.INSTANCE = new Game();
}
}
}