diff --git a/src/main/java/org/bitbiome/Boot.java b/src/main/java/org/bitbiome/Boot.java index b264413..0f5ebdd 100644 --- a/src/main/java/org/bitbiome/Boot.java +++ b/src/main/java/org/bitbiome/Boot.java @@ -1,7 +1,11 @@ package org.bitbiome; import org.bitbiome.classes.InteractionLoop; +import org.bitbiome.classes.JsonParser; +import org.bitbiome.classes.TravelEngine; import org.bitbiome.commands.CommandListener; +import org.bitbiome.entities.Player; +import org.json.JSONObject; public class Boot { @@ -11,13 +15,23 @@ public class Boot { instance = this; cmdListener = new CommandListener(); InteractionLoop game = new InteractionLoop(); - game.run(); + Player player = getPlayerSave(); + TravelEngine travelEngine = new TravelEngine(player); + game.run(travelEngine); } public CommandListener getCmdListener(){ 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); + } + } diff --git a/src/main/java/org/bitbiome/classes/Colors.java b/src/main/java/org/bitbiome/classes/Colors.java new file mode 100644 index 0000000..99e45e1 --- /dev/null +++ b/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 }; + +} diff --git a/src/main/java/org/bitbiome/classes/InteractionLoop.java b/src/main/java/org/bitbiome/classes/InteractionLoop.java index 6566b0a..f8a6c84 100644 --- a/src/main/java/org/bitbiome/classes/InteractionLoop.java +++ b/src/main/java/org/bitbiome/classes/InteractionLoop.java @@ -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); + } } diff --git a/src/main/java/org/bitbiome/classes/JsonParser.java b/src/main/java/org/bitbiome/classes/JsonParser.java index 66dc79c..e7ad5b7 100644 --- a/src/main/java/org/bitbiome/classes/JsonParser.java +++ b/src/main/java/org/bitbiome/classes/JsonParser.java @@ -3,9 +3,9 @@ package org.bitbiome.classes; import org.json.JSONObject; import org.json.JSONTokener; -import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.FileReader; import java.io.InputStream; @@ -58,4 +58,18 @@ public class JsonParser { 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); + } + + + } } diff --git a/src/main/java/org/bitbiome/classes/TravelEngine.java b/src/main/java/org/bitbiome/classes/TravelEngine.java new file mode 100644 index 0000000..a8d3213 --- /dev/null +++ b/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; + } + } +} diff --git a/src/main/java/org/bitbiome/commands/CommandAPI.java b/src/main/java/org/bitbiome/commands/CommandAPI.java index d3a67c6..9e5ade8 100644 --- a/src/main/java/org/bitbiome/commands/CommandAPI.java +++ b/src/main/java/org/bitbiome/commands/CommandAPI.java @@ -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); } diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index fdb5ce4..38785d8 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -1,11 +1,15 @@ package org.bitbiome.commands; +import org.bitbiome.classes.TravelEngine; + import java.util.HashMap; import java.util.Scanner; public class CommandListener { - - private final HashMap 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 commands; public CommandListener() { commands = new HashMap<>(); @@ -14,16 +18,18 @@ public class CommandListener { commands.put("exit", new QuitCommand()); commands.put("quit", new QuitCommand()); + commands.put("location", new LocationCommand()); + commands.put("travel", new TravelCommand()); commands.put("quiz", new QuizCommand()); 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; if ((cmd = commands.get(command)) != null) { - cmd.performCommand(scanner, isRunning, message); + cmd.performCommand(scanner, isRunning, message, travelEngine); return true; } return false; diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java index 4d88e3a..ee4f237 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -1,21 +1,34 @@ 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; public class HelpCommand implements CommandAPI { @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()); } public static String getHelpMessage() { 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(); } diff --git a/src/main/java/org/bitbiome/commands/LocationCommand.java b/src/main/java/org/bitbiome/commands/LocationCommand.java new file mode 100644 index 0000000..cbbca02 --- /dev/null +++ b/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(); + } +} diff --git a/src/main/java/org/bitbiome/commands/QuitCommand.java b/src/main/java/org/bitbiome/commands/QuitCommand.java index d969852..258ab1a 100644 --- a/src/main/java/org/bitbiome/commands/QuitCommand.java +++ b/src/main/java/org/bitbiome/commands/QuitCommand.java @@ -1,11 +1,17 @@ package org.bitbiome.commands; +import org.bitbiome.classes.TravelEngine; + import java.util.Scanner; 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 - 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.exit(0); } diff --git a/src/main/java/org/bitbiome/commands/TravelCommand.java b/src/main/java/org/bitbiome/commands/TravelCommand.java new file mode 100644 index 0000000..810333e --- /dev/null +++ b/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(), new ArrayList())); + 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; + } +} diff --git a/src/main/java/org/bitbiome/entities/Item.java b/src/main/java/org/bitbiome/entities/Item.java new file mode 100644 index 0000000..0ded3ff --- /dev/null +++ b/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; + } + +} diff --git a/src/main/java/org/bitbiome/entities/Location.java b/src/main/java/org/bitbiome/entities/Location.java new file mode 100644 index 0000000..664509d --- /dev/null +++ b/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 mobList; + private ArrayList itemList; + + + public Location(String name, ArrayList mobList, ArrayList itemList) { + this.name = name; + this.mobList = mobList; + this.itemList = itemList; + } + + public Location() { + + } + + + public String getName() { + return name; + } + + public ArrayList getMobList() { + return mobList; + } + + public ArrayList getItemList() { + return itemList; + } + + public void setName(String name) { + this.name = name; + } + + + +} diff --git a/src/main/java/org/bitbiome/entities/Mob.java b/src/main/java/org/bitbiome/entities/Mob.java new file mode 100644 index 0000000..4bb0d03 --- /dev/null +++ b/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; + } + + +} diff --git a/src/main/java/org/bitbiome/entities/Player.java b/src/main/java/org/bitbiome/entities/Player.java new file mode 100644 index 0000000..3d46e17 --- /dev/null +++ b/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 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 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; + } + +} diff --git a/src/main/resources/gameconfig.json b/src/main/resources/gameconfig.json index a29ef19..cb08775 100644 --- a/src/main/resources/gameconfig.json +++ b/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" + ] + } + ] } ] } \ No newline at end of file diff --git a/src/test/java/org/bitbiome/classes/ColorsTest.java b/src/test/java/org/bitbiome/classes/ColorsTest.java new file mode 100644 index 0000000..541ebdf --- /dev/null +++ b/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); + } +} diff --git a/src/test/java/org/bitbiome/commands/HelpCommandTest.java b/src/test/java/org/bitbiome/commands/HelpCommandTest.java index 75006ed..5caac07 100644 --- a/src/test/java/org/bitbiome/commands/HelpCommandTest.java +++ b/src/test/java/org/bitbiome/commands/HelpCommandTest.java @@ -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); } diff --git a/src/test/java/org/bitbiome/commands/LocationCommandTest.java b/src/test/java/org/bitbiome/commands/LocationCommandTest.java new file mode 100644 index 0000000..23c6541 --- /dev/null +++ b/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)); + } + +} diff --git a/src/test/java/org/bitbiome/entitiesTest/ItemTest.java b/src/test/java/org/bitbiome/entitiesTest/ItemTest.java new file mode 100644 index 0000000..4214043 --- /dev/null +++ b/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); + } +} diff --git a/src/test/java/org/bitbiome/entitiesTest/LocationTest.java b/src/test/java/org/bitbiome/entitiesTest/LocationTest.java new file mode 100644 index 0000000..1ae0575 --- /dev/null +++ b/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()); + } +} diff --git a/src/test/java/org/bitbiome/entitiesTest/MobTest.java b/src/test/java/org/bitbiome/entitiesTest/MobTest.java new file mode 100644 index 0000000..00afaf8 --- /dev/null +++ b/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); + } +} diff --git a/src/test/java/org/bitbiome/entitiesTest/PlayerTest.java b/src/test/java/org/bitbiome/entitiesTest/PlayerTest.java new file mode 100644 index 0000000..2205e95 --- /dev/null +++ b/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()); + } + +}