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..d08f59e --- /dev/null +++ b/src/main/java/org/bitbiome/classes/Colors.java @@ -0,0 +1,56 @@ +package org.bitbiome.classes; + +public class 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/CreateLocations.java b/src/main/java/org/bitbiome/classes/CreateLocations.java new file mode 100644 index 0000000..ed237a1 --- /dev/null +++ b/src/main/java/org/bitbiome/classes/CreateLocations.java @@ -0,0 +1,24 @@ +package org.bitbiome.classes; + +import org.bitbiome.entities.Item; +import org.bitbiome.entities.Location; +import org.bitbiome.entities.Mob; + +import java.util.ArrayList; + +public class CreateLocations { + + public static Location createForest() { + ArrayList items = new ArrayList<>(); + ArrayList mobs = new ArrayList<>(); + String name = "Wald"; + return new Location(name, mobs, items); + } + + public static Location createBeach() { + ArrayList items = new ArrayList<>(); + ArrayList mobs = new ArrayList<>(); + String name = "Strand"; + return new Location(name, mobs, items); + } +} diff --git a/src/main/java/org/bitbiome/classes/InteractionLoop.java b/src/main/java/org/bitbiome/classes/InteractionLoop.java index 6566b0a..2523644 100644 --- a/src/main/java/org/bitbiome/classes/InteractionLoop.java +++ b/src/main/java/org/bitbiome/classes/InteractionLoop.java @@ -1,18 +1,28 @@ 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 (travelEngine.getPlayer().getName().equals("null")) { + System.out.println(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); + } + System.out.println(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)) { + if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line, travelEngine)) { System.out.println("Unknown Command"); } } diff --git a/src/main/java/org/bitbiome/classes/JsonParser.java b/src/main/java/org/bitbiome/classes/JsonParser.java index be0e9b8..0eb23d5 100644 --- a/src/main/java/org/bitbiome/classes/JsonParser.java +++ b/src/main/java/org/bitbiome/classes/JsonParser.java @@ -2,8 +2,14 @@ package org.bitbiome.classes; import org.json.JSONObject; import org.json.JSONTokener; +import org.json.JSONWriter; +import java.io.FileWriter; +import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; + + public class JsonParser { @@ -22,15 +28,28 @@ public class JsonParser { https://github.com/stleary/JSON-java */ - public static JSONObject getJSONObject(String fileName) { - String resourceName = "./../../" + fileName; + public JSONObject getJSONObject(String fileName) { + String resourceName = "./../../../" + fileName; InputStream is = JsonParser.class.getResourceAsStream(resourceName); if (is == null) { throw new NullPointerException("Cannot find resource file " + resourceName); } JSONTokener tokener = new JSONTokener(is); - return new JSONObject(tokener); } + + 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..a5c48be 100644 --- a/src/main/java/org/bitbiome/commands/CommandAPI.java +++ b/src/main/java/org/bitbiome/commands/CommandAPI.java @@ -1,8 +1,10 @@ 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); + 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 545eae9..4c67d71 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -1,5 +1,7 @@ package org.bitbiome.commands; +import org.bitbiome.classes.TravelEngine; + import java.util.HashMap; import java.util.Scanner; @@ -16,6 +18,8 @@ public class CommandListener { commands.put("quit", new QuitCommand()); commands.put("use", new UseCommand()); + commands.put("location", new LocationCommand()); + commands.put("travel", new TravelCommand()); } public HashMap returnCommands() { @@ -23,11 +27,11 @@ public class CommandListener { } - 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 f4439df..90702cc 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -1,18 +1,34 @@ package org.bitbiome.commands; +import org.bitbiome.Boot; +import org.bitbiome.classes.Colors; +import org.bitbiome.classes.TravelEngine; + +import java.util.HashMap; 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..25dbb00 100644 --- a/src/main/java/org/bitbiome/commands/QuitCommand.java +++ b/src/main/java/org/bitbiome/commands/QuitCommand.java @@ -1,11 +1,13 @@ package org.bitbiome.commands; +import org.bitbiome.classes.TravelEngine; + import java.util.Scanner; public class QuitCommand 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(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..ca68bf5 --- /dev/null +++ b/src/main/java/org/bitbiome/commands/TravelCommand.java @@ -0,0 +1,33 @@ +package org.bitbiome.commands; + +import org.bitbiome.classes.Colors; +import org.bitbiome.classes.CreateLocations; +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) { + System.out.println(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++) { + System.out.println("- " + locations.getJSONObject(i).getString("name")); + } + + String locationName = scanner.nextLine(); + if (travelEngine.locationExists(locationName)) { + travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); + System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); + } else { + System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + } + } +} diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index ceef595..61eb376 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -3,11 +3,12 @@ package org.bitbiome.commands; import java.util.Scanner; import org.bitbiome.classes.JsonParser; +import org.bitbiome.classes.TravelEngine; import org.json.*; public class UseCommand implements CommandAPI { @Override - public void performCommand(Scanner scanner, boolean isRunning, String message) { + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { System.out.println(getUseMessage(message.split(" ", 2)[1])); } @@ -15,13 +16,14 @@ public class UseCommand implements CommandAPI { String message[] = msg.split(" on "); String itemName = message[0]; JSONObject item = getItem(itemName), target; + JsonParser p = new JsonParser(); if(item == null) return "You don't have that item."; if(item.getBoolean("attack")) return "You can't attack with this."; if(message.length == 1) - target = JsonParser.getJSONObject("playerconfig.json"); + target = p.getJSONObject("playerconfig.json"); else target = getTarget(message[1]); if(target == null) @@ -34,7 +36,8 @@ public class UseCommand implements CommandAPI { } private JSONObject getItem(String item) { - JSONArray inventory = JsonParser.getJSONObject("playerconfig.json").getJSONArray("inventory"); + JsonParser p = new JsonParser(); + JSONArray inventory = p.getJSONObject("playerconfig.json").getJSONArray("inventory"); for(int i = 0; i < inventory.length(); i++) { JSONObject currentItem = inventory.getJSONObject(i); if(currentItem.getString("name").equals(item)) @@ -44,8 +47,9 @@ public class UseCommand implements CommandAPI { } private JSONObject getTarget(String target) { - String currentLocation = JsonParser.getJSONObject("playerconfig").getString("currentLocation"); - JSONArray locations = JsonParser.getJSONObject("gameconfig").getJSONArray("locations"); + JsonParser p = new JsonParser(); + String currentLocation = p.getJSONObject("playerconfig").getString("currentLocation"); + JSONArray locations = p.getJSONObject("gameconfig").getJSONArray("locations"); for(int i = 0; i < locations.length(); i++) { JSONObject location = locations.getJSONObject(i); if(locations.getJSONObject(i).getString("name").equals(currentLocation)) { 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..2817cd5 --- /dev/null +++ b/src/main/java/org/bitbiome/entities/Item.java @@ -0,0 +1,40 @@ +package org.bitbiome.entities; + +public class Item { + + public String name; + public boolean doesDamage; + public float damage; + + + public Item(String name, boolean doesDamage, float damage) { + this.name = name; + this.doesDamage = doesDamage; + this.damage = damage; + } + + 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..98c04d1 --- /dev/null +++ b/src/main/java/org/bitbiome/entities/Location.java @@ -0,0 +1,33 @@ +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 String getName() { + return name; + } + + public ArrayList getMobList() { + return mobList; + } + + public ArrayList getItemList() { + return itemList; + } + + + +} 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..af479ce --- /dev/null +++ b/src/main/java/org/bitbiome/entities/Mob.java @@ -0,0 +1,47 @@ +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 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..6fe3152 --- /dev/null +++ b/src/main/java/org/bitbiome/entities/Player.java @@ -0,0 +1,61 @@ +package org.bitbiome.entities; + +import org.bitbiome.classes.CreateLocations; +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 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/main/resources/quiz.json b/src/main/resources/quiz.json new file mode 100644 index 0000000..cc58a3f --- /dev/null +++ b/src/main/resources/quiz.json @@ -0,0 +1,204 @@ +{ + "Quiz": [ + { + "frage": "Wie lang ist der Äquator der Erde?", + "antworten": [ + "20.000m", + "30km", + "60.000km", + "40.000km" + ], + "korrekteAntwort": "40.000km" + }, + { + "frage": "Was ist der längste Fluss der Welt?", + "antworten": [ + "Amazonas", + "Nil", + "Rhein", + "Niger" + ], + "korrekteAntwort": "Nil" + }, + { + "frage": "Wie viele Tasten hat ein Klavier?", + "antworten": [ + "74", + "86", + "82", + "88" + ], + "korrekteAntwort": "88" + }, + { + "frage": "Von wem wird der Bundespräsident gewählt?", + "antworten": [ + "Vom Europäischen Parlament", + "Vom Bundeskanzler", + "Vom Bundestag", + "Von der Bundesversammlung" + ], + "korrekteAntwort": "von der Bundesversammlung" + }, + { + "frage": "Welches Land produziert jährlich die meisten Filme?", + "antworten": [ + "USA", + "Indien", + "Japan", + "Nigeria" + ], + "korrekteAntwort": "Indien" + }, + { + "frage": "Wie heißt der am schnellsten schwimmende Fisch auf Erden?", + "antworten": [ + "Flugfisch", + "Tigerhai", + "Segelfisch", + "Windfisch" + ], + "korrekteAntwort": "Segelfisch" + }, + { + "frage": "Was ist KEIN Gewächs?", + "antworten": [ + "Geranie", + "Moosfarn", + "Incolornis", + "Strandflieder" + ], + "korrekteAntwort": "Incolornis" + }, + { + "frage": "Was nutzt eine Fledermaus zur Orientierung in der Luft?", + "antworten": [ + "Infrarot", + "Röntgenstrahlen", + "Speichel", + "Ultraschall" + ], + "korrekteAntwort": "Ultraschall" + }, + { + "frage": "Von wem stammt der berühmte Satz: 'Ich denke, also bin ich'?", + "antworten": [ + "John Fitzgerald Kennedy", + "George Walker Bush", + "René Descartes", + "Julius Caesar" + ], + "korrekteAntwort": "René Descartes" + }, + { + "frage": "Welches Lebensmittel enthält das meiste Wasser?", + "antworten": [ + "Gurke", + "Wassermelone", + "Zitrone", + "Paprika" + ], + "korrekteAntwort": "Gurke" + }, + { + "frage": "Welches Lebensmittel gehört im botanischen Sinne zu den Früchten?", + "antworten": [ + "Möhre", + "Kartoffel", + "Tomate", + "Weißkohl" + ], + "korrekteAntwort": "Tomate" + }, + { + "frage": "Haptische Wahrnehmung beruht auf dem...?", + "antworten": [ + "Greifreflex", + "Gleichgewichtssinn", + "Hörsinn", + "Tastsinn" + ], + "korrekteAntwort": "Tastsinn" + }, + { + "frage": "Wie nennt man den letzten Tanz einer Tanzveranstaltung?", + "antworten": [ + "Voraus", + "Garaus", + "Kehraus", + "Durchaus" + ], + "korrekteAntwort": "Kehraus" + }, + { + "frage": "Wie nennt man ein tiefes, enges Tal, durch das ein Gebirgsbach fließt?", + "antworten": [ + "Klamm", + "Feucht", + "Nass", + "Schwamm" + ], + "korrekteAntwort": "Klamm" + }, + { + "frage": "Wer oder was ist Gerbera?", + "antworten": [ + "eine europäische Landschaft", + "eine Pflanze", + "die erste Präsidentin von Südafrika", + "eine Stadt in Lichtenstein" + ], + "korrekteAntwort": "eine Pflanze" + }, + { + "frage": "Nach wem wurde ein Gesellschaftsanzug benannt?", + "antworten": [ + "Richard von Weizsäcker", + "Gustav Heinemann", + "Jürgen Klinsmann", + "Gustav Stresemann" + ], + "korrekteAntwort": "Gustav Stresemann" + }, + { + "frage": "Was ist Speckstein?", + "antworten": [ + "eine Fischart, die sich als Stein tarnt", + "ein Gericht aus dem Mittelalter", + "eine Skulptur im Römischen Reich unter Nero", + "ein besonders weicher Stein" + ], + "korrekteAntwort": "ein besonders weicher Stein" + }, + { + "frage": "In welcher Religion gibt es Gurus?", + "antworten": [ + "im Christentum", + "im Hinduismus", + "im Islam", + "im Judentum" + ], + "korrekteAntwort": "im Hinduismus" + }, + { + "frage": "Was versteht man unter Brunsbüttel?", + "antworten": [ + "eine Industriestadt an der Unterelbe", + "einen Plakatkleber", + "eine 630 Mark-Kraft", + "ein Staatssekretär" + ], + "korrekteAntwort": "eine Industriestadt an der Unterelbe" + }, + { + "frage": "Welcher im 11. Jahrhundert gegründeter Orden rettet und pfelgt auch noch heute Verletzte und Kranke?", + "antworten": [ + "die Dominikaner", + "die Augustiner", + "die Zisterzienser", + "die Johanniter" + ], + "korrekteAntwort": "die Johanniter" + } + ] +} \ No newline at end of file diff --git a/src/test/java/org/bitbiome/commands/HelpCommandTest.java b/src/test/java/org/bitbiome/commands/HelpCommandTest.java index 75006ed..dab4d90 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; +import static org.junit.jupiter.api.Assertions.assertTrue; 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)); + } + +}