DEADSOFTWARE

Implement DI for menu and refactor #13
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / WorldGen.java
index faacb252ba36fd2dfd06b8f5c748d44203742a3d..cc02aea03f2dff4af2151175d451cb3c751c7f23 100644 (file)
@@ -3,13 +3,19 @@ package ru.deadsoftware.cavedroid.game;
 import com.badlogic.gdx.math.RandomXS128;
 import com.badlogic.gdx.utils.TimeUtils;
 
-public class WorldGen {
+import javax.annotation.CheckForNull;
 
+class WorldGen {
+
+    @CheckForNull
     private static RandomXS128 rand;
     private static long seed;
 
+    @CheckForNull
     private static int[][] foreMap, backMap;
+    @CheckForNull
     private static int[] hMap;
+    @CheckForNull
     private static int[] bMap; //biomes, 0-plains, 1-desert
 
     public static long getSeed() {
@@ -23,33 +29,48 @@ public class WorldGen {
         res[0] = mid;
         for (int i = 1; i < width; i++) {
             t = rand.nextInt(7) - 3;
-            if (t > -3 && t < 3) t = 0;
-            else t /= Math.abs(t);
+            if (t > -3 && t < 3) {
+                t = 0;
+            } else {
+                t /= Math.abs(t);
+            }
             if (i > width - (max - min)) {
-                if (res[i - 1] + t < res[0]) t = Math.abs(t);
-                else if (res[i - 1] + t > res[0]) t = -Math.abs(t);
+                if (res[i - 1] + t < res[0]) {
+                    t = Math.abs(t);
+                } else if (res[i - 1] + t > res[0]) {
+                    t = -Math.abs(t);
+                }
             }
             res[i] = res[i - 1] + t;
-            if (res[i] < min) res[i] = min;
-            if (res[i] > max) res[i] = max;
-            if (i >= width / 2) {
-                bMap[i] = 1;
-                if (res[i] < 60) res[i] = 60;
-            } else {
-                bMap[i] = 0;
+            if (res[i] < min) {
+                res[i] = min;
+            }
+            if (res[i] > max) {
+                res[i] = max;
             }
+            bMap[i] = 0;
+//            if (i >= width / 2) {
+//                bMap[i] = 1;
+//                if (res[i] < 60) res[i] = 60;
+//            } else {
+//                bMap[i] = 0;
+//            }
+        }
+        if (res[0] < res[width - 1]) {
+            res[width - 1] = res[0];
         }
-        if (res[0] < res[width - 1]) res[width - 1] = res[0];
         return res;
     }
 
     private static void genCactus(int x, int y) {
+        assert foreMap != null;
         foreMap[x][y] = 59;
         foreMap[x][y - 1] = 59;
         foreMap[x][y - 2] = 59;
     }
 
     private static void genOak(int x, int y) {
+        assert foreMap != null && backMap != null;
         backMap[x][y] = 15;
         backMap[x][y - 1] = 15;
         backMap[x][y - 2] = 15;
@@ -170,16 +191,16 @@ public class WorldGen {
     }
 
     static int[][] getForeMap() {
+        assert foreMap != null;
         return foreMap;
     }
 
     static int[][] getBackMap() {
+        assert backMap != null;
         return backMap;
     }
 
     static void clear() {
-        foreMap = null;
-        backMap = null;
         hMap = null;
         bMap = null;
     }