Browse Source

Merge branch 'develop' into quiz

remotes/origin/develop
David Hermann 2 years ago
parent
commit
42ff669bb6
  1. 16
      src/main/java/org/bitbiome/Boot.java
  2. 62
      src/main/java/org/bitbiome/classes/Colors.java
  3. 34
      src/main/java/org/bitbiome/classes/InteractionLoop.java
  4. 16
      src/main/java/org/bitbiome/classes/JsonParser.java
  5. 69
      src/main/java/org/bitbiome/classes/TravelEngine.java
  6. 8
      src/main/java/org/bitbiome/commands/CommandAPI.java
  7. 14
      src/main/java/org/bitbiome/commands/CommandListener.java
  8. 21
      src/main/java/org/bitbiome/commands/HelpCommand.java
  9. 18
      src/main/java/org/bitbiome/commands/LocationCommand.java
  10. 8
      src/main/java/org/bitbiome/commands/QuitCommand.java
  11. 38
      src/main/java/org/bitbiome/commands/TravelCommand.java
  12. 44
      src/main/java/org/bitbiome/entities/Item.java
  13. 41
      src/main/java/org/bitbiome/entities/Location.java
  14. 51
      src/main/java/org/bitbiome/entities/Mob.java
  15. 65
      src/main/java/org/bitbiome/entities/Player.java
  16. 17
      src/main/resources/gameconfig.json
  17. 23
      src/test/java/org/bitbiome/classes/ColorsTest.java
  18. 17
      src/test/java/org/bitbiome/commands/HelpCommandTest.java
  19. 22
      src/test/java/org/bitbiome/commands/LocationCommandTest.java
  20. 38
      src/test/java/org/bitbiome/entitiesTest/ItemTest.java
  21. 24
      src/test/java/org/bitbiome/entitiesTest/LocationTest.java
  22. 35
      src/test/java/org/bitbiome/entitiesTest/MobTest.java
  23. 43
      src/test/java/org/bitbiome/entitiesTest/PlayerTest.java

16
src/main/java/org/bitbiome/Boot.java

@ -1,7 +1,11 @@
package org.bitbiome; package org.bitbiome;
import org.bitbiome.classes.InteractionLoop; import org.bitbiome.classes.InteractionLoop;
import org.bitbiome.classes.JsonParser;
import org.bitbiome.classes.TravelEngine;
import org.bitbiome.commands.CommandListener; import org.bitbiome.commands.CommandListener;
import org.bitbiome.entities.Player;
import org.json.JSONObject;
public class Boot { public class Boot {
@ -11,13 +15,23 @@ public class Boot {
instance = this; instance = this;
cmdListener = new CommandListener(); cmdListener = new CommandListener();
InteractionLoop game = new InteractionLoop(); InteractionLoop game = new InteractionLoop();
game.run();
Player player = getPlayerSave();
TravelEngine travelEngine = new TravelEngine(player);
game.run(travelEngine);
} }
public CommandListener getCmdListener(){ public CommandListener getCmdListener(){
return cmdListener; return cmdListener;
} }
private Player getPlayerSave() {
String name;
JsonParser jp = new JsonParser();
JSONObject playerconfig = jp.getJSONObject("playerconfig.json");
name = playerconfig.getString("name");
return new Player(name);
}
} }

62
src/main/java/org/bitbiome/classes/Colors.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 };
}

34
src/main/java/org/bitbiome/classes/InteractionLoop.java

@ -1,23 +1,49 @@
package org.bitbiome.classes; package org.bitbiome.classes;
import org.bitbiome.Boot; import org.bitbiome.Boot;
import org.json.JSONObject;
import java.util.Scanner; import java.util.Scanner;
public class InteractionLoop { public class InteractionLoop {
Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
public void run() {
public void run(TravelEngine travelEngine) {
boolean isRunning = true; 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) { while (isRunning) {
String line = input.nextLine().toLowerCase(); 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);
}
} }

16
src/main/java/org/bitbiome/classes/JsonParser.java

@ -3,9 +3,9 @@ package org.bitbiome.classes;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONTokener; import org.json.JSONTokener;
import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.FileReader;
import java.io.InputStream; import java.io.InputStream;
@ -58,4 +58,18 @@ public class JsonParser {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public void writeObject(String fileName, JSONObject object) {
String resourceName = System.getProperty("user.dir") + "/src/main/resources/" + fileName;
try {
FileWriter fw = new FileWriter(resourceName, false);
fw.write(object.toString(1));
fw.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
} }

69
src/main/java/org/bitbiome/classes/TravelEngine.java

@ -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;
}
}
}

8
src/main/java/org/bitbiome/commands/CommandAPI.java

@ -1,8 +1,14 @@
package org.bitbiome.commands; package org.bitbiome.commands;
import org.bitbiome.classes.TravelEngine;
import java.util.Scanner; import java.util.Scanner;
public interface CommandAPI { 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);
} }

14
src/main/java/org/bitbiome/commands/CommandListener.java

