David Hermann
2 years ago
23 changed files with 707 additions and 17 deletions
-
16src/main/java/org/bitbiome/Boot.java
-
62src/main/java/org/bitbiome/classes/Colors.java
-
34src/main/java/org/bitbiome/classes/InteractionLoop.java
-
16src/main/java/org/bitbiome/classes/JsonParser.java
-
69src/main/java/org/bitbiome/classes/TravelEngine.java
-
8src/main/java/org/bitbiome/commands/CommandAPI.java
-
14src/main/java/org/bitbiome/commands/CommandListener.java
-
21src/main/java/org/bitbiome/commands/HelpCommand.java
-
18src/main/java/org/bitbiome/commands/LocationCommand.java
-
8src/main/java/org/bitbiome/commands/QuitCommand.java
-
38src/main/java/org/bitbiome/commands/TravelCommand.java
-
44src/main/java/org/bitbiome/entities/Item.java
-
41src/main/java/org/bitbiome/entities/Location.java
-
51src/main/java/org/bitbiome/entities/Mob.java
-
65src/main/java/org/bitbiome/entities/Player.java
-
17src/main/resources/gameconfig.json
-
23src/test/java/org/bitbiome/classes/ColorsTest.java
-
17src/test/java/org/bitbiome/commands/HelpCommandTest.java
-
22src/test/java/org/bitbiome/commands/LocationCommandTest.java
-
38src/test/java/org/bitbiome/entitiesTest/ItemTest.java
-
24src/test/java/org/bitbiome/entitiesTest/LocationTest.java
-
35src/test/java/org/bitbiome/entitiesTest/MobTest.java
-
43src/test/java/org/bitbiome/entitiesTest/PlayerTest.java
@ -0,0 +1,62 @@ |
|||
package org.bitbiome.classes; |
|||
|
|||
public class Colors { |
|||
|
|||
/* |
|||
* This class has only public static mehtods |
|||
* Just add a String to your String and finalize it with the ANSI_RESET String |
|||
* The Color Codes with BG in the variable name are for the background colors |
|||
*/ |
|||
|
|||
public static final String ANSI_RESET = "\u001B[0m"; |
|||
|
|||
public static final String ANSI_BLACK = "\u001B[30m"; |
|||
public static final String ANSI_RED = "\u001B[31m"; |
|||
public static final String ANSI_GREEN = "\u001B[32m"; |
|||
public static final String ANSI_YELLOW = "\u001B[33m"; |
|||
public static final String ANSI_BLUE = "\u001B[34m"; |
|||
public static final String ANSI_PURPLE = "\u001B[35m"; |
|||
public static final String ANSI_CYAN = "\u001B[36m"; |
|||
public static final String ANSI_WHITE = "\u001B[37m"; |
|||
|
|||
public static final String ANSI_BRIGHT_BLACK = "\u001B[90m"; |
|||
public static final String ANSI_BRIGHT_RED = "\u001B[91m"; |
|||
public static final String ANSI_BRIGHT_GREEN = "\u001B[92m"; |
|||
public static final String ANSI_BRIGHT_YELLOW = "\u001B[93m"; |
|||
public static final String ANSI_BRIGHT_BLUE = "\u001B[94m"; |
|||
public static final String ANSI_BRIGHT_PURPLE = "\u001B[95m"; |
|||
public static final String ANSI_BRIGHT_CYAN = "\u001B[96m"; |
|||
public static final String ANSI_BRIGHT_WHITE = "\u001B[97m"; |
|||
|
|||
public static final String[] FOREGROUNDS = { |
|||
ANSI_BLACK, ANSI_RED, ANSI_GREEN, ANSI_YELLOW, |
|||
ANSI_BLUE, ANSI_PURPLE, ANSI_CYAN, ANSI_WHITE, |
|||
ANSI_BRIGHT_BLACK, ANSI_BRIGHT_RED, ANSI_BRIGHT_GREEN, ANSI_BRIGHT_YELLOW, |
|||
ANSI_BRIGHT_BLUE, ANSI_BRIGHT_PURPLE, ANSI_BRIGHT_CYAN, ANSI_BRIGHT_WHITE |
|||
}; |
|||
|
|||
public static final String ANSI_BG_BLACK = "\u001B[40m"; |
|||
public static final String ANSI_BG_RED = "\u001B[41m"; |
|||
public static final String ANSI_BG_GREEN = "\u001B[42m"; |
|||
public static final String ANSI_BG_YELLOW = "\u001B[43m"; |
|||
public static final String ANSI_BG_BLUE = "\u001B[44m"; |
|||
public static final String ANSI_BG_PURPLE = "\u001B[45m"; |
|||
public static final String ANSI_BG_CYAN = "\u001B[46m"; |
|||
public static final String ANSI_BG_WHITE = "\u001B[47m"; |
|||
|
|||
public static final String ANSI_BRIGHT_BG_BLACK = "\u001B[100m"; |
|||
public static final String ANSI_BRIGHT_BG_RED = "\u001B[101m"; |
|||
public static final String ANSI_BRIGHT_BG_GREEN = "\u001B[102m"; |
|||
public static final String ANSI_BRIGHT_BG_YELLOW = "\u001B[103m"; |
|||
public static final String ANSI_BRIGHT_BG_BLUE = "\u001B[104m"; |
|||
public static final String ANSI_BRIGHT_BG_PURPLE = "\u001B[105m"; |
|||
public static final String ANSI_BRIGHT_BG_CYAN = "\u001B[106m"; |
|||
public static final String ANSI_BRIGHT_BG_WHITE = "\u001B[107m"; |
|||
|
|||
public static final String[] BACKGROUNDS = { |
|||
ANSI_BG_BLACK, ANSI_BG_RED, ANSI_BG_GREEN, ANSI_BG_YELLOW, |
|||
ANSI_BG_BLUE, ANSI_BG_PURPLE, ANSI_BG_CYAN, ANSI_BG_WHITE, |
|||
ANSI_BRIGHT_BG_BLACK, ANSI_BRIGHT_BG_RED, ANSI_BRIGHT_BG_GREEN, ANSI_BRIGHT_BG_YELLOW, |
|||
ANSI_BRIGHT_BG_BLUE, ANSI_BRIGHT_BG_PURPLE, ANSI_BRIGHT_BG_CYAN, ANSI_BRIGHT_BG_WHITE }; |
|||
|
|||
} |
@ -1,23 +1,49 @@ |
|||
package org.bitbiome.classes; |
|||
|
|||
import org.bitbiome.Boot; |
|||
|
|||
import org.json.JSONObject; |
|||
import java.util.Scanner; |
|||
|
|||
public class InteractionLoop { |
|||
|
|||
Scanner input = new Scanner(System.in); |
|||
|
|||
public void run() { |
|||
public void run(TravelEngine travelEngine) { |
|||
boolean isRunning = true; |
|||
if (playerIsNew(travelEngine.getPlayer().getName())) { |
|||
newPlayerWelcome(travelEngine); |
|||
} |
|||
print(Colors.ANSI_BG_CYAN + Colors.ANSI_BLACK + "Willkommen zu BitBiome " + travelEngine.getPlayer().getName() |
|||
+ "!" + Colors.ANSI_RESET + "\n\n"); |
|||
while (isRunning) { |
|||
String line = input.nextLine().toLowerCase(); |
|||
if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line)) { |
|||
System.out.println("Unknown Command"); |
|||
if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line, |
|||
travelEngine)) { |
|||
print(Colors.ANSI_RED + "Unbekannter Befehl - Siehe " + Colors.ANSI_PURPLE + "help\n" |
|||
+ Colors.ANSI_RESET); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public boolean print(String message) { |
|||
System.out.println(message); |
|||
return true; |
|||
} |
|||
|
|||
public boolean playerIsNew(String name) { |
|||
return name.equalsIgnoreCase("null"); |
|||
} |
|||
|
|||
public void newPlayerWelcome(TravelEngine travelEngine) { |
|||
print(Colors.ANSI_BLUE |
|||
+ "Oh, ein Fremder!\nBist du bereit für dein womöglich größtes Abenteuer?\nDann sag mir doch zunächst wie du heißt: " |
|||
+ Colors.ANSI_RESET); |
|||
String name = input.nextLine(); |
|||
JsonParser jp = new JsonParser(); |
|||
JSONObject playerconf = jp.getJSONObject("playerconfig.json"); |
|||
playerconf.put("name", name); |
|||
travelEngine.getPlayer().setName(name); |
|||
jp.writeObject("playerconfig.json", playerconf); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,69 @@ |
|||
package org.bitbiome.classes; |
|||
|
|||
import org.bitbiome.entities.Location; |
|||
import org.bitbiome.entities.Player; |
|||
import org.json.JSONArray; |
|||
import org.json.JSONObject; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
public class TravelEngine { |
|||
|
|||
private JSONArray locations; |
|||
private JsonParser jp; |
|||
private Player player; |
|||
|
|||
public TravelEngine(Player player) { |
|||
jp = new JsonParser(); |
|||
locations = jp.getJSONObject("gameconfig.json").getJSONArray("locations"); |
|||
this.player = player; |
|||
} |
|||
|
|||
public void travelTo(Location location) { |
|||
player.setLocation(location); |
|||
JSONObject jObj = jp.getJSONObject("playerconfig.json"); |
|||
jObj.put("currentLocation", location.getName()); |
|||
|
|||
jp.writeObject("playerconfig.json", jObj); |
|||
} |
|||
|
|||
public Player getPlayer() { |
|||
return player; |
|||
} |
|||
|
|||
public JSONArray getLocationList() { |
|||
return locations; |
|||
} |
|||
|
|||
public boolean locationExists(String name) { |
|||
boolean found = false; |
|||
for (int i = 0; i < locations.length(); i++) |
|||
if (locations.getJSONObject(i).getString("name").equals(name)) { |
|||
found = true; |
|||
} |
|||
return found; |
|||
} |
|||
|
|||
public Location getLocationByName(String name) { |
|||
JsonParser jp = new JsonParser(); |
|||
JSONObject gameconfig = jp.getJSONObject("gameconfig.json"); |
|||
JSONArray locations = gameconfig.getJSONArray("locations"); |
|||
JSONObject location = null; |
|||
if (locationExists(name)) { |
|||
for (int i = 0; i < locations.length(); i++) { |
|||
if (locations.getJSONObject(i).getString("name").equals(name)) { |
|||
location = locations.getJSONObject(i); |
|||
} |
|||
} |
|||
assert location != null; |
|||
//TODO Create Location by name and add mobs and times to the location |
|||
JSONArray items = location.getJSONArray("items"); |
|||
JSONArray mobs = location.getJSONArray("mobs"); |
|||
System.out.println(items.toString(1)); |
|||
System.out.println(mobs.toString(1)); |
|||
return new Location(name, new ArrayList<>(), new ArrayList<>()); |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
} |
@ -1,8 +1,14 @@ |
|||
package org.bitbiome.commands; |
|||
|
|||
import org.bitbiome.classes.TravelEngine; |
|||
|
|||
import java.util.Scanner; |
|||
|
|||
public interface CommandAPI { |
|||
public void performCommand(Scanner scanner, boolean isRunning, String message); |
|||
|
|||
// This is the command interface. Every command implements it's run method from here |
|||
// This is the API between the commands and the interaction loop/game |
|||
|
|||
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine); |
|||
|
|||
} |
@ -0,0 +1,18 @@ |
|||
package org.bitbiome.commands; |
|||
|
|||
import org.bitbiome.classes.TravelEngine; |
|||
|
|||
import java.util.Scanner; |
|||
|
|||
public class LocationCommand implements CommandAPI{ |
|||
|
|||
@Override |
|||
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { |
|||
System.out.println(getLocationMessage(travelEngine)); |
|||
} |
|||
|
|||
|
|||
public static String getLocationMessage(TravelEngine travelEngine) { |
|||
return "Du befindest dich gerade hier: " + travelEngine.getPlayer().getLocation().getName(); |
|||
} |
|||
} |
@ -0,0 +1,38 @@ |
|||
package org.bitbiome.commands; |
|||
|
|||
import org.bitbiome.classes.Colors; |
|||
|
|||
import org.bitbiome.classes.TravelEngine; |
|||
import org.bitbiome.entities.Item; |
|||
import org.bitbiome.entities.Location; |
|||
import org.bitbiome.entities.Mob; |
|||
import org.json.JSONArray; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Scanner; |
|||
|
|||
|
|||
public class TravelCommand implements CommandAPI { |
|||
|
|||
@Override |
|||
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { |
|||
print(Colors.ANSI_BLUE + "Du hast dein Travel-Pad gezückt. Wohin möchtest du reisen?" + Colors.ANSI_RESET); |
|||
JSONArray locations = travelEngine.getLocationList(); |
|||
for (int i = 0; i < locations.length(); i++) { |
|||
print("- " + locations.getJSONObject(i).getString("name")); |
|||
} |
|||
|
|||
String locationName = scanner.nextLine(); |
|||
if (travelEngine.locationExists(locationName)) { |
|||
travelEngine.travelTo(new Location(locationName, new ArrayList<Mob>(), new ArrayList<Item>())); |
|||
print(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); |
|||
} else { |
|||
print(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); |
|||
} |
|||
} |
|||
|
|||
public String print(String message) { |
|||
System.out.println(message); |
|||
return message; |
|||
} |
|||
} |
@ -0,0 +1,44 @@ |
|||
package org.bitbiome.entities; |
|||
|
|||
public class Item { |
|||
|
|||
private String name; |
|||
private boolean doesDamage; |
|||
private float damage; |
|||
|
|||
|
|||
public Item(String name, boolean doesDamage, float damage) { |
|||
this.name = name; |
|||
this.doesDamage = doesDamage; |
|||
this.damage = damage; |
|||
} |
|||
|
|||
public Item() { |
|||
|
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public float getDamage() { |
|||
return damage; |
|||
} |
|||
|
|||
public boolean doesDamage() { |
|||
return doesDamage; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public void setDamage(float damage) { |
|||
this.damage = damage; |
|||
} |
|||
|
|||
public void changeDoesDamage(boolean doesDamage) { |
|||
this.doesDamage = doesDamage; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,41 @@ |
|||
package org.bitbiome.entities; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
public class Location { |
|||
|
|||
private String name; |
|||
private ArrayList<Mob> mobList; |
|||
private ArrayList<Item> itemList; |
|||
|
|||
|
|||
public Location(String name, ArrayList<Mob> mobList, ArrayList<Item> itemList) { |
|||
this.name = name; |
|||
this.mobList = mobList; |
|||
this.itemList = itemList; |
|||
} |
|||
|
|||
public Location() { |
|||
|
|||
} |
|||
|
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public ArrayList<Mob> getMobList() { |
|||
return mobList; |
|||
} |
|||
|
|||
public ArrayList<Item> getItemList() { |
|||
return itemList; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,51 @@ |
|||
package org.bitbiome.entities; |
|||
|
|||
public class Mob { |
|||
|
|||
private String name; |
|||
private boolean isFriendly; |
|||
|
|||
private float hp; |
|||
private float damage; |
|||
|
|||
public Mob(String name, boolean isFriendly, float hp, float damage) { |
|||
this.name = name; |
|||
this.isFriendly = isFriendly; |
|||
this.hp = hp; |
|||
this.damage = damage; |
|||
} |
|||
|
|||
public Mob() { |
|||
|
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public boolean isFriendly() { |
|||
return isFriendly; |
|||
} |
|||
|
|||
public float getHp() { |
|||
return hp; |
|||
} |
|||
|
|||
public float getDamage() { |
|||
return damage; |
|||
} |
|||
|
|||
public void setDamage(float damage) { |
|||
this.damage = damage; |
|||
} |
|||
|
|||
public void setHp(float hp) { |
|||
this.hp = hp; |
|||
} |
|||
|
|||
public void setFriendly(boolean isFriendly) { |
|||
this.isFriendly = isFriendly; |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,65 @@ |
|||
package org.bitbiome.entities; |
|||
|
|||
|
|||
import org.bitbiome.classes.JsonParser; |
|||
|
|||
import java.util.ArrayList; |
|||
|
|||
public class Player { |
|||
private String name; |
|||
private float hp; |
|||
private Location location; |
|||
|
|||
private ArrayList<Item> inventory; |
|||
|
|||
private JsonParser jp; |
|||
|
|||
public Player(String name) { |
|||
jp = new JsonParser(); |
|||
this.name = name; |
|||
hp = 100.0F; |
|||
location = new Location(jp.getJSONObject("playerconfig.json").getString("currentLocation"), new ArrayList<>(), new ArrayList<>()); |
|||
inventory = new ArrayList<>(); |
|||
} |
|||
|
|||
public Player() { |
|||
|
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public ArrayList<Item> getInventory() { |
|||
return inventory; |
|||
} |
|||
|
|||
public float getHp() { |
|||
return hp; |
|||
} |
|||
|
|||
public Location getLocation() { |
|||
return location; |
|||
} |
|||
|
|||
public void setLocation(Location location) { |
|||
this.location = location; |
|||
} |
|||
|
|||
public void setHp(float hp) { |
|||
this.hp = hp; |
|||
} |
|||
|
|||
public boolean addToInventory(Item item) { |
|||
return inventory.add(item); |
|||
} |
|||
|
|||
public boolean removeFromInventory(Item item) { |
|||
return inventory.remove(item); |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,23 @@ |
|||
package org.bitbiome.classes; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
|
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
public class ColorsTest { |
|||
|
|||
@Test |
|||
public void testResetCode() { |
|||
assertEquals("\u001B[0m", Colors.ANSI_RESET); |
|||
} |
|||
|
|||
@Test |
|||
public void testBlueCode() { |
|||
assertEquals("\u001B[34m", Colors.ANSI_BLUE); |
|||
} |
|||
|
|||
@Test |
|||
public void testCyanCode() { |
|||
assertEquals("\u001B[36m", Colors.ANSI_CYAN); |
|||
} |
|||
} |
@ -1,14 +1,29 @@ |
|||
package org.bitbiome.commands; |
|||
|
|||
import org.bitbiome.classes.Colors; |
|||
import org.junit.jupiter.api.Test; |
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
|
|||
|
|||
public class HelpCommandTest { |
|||
|
|||
@Test |
|||
public void testHelpCommand() { |
|||
String helpMessage = HelpCommand.getHelpMessage(); |
|||
assertEquals("Hier ist eine Liste der Commands:\n- help -> Gibt diese Nachricht aus\n- exit/quit -> Beendet das Spiel\n", helpMessage); |
|||
StringBuilder outputMessage = new StringBuilder(); |
|||
outputMessage |
|||
.append("|______________|_____________________________|\n") |
|||
.append("|" + Colors.ANSI_PURPLE + " Command" + Colors.ANSI_RESET + " | " + Colors.ANSI_PURPLE + "Description" + Colors.ANSI_RESET + " |\n") |
|||
.append("|--------------|-----------------------------|\n") |
|||
.append("|" + Colors.ANSI_GREEN + " help" + Colors.ANSI_RESET + " | Gibt diese Nachricht aus |\n") |
|||
.append("|--------------|-----------------------------|\n") |
|||
.append("|" + Colors.ANSI_GREEN + " exit/quit" + Colors.ANSI_RESET + " | Beendet das Spiel |\n") |
|||
.append("|--------------|-----------------------------|\n") |
|||
.append("|" + Colors.ANSI_GREEN + " travel" + Colors.ANSI_RESET + " | Startet das Reise System |\n") |
|||
.append("|--------------|-----------------------------|\n") |
|||
.append("|" + Colors.ANSI_GREEN + " location" + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") |
|||
.append("|______________|_____________________________|\n"); |
|||
assertEquals(outputMessage.toString(), helpMessage); |
|||
} |
|||
|
|||
|
|||
|
@ -0,0 +1,22 @@ |
|||
package org.bitbiome.commands; |
|||
|
|||
import org.bitbiome.classes.TravelEngine; |
|||
import org.bitbiome.entities.Player; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue; |
|||
|
|||
import java.util.Arrays; |
|||
|
|||
public class LocationCommandTest { |
|||
|
|||
@Test |
|||
public void testLocationCommand() { |
|||
Player p = new Player("Unit"); |
|||
TravelEngine tE = new TravelEngine(p); |
|||
String[] standorte = {"Wald", "Strand"}; |
|||
String locationMessage = LocationCommand.getLocationMessage(tE).split(": ")[1]; |
|||
assertTrue(Arrays.asList(standorte).contains(locationMessage)); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,38 @@ |
|||
package org.bitbiome.entitiesTest; |
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
import static org.junit.jupiter.api.Assumptions.assumeTrue; |
|||
|
|||
import org.bitbiome.entities.Item; |
|||
import org.junit.jupiter.api.BeforeAll; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
|
|||
public class ItemTest { |
|||
|
|||
private static Item item; |
|||
|
|||
@BeforeAll |
|||
public static void setItem() { |
|||
item = new Item(); |
|||
item.setName("Unit"); |
|||
item.setDamage(12.5F); |
|||
item.changeDoesDamage(true); |
|||
} |
|||
|
|||
@Test |
|||
public void testGetName() { |
|||
assertEquals("Unit", item.getName()); |
|||
} |
|||
|
|||
@Test |
|||
public void testGetDamage() { |
|||
assertEquals(12.5, item.getDamage()); |
|||
} |
|||
|
|||
@Test |
|||
public void testDoesDamage() { |
|||
boolean doesDamage = item.doesDamage(); |
|||
assumeTrue(item.getDamage() > 0); |
|||
assumeTrue(doesDamage); |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
package org.bitbiome.entitiesTest; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
|
|||
import org.bitbiome.entities.Location; |
|||
import org.junit.jupiter.api.BeforeAll; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
public class LocationTest { |
|||
|
|||
private static Location location; |
|||
|
|||
|
|||
@BeforeAll |
|||
public static void setLocation() { |
|||
location = new Location(); |
|||
location.setName("NewUnitWorld"); |
|||
} |
|||
|
|||
@Test |
|||
public void testLocationName() { |
|||
assertEquals("NewUnitWorld", location.getName()); |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
package org.bitbiome.entitiesTest; |
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
import org.bitbiome.entities.Mob; |
|||
import org.junit.jupiter.api.BeforeAll; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
|
|||
public class MobTest { |
|||
|
|||
private static Mob mob; |
|||
|
|||
@BeforeAll |
|||
public static void setMob() { |
|||
mob = new Mob(); |
|||
mob.setFriendly(true); |
|||
mob.setDamage(0F); |
|||
mob.setHp(561.45F); |
|||
} |
|||
|
|||
|
|||
@Test |
|||
public void testFriendly() { |
|||
assertEquals(mob.isFriendly(), true); |
|||
} |
|||
|
|||
@Test |
|||
public void testDamage() { |
|||
assertEquals(mob.getDamage(), 0F); |
|||
} |
|||
|
|||
@Test |
|||
public void testHp() { |
|||
assertEquals(mob.getHp(), 561.45F); |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
package org.bitbiome.entitiesTest; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
|
|||
import org.bitbiome.entities.Location; |
|||
import org.bitbiome.entities.Player; |
|||
import org.junit.jupiter.api.BeforeAll; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
public class PlayerTest { |
|||
|
|||
private static Player player; |
|||
private static Location location; |
|||
|
|||
@BeforeAll |
|||
public static void setPlayer() { |
|||
player = new Player(); |
|||
location = new Location(); |
|||
|
|||
location.setName("NewUnitWorld"); |
|||
|
|||
player.setName("UnitPlayer"); |
|||
player.setLocation(location); |
|||
player.setHp(100F); |
|||
} |
|||
|
|||
@Test |
|||
public void testPlayerName() { |
|||
assertEquals("UnitPlayer", player.getName()); |
|||
} |
|||
|
|||
|
|||
@Test |
|||
public void testPlayerHp() { |
|||
assertEquals(100F, player.getHp()); |
|||
} |
|||
|
|||
@Test |
|||
public void testLocationNameFromPlayer() { |
|||
assertEquals("NewUnitWorld", player.getLocation().getName()); |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue