commencement de TODO: apply game rule to all cells of the field
This commit is contained in:
parent
6e1baecd7e
commit
a1d30f7ad7
|
|
@ -25,6 +25,8 @@ public class Simulator extends Thread {
|
||||||
private boolean clickActionFlag;
|
private boolean clickActionFlag;
|
||||||
private int loopDelay = 150;
|
private int loopDelay = 150;
|
||||||
|
|
||||||
|
private int[][] grid;
|
||||||
|
|
||||||
//TODO : add missing attribute(s)
|
//TODO : add missing attribute(s)
|
||||||
|
|
||||||
public Simulator(MyInterface mjfParam) {
|
public Simulator(MyInterface mjfParam) {
|
||||||
|
|
@ -39,8 +41,15 @@ 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];
|
||||||
|
// 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(2);
|
||||||
fieldSurviveValues.add(3);
|
fieldSurviveValues.add(3);
|
||||||
fieldBirthValues.add(3);
|
fieldBirthValues.add(3);
|
||||||
|
|
@ -120,10 +129,22 @@ public class Simulator extends Thread {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
* leave this as is
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue