commencement de TODO: apply game rule to all cells of the field

This commit is contained in:
yoenm 2024-05-14 17:21:01 +02:00
parent 6e1baecd7e
commit a1d30f7ad7
1 changed files with 26 additions and 5 deletions

View File

@ -25,6 +25,8 @@ public class Simulator extends Thread {
private boolean clickActionFlag;
private int loopDelay = 150;
private int[][] grid;
//TODO : add missing attribute(s)
public Simulator(MyInterface mjfParam) {
@ -39,8 +41,15 @@ public class Simulator extends Thread {
fieldSurviveValues = new ArrayList<Integer>();
//TODO : add missing attribute initialization
grid = new int[COL_NUM][LINE_NUM];
// we set the grid of the size of col_num and line_num
for (int x=0; x<COL_NUM; x++) {
for (int y=0; y< LINE_NUM;y++) {
grid[x][y]= 0;
}
}
// we set each cell as 0 = dead
// but we still have to define that 0 = dead cell and 1 = alive cell
fieldSurviveValues.add(2);
fieldSurviveValues.add(3);
fieldBirthValues.add(3);
@ -117,13 +126,25 @@ public class Simulator extends Thread {
* if the cell is not alive
* and the count is in the birth list,
* then the cell becomes alive
*/
*/
}
public int countSurroundingValues(int x, int y, int typeToCount) {
int count=0;
for (int j= y-1; j<=y+1; j++) {
for (int i=x-1; i<=x+1;i++) {
if (grid[x][y]==typeToCount) {
count +=1;
}
}
}
return count;
}
/*
* leave this as is
*/