From 62f3b5cc0718e5dc5d79942a180144c61fc6d306 Mon Sep 17 00:00:00 2001 From: virgi Date: Fri, 31 May 2024 14:10:20 +0200 Subject: [PATCH 1/2] comment world class --- OOP_D7_Project/src/backend/World.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OOP_D7_Project/src/backend/World.java b/OOP_D7_Project/src/backend/World.java index ac32c58..f04cffd 100644 --- a/OOP_D7_Project/src/backend/World.java +++ b/OOP_D7_Project/src/backend/World.java @@ -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 public void randomizer(double randValue) { for (int i =0; i < currentWorld.length; i++) { for (int j =0; j < currentWorld[i].length; j++) { From b488a9fa0e3ce72083aaecae56289f2673913809 Mon Sep 17 00:00:00 2001 From: virgi Date: Fri, 31 May 2024 14:10:53 +0200 Subject: [PATCH 2/2] add comment world class --- OOP_D7_Project/src/backend/World.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OOP_D7_Project/src/backend/World.java b/OOP_D7_Project/src/backend/World.java index f04cffd..fb838d0 100644 --- a/OOP_D7_Project/src/backend/World.java +++ b/OOP_D7_Project/src/backend/World.java @@ -17,7 +17,7 @@ public class World { this.teleportX = new Teleporter(width); this.teleportY = new Teleporter(height); } - //method to + //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++) { @@ -32,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++) {