Merge branch 'master' of https://gitarero.ecam.fr/lucas.jacquet/OOP_D7_Project.git
This commit is contained in:
commit
7295ad831e
|
|
@ -1,18 +1,23 @@
|
|||
package backend;
|
||||
import java.util.Random;
|
||||
|
||||
// Here we will deal with the grid setup
|
||||
|
||||
public class World {
|
||||
//this part is to randomly create a grid.
|
||||
Random randGen = new Random();
|
||||
Teleporter teleportX ;
|
||||
Teleporter teleportY ;
|
||||
|
||||
// 2D array representing the state of the world
|
||||
private int[][] currentWorld;
|
||||
public World(int width, int height) {
|
||||
// set up the size of the grid
|
||||
public World(int width, int height) {
|
||||
currentWorld = new int[width][height];
|
||||
this.teleportX = new Teleporter(width);
|
||||
this.teleportY = new Teleporter(height);
|
||||
}
|
||||
//method to create a random field
|
||||
public void randomizer(double randValue) {
|
||||
for (int i =0; i < currentWorld.length; i++) {
|
||||
for (int j =0; j < currentWorld[i].length; j++) {
|
||||
|
|
@ -27,15 +32,19 @@ public class World {
|
|||
|
||||
}
|
||||
}
|
||||
// Method to get the value of a cell in the grid
|
||||
public int getValue(int x, int y) {
|
||||
// Check if the position is inside the Grid
|
||||
if (x == -99 || y == -99 ) {
|
||||
return 0;
|
||||
}
|
||||
return currentWorld [x][y];
|
||||
}
|
||||
// Method to set the value of a cell in the grid
|
||||
public void setValue(int x, int y, int value) {
|
||||
currentWorld [x][y] = value;
|
||||
}
|
||||
//Method to count the number of living cells around a cell
|
||||
public int getLiving(int x,int y,int radius,boolean loop) {
|
||||
int out = 0;
|
||||
for (int i=x-radius;i<=x+radius;i++) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue