DEADSOFTWARE

Nonnull by default
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / GameWorld.java
index 89c458523c1a0c53df3f1f3cdf97138c5dbcc3b5..01ddee9c111de4c81be866d4293cb7497d77b503 100644 (file)
@@ -5,11 +5,29 @@ import ru.deadsoftware.cavedroid.game.objects.Drop;
 
 import static ru.deadsoftware.cavedroid.GameScreen.GP;
 
+@SuppressWarnings("WeakerAccess")
 public class GameWorld {
 
-    private int WIDTH, HEIGHT;
-    private int[][] foreMap;
-    private int[][] backMap;
+    private final int WIDTH;
+    private final int HEIGHT;
+    private final int[][] foreMap;
+    private final int[][] backMap;
+
+    GameWorld(int width, int height) {
+        WIDTH = width;
+        HEIGHT = height;
+        WorldGen.genWorld(WIDTH, HEIGHT);
+        foreMap = WorldGen.getForeMap();
+        backMap = WorldGen.getBackMap();
+        WorldGen.clear();
+    }
+
+    GameWorld(int[][] foreMap, int[][] backMap) {
+        this.foreMap = foreMap.clone();
+        this.backMap = backMap.clone();
+        WIDTH = foreMap.length;
+        HEIGHT = foreMap[0].length;
+    }
 
     public int getWidth() {
         return WIDTH;
@@ -27,11 +45,11 @@ public class GameWorld {
         return HEIGHT * 16f;
     }
 
-    public int[][] getFullForeMap() {
+    int[][] getFullForeMap() {
         return foreMap;
     }
 
-    public int[][] getFullBackMap() {
+    int[][] getFullBackMap() {
         return backMap;
     }
 
@@ -60,10 +78,14 @@ public class GameWorld {
         }
     }
 
-    public boolean hasBlockAt(int x, int y) {
+    public boolean hasForeAt(int x, int y) {
         return getMap(x, y, 0) != 0;
     }
 
+    public boolean hasBackAt(int x, int y) {
+        return getMap(x, y, 1) != 0;
+    }
+
     public int getForeMap(int x, int y) {
         return getMap(x, y, 0);
     }
@@ -112,7 +134,7 @@ public class GameWorld {
     }
 
     public void placeToForeground(int x, int y, int value) {
-        if (!hasBlockAt(x, y) || value == 0 || !GameItems.getBlock(getForeMap(x, y)).hasCollision()) {
+        if (!hasForeAt(x, y) || value == 0 || !GameItems.getBlock(getForeMap(x, y)).hasCollision()) {
             setForeMap(x, y, value);
         } else if (GameItems.isSlab(value) && getForeMap(x, y) == value) {
             placeSlab(x, y, value);
@@ -143,20 +165,4 @@ public class GameWorld {
         placeToBackground(x, y, 0);
     }
 
-    public void generate(int w, int h) {
-        WIDTH = w;
-        HEIGHT = h;
-        WorldGen.genWorld(WIDTH, HEIGHT);
-        foreMap = WorldGen.getForeMap();
-        backMap = WorldGen.getBackMap();
-        WorldGen.clear();
-    }
-
-    void setMaps(int[][] foreMap, int[][] backMap) {
-        this.foreMap = foreMap.clone();
-        this.backMap = backMap.clone();
-        WIDTH = foreMap.length;
-        HEIGHT = foreMap[0].length;
-    }
-
 }
\ No newline at end of file