Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/ThreadsController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JLabel;

//Controls all the game logic .. most important class in this project.
public class ThreadsController extends Thread {
ArrayList<ArrayList<DataOfSquare>> Squares= new ArrayList<ArrayList<DataOfSquare>>();
Tuple headSnakePos;
int sizeSnake=3;
long speed = 50;
int v=0;
Tuple finishposition;
long speed = 100;
public static int directionSnake ;

ArrayList<Tuple> positions = new ArrayList<Tuple>();
Expand Down Expand Up @@ -63,15 +66,25 @@ private void checkCollision() {
if(eatingFood){
System.out.println("Yummy!");
sizeSnake=sizeSnake+1;
foodPosition = getValAleaNotInSnake();

v=v+10;
System.out.println(v);
foodPosition = getValAleaNotInSnake();

spawnFood(foodPosition);
}
}

//Stops The Game
private void stopTheGame(){
System.out.println("COLISION! \n");
System.out.println("Game over");
System.out.println(v);
JFrame newFrame = new JFrame();
newFrame.setSize(200,200);
JLabel p=new JLabel();
p.setText("Game over . Total score is :"+v);
newFrame.add(p);
newFrame.setVisible(true);
while(true){
pauser();
}
Expand All @@ -82,6 +95,10 @@ private void spawnFood(Tuple foodPositionIn){
Squares.get(foodPositionIn.x).get(foodPositionIn.y).lightMeUp(1);
}





//return a position not occupied by the snake
private Tuple getValAleaNotInSnake(){
Tuple p ;
Expand Down
7 changes: 7 additions & 0 deletions src/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JLabel;


class Window extends JFrame{
Expand All @@ -13,6 +14,9 @@ class Window extends JFrame{
public Window(){





// Creates the arraylist that'll contain the threads
Grid = new ArrayList<ArrayList<DataOfSquare>>();
ArrayList<DataOfSquare> data;
Expand All @@ -25,8 +29,11 @@ public Window(){
data.add(c);
}
Grid.add(data);

}



// Setting up the layout of the panel
getContentPane().setLayout(new GridLayout(20,20,0,0));

Expand Down