diff --git a/.idea/misc.xml b/.idea/misc.xml index 25d34a4..57cdb8e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index c064301..0fbcc21 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ buildscript { } allprojects { - version = '1.0' + version = '0.1' ext { appName = "Cookery" diff --git a/core/build.gradle b/core/build.gradle index 889d596..d9b0752 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,6 +1,6 @@ apply plugin: "java" -sourceCompatibility = 1.7 +sourceCompatibility = 1.8 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' sourceSets { diff --git a/core/src/se/cookery/world/Block.java b/core/src/se/cookery/world/Block.java index 8cfca01..2ff0032 100644 --- a/core/src/se/cookery/world/Block.java +++ b/core/src/se/cookery/world/Block.java @@ -1,4 +1,43 @@ package se.cookery.world; +/** + * Class representing a block of the world. + * + * The class contains items, land type and world height information + */ public class Block { + /** + * The size of a block in units of squares. The block is a square with size BLOCK_SIZE x BLOCK_SIZE. + **/ + public static final int BLOCK_SIZE = 20; + + private long offset_x = 0; + private long offset_y = 0; + private byte[][] height = new byte[BLOCK_SIZE][BLOCK_SIZE]; + private byte[][] landType = new byte[BLOCK_SIZE][BLOCK_SIZE]; + + + public long getBlockStartX(){ + return offset_x; + } + + public long getBlockStartY(){ + return offset_y; + } + + public long getBlockEndX(){ + return offset_x + BLOCK_SIZE; + } + + public long getBlockEndY(){ + return offset_y + BLOCK_SIZE; + } + + public int getHeight(long x, long y) { + return height[(int) Math.abs(x-offset_x)][(int) Math.abs(y-offset_y)]; + } + + public int getGround(long x, long y) { + return landType[(int) Math.abs(x-offset_x)][(int) Math.abs(y-offset_y)]; + } } diff --git a/core/src/se/cookery/world/Ground.java b/core/src/se/cookery/world/Ground.java new file mode 100644 index 0000000..f251c76 --- /dev/null +++ b/core/src/se/cookery/world/Ground.java @@ -0,0 +1,8 @@ +package se.cookery.world; + +/** + * Class representing a ground material type. + */ +public class Ground { + private int id; +} diff --git a/core/src/se/cookery/world/GroundFactory.java b/core/src/se/cookery/world/GroundFactory.java new file mode 100644 index 0000000..4a75e2f --- /dev/null +++ b/core/src/se/cookery/world/GroundFactory.java @@ -0,0 +1,18 @@ +package se.cookery.world; + +import java.security.InvalidParameterException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GroundFactory { + public static Map groundTypes = new HashMap<>(); + + + public static Ground get(int id) { + if (0 > id || id > groundTypes.size()) + throw new InvalidParameterException("Provided id " + id + " is not associated dwith a ground type."); + return groundTypes.get(id); + } +} diff --git a/core/src/se/cookery/world/World.java b/core/src/se/cookery/world/World.java index 2284967..dd6ec03 100644 --- a/core/src/se/cookery/world/World.java +++ b/core/src/se/cookery/world/World.java @@ -1,32 +1,21 @@ package se.cookery.world; +import se.cookery.world.gen.WorldGenerator; + import java.util.Map; import java.util.TreeMap; public class World { - // Constants - - /** - * The size in a virtual coordinate system unit. The square is a square with size BLOCK_SIZE x BLOCK_SIZE. - **/ - public static final int SQUARE_SIZE = 1; - - /** - * The size of a block in units of squares. The block is a square with size BLOCK_SIZE x BLOCK_SIZE. - **/ - public static final int BLOCK_SIZE = 20; - - // Variables - private Map> worldBlocks = new TreeMap<>(); + private WorldGenerator generator; - public World() { - + public World(WorldGenerator generator) { + this.generator = generator; } /** - * @return true if the block coordiante exists, otherwise false + * @return true if the block coordinate exists, otherwise false */ public boolean blockExists(long x, long y) { return worldBlocks.get(x) != null && worldBlocks.get(x).get(y) != null; @@ -37,6 +26,8 @@ public class World { * not exist then a new block will be generated for the requested coordinate */ public Block getBlock(long x, long y) { + if (!blockExists(x, y)) + generator.generateBlock(x, y); return null; } } diff --git a/core/src/se/cookery/world/gen/GrassLandWorldGenerator.java b/core/src/se/cookery/world/gen/GrassLandWorldGenerator.java new file mode 100644 index 0000000..a6275c4 --- /dev/null +++ b/core/src/se/cookery/world/gen/GrassLandWorldGenerator.java @@ -0,0 +1,11 @@ +package se.cookery.world.gen; + +import se.cookery.world.Block; + +public class GrassLandWorldGenerator implements WorldGenerator { + + @Override + public Block generateBlock(long x, long y) { + return null; + } +} diff --git a/core/src/se/cookery/world/gen/WorldGenerator.java b/core/src/se/cookery/world/gen/WorldGenerator.java new file mode 100644 index 0000000..c037b03 --- /dev/null +++ b/core/src/se/cookery/world/gen/WorldGenerator.java @@ -0,0 +1,19 @@ +package se.cookery.world.gen; + +import se.cookery.world.Block; + +/** + * Interface representing a world generation class. + * + * A class that implements this interface can be used + * to generate a static or dynamic world. + */ +public interface WorldGenerator { + + /** + * Method to generate a block with the provided coordinates, + * calling this method with the same parameters will always + * return a new Block object but with the same values. + */ + Block generateBlock(long x, long y); +} diff --git a/core/test/se/cookery/world/GroundFactoryTest.java b/core/test/se/cookery/world/GroundFactoryTest.java new file mode 100644 index 0000000..d32b2ad --- /dev/null +++ b/core/test/se/cookery/world/GroundFactoryTest.java @@ -0,0 +1,21 @@ +package se.cookery.world; + +import org.junit.jupiter.api.Test; + +import java.security.InvalidParameterException; + +import static org.junit.jupiter.api.Assertions.*; + +class GroundFactoryTest { + + @Test + void get() { + assertThrows(InvalidParameterException.class, () -> { + GroundFactory.get(-1); + }); + + assertThrows(InvalidParameterException.class, () -> { + GroundFactory.get(500); + }); + } +} \ No newline at end of file diff --git a/core/test/se/cookery/world/WorldTest.java b/core/test/se/cookery/world/WorldTest.java index 0c5c636..0e8139a 100644 --- a/core/test/se/cookery/world/WorldTest.java +++ b/core/test/se/cookery/world/WorldTest.java @@ -1,18 +1,27 @@ package se.cookery.world; import org.junit.jupiter.api.Test; +import se.cookery.world.gen.GrassLandWorldGenerator; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.*; public class WorldTest { @Test public void blockExists() { - World w = new World(); - assertNull(w.getBlock(0, 0)); + World w = new World(new GrassLandWorldGenerator()); + assertFalse(w.blockExists(0, 0)); + assertFalse(w.blockExists(Long.MAX_VALUE, Long.MAX_VALUE)); + assertFalse(w.blockExists(Long.MIN_VALUE, Long.MAX_VALUE)); + assertFalse(w.blockExists(Long.MAX_VALUE, Long.MIN_VALUE)); + assertFalse(w.blockExists(Long.MIN_VALUE, Long.MIN_VALUE)); } @Test public void getBlock() { + World w = new World(new GrassLandWorldGenerator()); + assertFalse(w.blockExists(0, 0)); + assertNotNull(w.getBlock(0,0)); + assertTrue(w.blockExists(0, 0)); } } \ No newline at end of file diff --git a/core/test/se/cookery/world/gen/GrassLandWorldGeneratorTest.java b/core/test/se/cookery/world/gen/GrassLandWorldGeneratorTest.java new file mode 100644 index 0000000..c88d813 --- /dev/null +++ b/core/test/se/cookery/world/gen/GrassLandWorldGeneratorTest.java @@ -0,0 +1,13 @@ +package se.cookery.world.gen; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class GrassLandWorldGeneratorTest { + + @Test + void generateBlock() { + + } +} \ No newline at end of file diff --git a/desktop/build.gradle b/desktop/build.gradle index c046cb1..08c83c7 100644 --- a/desktop/build.gradle +++ b/desktop/build.gradle @@ -1,6 +1,6 @@ apply plugin: "java" -sourceCompatibility = 1.7 +sourceCompatibility = 1.8 sourceSets.main.java.srcDirs = [ "src/" ] sourceSets.main.resources.srcDirs = ["../android/assets"] diff --git a/ios/build.gradle b/ios/build.gradle index b642f42..418201d 100644 --- a/ios/build.gradle +++ b/ios/build.gradle @@ -1,6 +1,6 @@ sourceSets.main.java.srcDirs = [ "src/" ] -sourceCompatibility = '1.7' +sourceCompatibility = '1.8' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' dependencies {