all page 3 methods are updated
This commit is contained in:
parent
fffd3b6e52
commit
81e4c7ed59
|
|
@ -1,10 +1,12 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
public class Grid {
|
public class Grid {
|
||||||
private int[][] grid;
|
public static int[][] grid;
|
||||||
|
int width=Simulator.COL_NUM;
|
||||||
|
int height=Simulator.LINE_NUM;
|
||||||
|
|
||||||
public Grid(int width, int height) {
|
public Grid() {
|
||||||
grid = new int[width][height];
|
grid = new int[Simulator.COL_NUM][Simulator.LINE_NUM];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package backend;
|
package backend;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import windowInterface.MyInterface;
|
import windowInterface.MyInterface;
|
||||||
|
|
||||||
|
|
@ -7,8 +8,8 @@ public class Simulator extends Thread {
|
||||||
|
|
||||||
private MyInterface mjf;
|
private MyInterface mjf;
|
||||||
|
|
||||||
private final int COL_NUM = 100;
|
public static final int COL_NUM = 100;
|
||||||
private final int LINE_NUM = 100;
|
public static 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;
|
||||||
|
|
@ -24,8 +25,6 @@ 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;
|
||||||
|
|
||||||
private int[][] grid;
|
|
||||||
|
|
||||||
//TODO : add missing attribute(s)
|
//TODO : add missing attribute(s)
|
||||||
|
|
||||||
|
|
@ -148,7 +147,7 @@ public class Simulator extends Thread {
|
||||||
agents.add(newAgent);
|
agents.add(newAgent);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
grid[x][y] = (grid[x][y] == 0) ? 1 : 0; // 0=dead and 1=alive
|
Grid.grid[x][y] = (Grid.grid[x][y] == 0) ? 1 : 0; // 0=dead and 1=alive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,7 +159,7 @@ 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[x][y];
|
return Grid.grid[x][y];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("Error: Coordinates out of the grid.");
|
System.out.println("Error: Coordinates out of the grid.");
|
||||||
|
|
@ -200,7 +199,7 @@ 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[x][y] = val;
|
Grid.grid[x][y] = val;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("Error: Coordinates out of the grid.");
|
System.out.println("Error: Coordinates out of the grid.");
|
||||||
|
|
@ -257,14 +256,16 @@ public class Simulator extends Thread {
|
||||||
* to be alive in new state
|
* to be alive in new state
|
||||||
*/
|
*/
|
||||||
public void generateRandom(float chanceOfLife) {
|
public void generateRandom(float chanceOfLife) {
|
||||||
//TODO : complete method
|
Random random = new Random();
|
||||||
/*
|
for (int x = 0; x < COL_NUM; x++) {
|
||||||
* Advice :
|
for (int y = 0; y < LINE_NUM; y++) {
|
||||||
* as you should probably have a separate class
|
if (random.nextFloat() < chanceOfLife) {
|
||||||
* representing the field of cells...
|
setCell(x, y, 1);
|
||||||
* maybe just make a constructor in there
|
} else {
|
||||||
* and use it here
|
setCell(x, y, 0);
|
||||||
*/
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoopingBorder() {
|
public boolean isLoopingBorder() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue