Added Zutil as dependency and added new ground type datafile

This commit is contained in:
Ziver Koc 2020-01-04 20:03:57 +01:00
parent c51a473120
commit 3b9422346a
11 changed files with 80 additions and 39 deletions

2
.idea/misc.xml generated
View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="11" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project> </project>

View file

@ -4,7 +4,7 @@
<facet type="android-gradle" name="Android-Gradle"> <facet type="android-gradle" name="Android-Gradle">
<configuration> <configuration>
<option name="GRADLE_PROJECT_PATH" value=":android" /> <option name="GRADLE_PROJECT_PATH" value=":android" />
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" value="3.5.0" /> <option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" />
<option name="LAST_KNOWN_AGP_VERSION" value="3.5.0" /> <option name="LAST_KNOWN_AGP_VERSION" value="3.5.0" />
</configuration> </configuration>
</facet> </facet>
@ -17,8 +17,6 @@
<task>generateDebugSources</task> <task>generateDebugSources</task>
</afterSyncTasks> </afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" /> <option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/res;file://$MODULE_DIR$/build/generated/res/rs/debug;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="" />
</configuration> </configuration>
</facet> </facet>
</component> </component>

View file

@ -6,6 +6,7 @@ sourceCompatibility = 1.8
sourceSets { sourceSets {
main { main {
java.srcDirs = [ "src/" ] java.srcDirs = [ "src/" ]
resources.srcDirs= ["resources/"]
} }
test { test {
java.srcDirs = ["test/"] java.srcDirs = ["test/"]
@ -13,9 +14,12 @@ sourceSets {
} }
dependencies { dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
implementation 'se.koc:zutil:1.0.236'
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.5.2" testImplementation "org.junit.jupiter:junit-jupiter-engine:5.5.2"
testImplementation "org.junit.platform:junit-platform-runner:1.5.2" testImplementation "org.junit.platform:junit-platform-runner:1.5.2"
api "com.badlogicgames.gdx:gdx:$gdxVersion"
} }
test { test {

View file

@ -0,0 +1,5 @@
{
"1": {
"name": "Grass"
}
}

View file

@ -6,11 +6,15 @@ package se.cookery.world;
* The class contains items, land type and world height information * The class contains items, land type and world height information
*/ */
public class Block { public class Block {
// Constants
/** /**
* The size of a block in units of squares. The block is a square with size BLOCK_SIZE x BLOCK_SIZE. * 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; public static final int BLOCK_SIZE = 20;
// Variables
private long offset_x = 0; private long offset_x = 0;
private long offset_y = 0; private long offset_y = 0;
private byte[][] height = new byte[BLOCK_SIZE][BLOCK_SIZE]; private byte[][] height = new byte[BLOCK_SIZE][BLOCK_SIZE];

View file

@ -1,8 +0,0 @@
package se.cookery.world;
/**
* Class representing a ground material type.
*/
public class Ground {
private int id;
}

View file

@ -1,18 +0,0 @@
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<Integer, Ground> 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);
}
}

View file

@ -0,0 +1,18 @@
package se.cookery.world;
/**
* Class representing a ground material type.
*/
public class GroundType {
// Variables
private int id;
private String name;
protected GroundType() {}
public String getName() {
return null;
}
}

View file

@ -0,0 +1,28 @@
package se.cookery.world;
import com.badlogic.gdx.utils.JsonReader;
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.Map;
public class GroundTypeFactory {
// Constants
public static final String RESOURCE_GROUND_TYPE = "data/ground_types.json";
// Variables
public static Map<Integer, GroundType> groundTypes = new HashMap<>();
public static void initialize() {
}
public static GroundType get(int id) {
if (0 > id || id > groundTypes.size())
throw new InvalidParameterException("Provided id " + id + " is not associated with a ground type.");
return groundTypes.get(id);
}
}

View file

@ -6,6 +6,8 @@ import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
public class World { public class World {
// Variables
private Map<Long, Map<Long, Block>> worldBlocks = new TreeMap<>(); private Map<Long, Map<Long, Block>> worldBlocks = new TreeMap<>();
private WorldGenerator generator; private WorldGenerator generator;

View file

@ -6,16 +6,24 @@ import java.security.InvalidParameterException;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class GroundFactoryTest { class GroundTypeFactoryTest {
@Test
void invalidIDTest() {
assertThrows(InvalidParameterException.class, () -> {
GroundTypeFactory.get(-1);
});
assertThrows(InvalidParameterException.class, () -> {
GroundTypeFactory.get(500);
});
}
@Test @Test
void get() { void get() {
assertThrows(InvalidParameterException.class, () -> { GroundType ground = GroundTypeFactory.get(0);
GroundFactory.get(-1); assertNotNull(ground);
}); assertSame(ground, GroundTypeFactory.get(0));
assertEquals("Grass", ground.getName());
assertThrows(InvalidParameterException.class, () -> {
GroundFactory.get(500);
});
} }
} }