version corrigée sans Grid.java

This commit is contained in:
yoyom 2024-05-07 17:18:50 +02:00
parent 81e4c7ed59
commit 770828e42d
2 changed files with 16 additions and 13 deletions

View File

@ -1,12 +1,14 @@
package backend;
public class Grid {
public static int[][] grid;
int width=Simulator.COL_NUM;
int height=Simulator.LINE_NUM;
public int[][] grid;
public Grid() {
grid = new int[Simulator.COL_NUM][Simulator.LINE_NUM];
public Grid(int width, int height) {
grid = new int[width][height];
}
public int getCell(int x,int y) {
return grid[x][y];
}
}

View File

@ -8,8 +8,8 @@ public class Simulator extends Thread {
private MyInterface mjf;
public static final int COL_NUM = 100;
public static final int LINE_NUM = 100;
private final int COL_NUM = 100;
private final int LINE_NUM = 100;
private final int LIFE_TYPE_NUM = 4;
//Conway Radius : 1
private final int LIFE_AREA_RADIUS = 1;
@ -25,6 +25,7 @@ public class Simulator extends Thread {
private boolean loopingBorder;
private boolean clickActionFlag;
private int loopDelay = 150;
public int[][] grid;
//TODO : add missing attribute(s)
@ -40,7 +41,7 @@ public class Simulator extends Thread {
fieldSurviveValues = new ArrayList<Integer>();
//TODO : add missing attribute initialization
grid = new int[COL_NUM][LINE_NUM];
//Default rule : Survive always, birth never
@ -147,7 +148,7 @@ public class Simulator extends Thread {
agents.add(newAgent);
}
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) {
if (x >= 0 && x < COL_NUM && y >= 0 && y < LINE_NUM) {
return Grid.grid[x][y];
return grid[x][y];
}
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
}
}
@ -199,10 +200,10 @@ public class Simulator extends Thread {
*/
public void setCell(int x, int y, int val) {
if (x >= 0 && x < COL_NUM && y >= 0 && y < LINE_NUM) {
Grid.grid[x][y] = val;
grid[x][y] = val;
}
else {
System.out.println("Error: Coordinates out of the grid.");
System.out.println("Error: Coordinates out of the ");
}
}