version corrigée sans Grid.java
This commit is contained in:
parent
81e4c7ed59
commit
770828e42d
|
|
@ -1,12 +1,14 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
public class Grid {
|
public class Grid {
|
||||||
public static int[][] grid;
|
public int[][] grid;
|
||||||
int width=Simulator.COL_NUM;
|
|
||||||
int height=Simulator.LINE_NUM;
|
|
||||||
|
|
||||||
public Grid() {
|
public Grid(int width, int height) {
|
||||||
grid = new int[Simulator.COL_NUM][Simulator.LINE_NUM];
|
grid = new int[width][height];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCell(int x,int y) {
|
||||||
|
return grid[x][y];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
private MyInterface mjf;
|
private MyInterface mjf;
|
||||||
|
|
||||||
public static final int COL_NUM = 100;
|
private final int COL_NUM = 100;
|
||||||
public static final int LINE_NUM = 100;
|
private final int LINE_NUM = 100;
|
||||||
private final int LIFE_TYPE_NUM = 4;
|
private final int LIFE_TYPE_NUM = 4;
|
||||||
//Conway Radius : 1
|
//Conway Radius : 1
|
||||||
private final int LIFE_AREA_RADIUS = 1;
|
private final int LIFE_AREA_RADIUS = 1;
|
||||||
|
|
@ -25,6 +25,7 @@ public class Simulator extends Thread {
|
||||||
private boolean loopingBorder;
|
private boolean loopingBorder;
|
||||||
private boolean clickActionFlag;
|
private boolean clickActionFlag;
|
||||||
private int loopDelay = 150;
|
private int loopDelay = 150;
|
||||||
|
public int[][] grid;
|
||||||
|
|
||||||
//TODO : add missing attribute(s)
|
//TODO : add missing attribute(s)
|
||||||
|
|
||||||
|
|
@ -40,7 +41,7 @@ public class Simulator extends Thread {
|
||||||
fieldSurviveValues = new ArrayList<Integer>();
|
fieldSurviveValues = new ArrayList<Integer>();
|
||||||
|
|
||||||
//TODO : add missing attribute initialization
|
//TODO : add missing attribute initialization
|
||||||
|
grid = new int[COL_NUM][LINE_NUM];
|
||||||
|
|
||||||
|
|
||||||
//Default rule : Survive always, birth never
|
//Default rule : Survive always, birth never
|
||||||
|
|
@ -147,7 +148,7 @@ public class Simulator extends Thread {
|
||||||
agents.add(newAgent);
|
agents.add(newAgent);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Grid.grid[x][y] = (Grid.grid[x][y] == 0) ? 1 : 0; // 0=dead and 1=alive
|
grid[x][y] = (grid[x][y] == 0) ? 1 : 0; // 0=dead and 1=alive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,10 +160,10 @@ public class Simulator extends Thread {
|
||||||
*/
|
*/
|
||||||
public int getCell(int x, int y) {
|
public int getCell(int x, int y) {
|
||||||
if (x >= 0 && x < COL_NUM && y >= 0 && y < LINE_NUM) {
|
if (x >= 0 && x < COL_NUM && y >= 0 && y < LINE_NUM) {
|
||||||
return Grid.grid[x][y];
|
return grid[x][y];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("Error: Coordinates out of the grid.");
|
System.out.println("Error: Coordinates out of the ");
|
||||||
return -1;// If the coordinates are out of the grid, we return -1 as an error value
|
return -1;// If the coordinates are out of the grid, we return -1 as an error value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -199,10 +200,10 @@ public class Simulator extends Thread {
|
||||||
*/
|
*/
|
||||||
public void setCell(int x, int y, int val) {
|
public void setCell(int x, int y, int val) {
|
||||||
if (x >= 0 && x < COL_NUM && y >= 0 && y < LINE_NUM) {
|
if (x >= 0 && x < COL_NUM && y >= 0 && y < LINE_NUM) {
|
||||||
Grid.grid[x][y] = val;
|
grid[x][y] = val;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("Error: Coordinates out of the grid.");
|
System.out.println("Error: Coordinates out of the ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue