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
14 changes: 7 additions & 7 deletions src/ThreadsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ThreadsController extends Thread {
//Constructor of ControlleurThread
ThreadsController(Tuple positionDepart){
//Get all the threads
Squares=Window.Grid;
Squares=Window.grid;

headSnakePos=new Tuple(positionDepart.x,positionDepart.y);
directionSnake = 1;
Expand Down Expand Up @@ -104,30 +104,30 @@ private Tuple getValAleaNotInSnake(){
private void moveInterne(int dir){
switch(dir){
case 4:
headSnakePos.ChangeData(headSnakePos.x,(headSnakePos.y+1)%20);
headSnakePos.changeData(headSnakePos.x,(headSnakePos.y+1)%20);
positions.add(new Tuple(headSnakePos.x,headSnakePos.y));
break;
case 3:
if(headSnakePos.y-1<0){
headSnakePos.ChangeData(headSnakePos.x,19);
headSnakePos.changeData(headSnakePos.x,19);
}
else{
headSnakePos.ChangeData(headSnakePos.x,Math.abs(headSnakePos.y-1)%20);
headSnakePos.changeData(headSnakePos.x,Math.abs(headSnakePos.y-1)%20);
}
positions.add(new Tuple(headSnakePos.x,headSnakePos.y));
break;
case 2:
if(headSnakePos.x-1<0){
headSnakePos.ChangeData(19,headSnakePos.y);
headSnakePos.changeData(19,headSnakePos.y);
}
else{
headSnakePos.ChangeData(Math.abs(headSnakePos.x-1)%20,headSnakePos.y);
headSnakePos.changeData(Math.abs(headSnakePos.x-1)%20,headSnakePos.y);
}
positions.add(new Tuple(headSnakePos.x,headSnakePos.y));

break;
case 1:
headSnakePos.ChangeData(Math.abs(headSnakePos.x+1)%20,headSnakePos.y);
headSnakePos.changeData(Math.abs(headSnakePos.x+1)%20,headSnakePos.y);
positions.add(new Tuple(headSnakePos.x,headSnakePos.y));
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public Tuple(int x, int y) {
this.x = x;
this.y = y;
}
public void ChangeData(int x, int y){
public void changeData(int x, int y){
this.x = x;
this.y = y;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

class Window extends JFrame{
private static final long serialVersionUID = -2542001418764869760L;
public static ArrayList<ArrayList<DataOfSquare>> Grid;
public static ArrayList<ArrayList<DataOfSquare>> grid;
public static int width = 20;
public static int height = 20;
public Window(){


// Creates the arraylist that'll contain the threads
Grid = new ArrayList<ArrayList<DataOfSquare>>();
grid = new ArrayList<ArrayList<DataOfSquare>>();
ArrayList<DataOfSquare> data;

// Creates Threads and its data and adds it to the arrayList
Expand All @@ -24,7 +24,7 @@ public Window(){
DataOfSquare c = new DataOfSquare(2);
data.add(c);
}
Grid.add(data);
grid.add(data);
}

// Setting up the layout of the panel
Expand All @@ -33,7 +33,7 @@ public Window(){
// Start & pauses all threads, then adds every square of each thread to the panel
for(int i=0;i<width;i++){
for(int j=0;j<height;j++){
getContentPane().add(Grid.get(i).get(j).square);
getContentPane().add(grid.get(i).get(j).square);
}
}

Expand Down