@ -1,11 +1,15 @@
package org.bitbiome.commands; package org.bitbiome.commands;
import org.bitbiome.classes.TravelEngine;
import java.util.HashMap; import java.util.HashMap;
import java.util.Scanner; import java.util.Scanner;
public class CommandListener { public class CommandListener {
private final HashMap<String, CommandAPI> commands;
// This class is the API between the command interface and the user input
// This class is used to handle all the commands
// The commands are stored in a hashmap
private HashMap<String, CommandAPI> commands;
public CommandListener() { public CommandListener() {
commands = new HashMap<>(); commands = new HashMap<>();
@ -14,16 +18,18 @@ public class CommandListener {
commands.put("exit", new QuitCommand()); commands.put("exit", new QuitCommand());
commands.put("quit", new QuitCommand()); commands.put("quit", new QuitCommand());
commands.put("location", new LocationCommand());
commands.put("travel", new TravelCommand());
commands.put("quiz", new QuizCommand()); commands.put("quiz", new QuizCommand());
commands.put("blackjack", new BlackJackCommand()); commands.put("blackjack", new BlackJackCommand());
} }
public boolean perform(String command, Scanner scanner, boolean isRunning, String message) {
public boolean perform(String command, Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
CommandAPI cmd; CommandAPI cmd;
if ((cmd = commands.get(command)) != null) { if ((cmd = commands.get(command)) != null) {
cmd.performCommand(scanner, isRunning, message);
cmd.performCommand(scanner, isRunning, message, travelEngine);
return true; return true;
} }
return false; return false;

21
src/main/java/org/bitbiome/commands/HelpCommand.java

@ -1,21 +1,34 @@
package org.bitbiome.commands; package org.bitbiome.commands;
import org.bitbiome.Boot;
import java.util.HashMap;
import org.bitbiome.classes.Colors;
import org.bitbiome.classes.TravelEngine;
import java.util.Scanner; import java.util.Scanner;
public class HelpCommand implements CommandAPI { public class HelpCommand implements CommandAPI {
@Override @Override
public void performCommand(Scanner scanner, boolean isRunning, String message) {
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
System.out.println(getHelpMessage()); System.out.println(getHelpMessage());
} }
public static String getHelpMessage() { public static String getHelpMessage() {
StringBuilder outputMessage = new StringBuilder(); StringBuilder outputMessage = new StringBuilder();
outputMessage.append("Hier ist eine Liste der Commands:\n").append("- help -> Gibt diese Nachricht aus\n").append("- exit/quit -> Beendet das Spiel\n");
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");
return outputMessage.toString(); return outputMessage.toString();
} }

18
src/main/java/org/bitbiome/commands/LocationCommand.java

@ -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();
}
}

8
src/main/java/org/bitbiome/commands/QuitCommand.java

@ -1,11 +1,17 @@
package org.bitbiome.commands; package org.bitbiome.commands;
import org.bitbiome.classes.TravelEngine;
import java.util.Scanner; import java.util.Scanner;
public class QuitCommand implements CommandAPI { public class QuitCommand implements CommandAPI {
// This command is used to end the game via command
// When the player quits the game, the game is stopped through System.exit(0)
// That means it is exited with no error status
@Override @Override
public void performCommand(Scanner scanner, boolean isRunning, String message) {
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
System.out.println(getQuitMessage()); System.out.println(getQuitMessage());
System.exit(0); System.exit(0);
} }

38
src/main/java/org/bitbiome/commands/TravelCommand.java

@ -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;
}
}

44
src/main/java/org/bitbiome/entities/Item.java

@ -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;
}
}

41
src/main/java/org/bitbiome/entities/Location.java

@ -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;
}
}

51
src/main/java/org/bitbiome/entities/Mob.java

@ -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;
}
}

65
src/main/java/org/bitbiome/entities/Player.java

@ -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;
}
}

17
src/main/resources/gameconfig.json

@ -33,6 +33,23 @@
] ]
} }
] ]
},
{
"name": "Strand",
"items": [
"Holz",
"Stein"
],
"mobs": [
{
"name": "Big Foot",
"hp": 50,
"damage": "10-15",
"items": [
"Fell"
]
}
]
} }
] ]
} }

23
src/test/java/org/bitbiome/classes/ColorsTest.java

@ -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);
}
}

17
src/test/java/org/bitbiome/commands/HelpCommandTest.java

@ -1,14 +1,29 @@
package org.bitbiome.commands; package org.bitbiome.commands;
import org.bitbiome.classes.Colors;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class HelpCommandTest { public class HelpCommandTest {
@Test @Test
public void testHelpCommand() { public void testHelpCommand() {
String helpMessage = HelpCommand.getHelpMessage(); 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);
} }

22
src/test/java/org/bitbiome/commands/LocationCommandTest.java

@ -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));
}
}

38
src/test/java/org/bitbiome/entitiesTest/ItemTest.java

@ -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);
}
}

24
src/test/java/org/bitbiome/entitiesTest/LocationTest.java

@ -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());
}
}

35
src/test/java/org/bitbiome/entitiesTest/MobTest.java

@ -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);
}
}

43
src/test/java/org/bitbiome/entitiesTest/PlayerTest.java

@ -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());
}
}
Loading…
Cancel
Save