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

View file

@ -6,6 +6,7 @@ sourceCompatibility = 1.8
sourceSets {
main {
java.srcDirs = [ "src/" ]
resources.srcDirs= ["resources/"]
}
test {
java.srcDirs = ["test/"]
@ -13,9 +14,12 @@ sourceSets {
}
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.platform:junit-platform-runner:1.5.2"
api "com.badlogicgames.gdx:gdx:$gdxVersion"
}
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
*/
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.
**/
public static final int BLOCK_SIZE = 20;
// Variables
private long offset_x = 0;
private long offset_y = 0;
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;
public class World {
// Variables
private Map<Long, Map<Long, Block>> worldBlocks = new TreeMap<>();
private WorldGenerator generator;

View file

@ -6,16 +6,24 @@ import java.security.InvalidParameterException;
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
void get() {
assertThrows(InvalidParameterException.class, () -> {
GroundFactory.get(-1);
});
assertThrows(InvalidParameterException.class, () -> {
GroundFactory.get(500);
});
GroundType ground = GroundTypeFactory.get(0);
assertNotNull(ground);
assertSame(ground, GroundTypeFactory.get(0));
assertEquals("Grass", ground.getName());
}
}