diff --git a/src/ThreadsController.java b/src/ThreadsController.java index 3df2d3d..1937460 100644 --- a/src/ThreadsController.java +++ b/src/ThreadsController.java @@ -1,11 +1,13 @@ import java.util.ArrayList; +import javax.swing.JFrame; + //Controls all the game logic .. most important class in this project. public class ThreadsController extends Thread { ArrayList> Squares= new ArrayList>(); Tuple headSnakePos; - int sizeSnake=3; + int sizeSnake = 3; long speed = 50; public static int directionSnake ; @@ -42,12 +44,23 @@ public void run() { //delay between each move of the snake private void pauser(){ - try { + try { sleep(speed); - } catch (InterruptedException e) { + } catch (InterruptedException e) { e.printStackTrace(); } } + //Setting up restart after game pauses + private void restart() { + // Restarting the game + //Creating the window again + Window f1= new Window(); + //Setting up the window settings + f1.setTitle("Snake"); + f1.setSize(300,300); + f1.setVisible(true); + f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } //Checking if the snake bites itself or is eating private void checkCollision() { @@ -56,6 +69,7 @@ private void checkCollision() { boolean biteItself = posCritique.getX()==positions.get(i).getX() && posCritique.getY()==positions.get(i).getY(); if(biteItself){ stopTheGame(); + } } @@ -72,9 +86,11 @@ private void checkCollision() { //Stops The Game private void stopTheGame(){ System.out.println("COLISION! \n"); + restart(); while(true){ pauser(); - } + } + } //Put food in a position and displays it diff --git a/src/Window.java b/src/Window.java index 518fa9e..5f2b7e4 100644 --- a/src/Window.java +++ b/src/Window.java @@ -49,9 +49,9 @@ public Window(){ //To do : handle multiplayers .. The above works, test it and see what happens - //Tuple position2 = new Tuple(13,13); - //ControlleurThreads c2 = new ControlleurThreads(position2); - //c2.start(); +// Tuple position2 = new Tuple(13,13); +// ControlleurThreads c2 = new ControlleurThreads(position2); +// c2.start(); } }