From 1e20ed46212dfe6dabb094a69d834c57dbd1179e Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 11:18:27 +0100 Subject: [PATCH 01/53] Create InventoryCommand Create InventoryCommand --- .../java/org/bitbiome/commands/InventoryCommand.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/org/bitbiome/commands/InventoryCommand.java diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java new file mode 100644 index 0000000..81e7295 --- /dev/null +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -0,0 +1,12 @@ +package org.bitbiome.commands; + +import org.bitbiome.classes.TravelEngine; + +import java.util.Scanner; + +public class InventoryCommand implements CommandAPI{ + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + + } +} From 14cbe43890e59f02bfb9351169867753e9195512 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 11:44:51 +0100 Subject: [PATCH 02/53] added readInv() --- src/main/java/org/bitbiome/commands/InventoryCommand.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java index 81e7295..7e407ab 100644 --- a/src/main/java/org/bitbiome/commands/InventoryCommand.java +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -7,6 +7,9 @@ import java.util.Scanner; public class InventoryCommand implements CommandAPI{ @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { - + + } + public String readInv(TravelEngine travelEngine){ + return ""; } } From 0936d9f39c477759b8f528f08d7c8e0b9dc6fadb Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 11:45:48 +0100 Subject: [PATCH 03/53] implementing readInv() --- src/main/java/org/bitbiome/commands/InventoryCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java index 7e407ab..6d4e83b 100644 --- a/src/main/java/org/bitbiome/commands/InventoryCommand.java +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -7,7 +7,7 @@ import java.util.Scanner; public class InventoryCommand implements CommandAPI{ @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { - + System.out.println(readInv(travelEngine)); } public String readInv(TravelEngine travelEngine){ return ""; From 3a54eff3082b414e22b2e41db49d8ec43f8d9c1b Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 12:13:33 +0100 Subject: [PATCH 04/53] edited method readInv() puts inventory out --- .../bitbiome/commands/InventoryCommand.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java index 6d4e83b..da14945 100644 --- a/src/main/java/org/bitbiome/commands/InventoryCommand.java +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -1,15 +1,31 @@ package org.bitbiome.commands; +import org.bitbiome.classes.JsonParser; import org.bitbiome.classes.TravelEngine; +import org.bitbiome.entities.Item; +import org.json.JSONObject; +import java.util.ArrayList; import java.util.Scanner; -public class InventoryCommand implements CommandAPI{ +public class InventoryCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + System.out.println(readInv(travelEngine)); } - public String readInv(TravelEngine travelEngine){ - return ""; + + public String readInv(TravelEngine travelEngine) { + StringBuilder s = new StringBuilder(); + JsonParser jp = new JsonParser(); + JSONObject o = jp.getJSONObject("playerconfig.json"); + + ArrayList inventory = travelEngine.getPlayer().getInventory(); + s.append("Inventory: \n"); + for (int i=0; i < inventory.size(); i++){ + s.append("- ").append(inventory.get(i).getName()).append("\n"); + } + + return s.toString(); } -} +} \ No newline at end of file From fed6f0b61c227f157e43249603dd04e43bc4b1bd Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 12:54:50 +0100 Subject: [PATCH 05/53] added amount to item.java added amount of items to constructor --- src/main/java/org/bitbiome/entities/Item.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/entities/Item.java b/src/main/java/org/bitbiome/entities/Item.java index 2817cd5..be02837 100644 --- a/src/main/java/org/bitbiome/entities/Item.java +++ b/src/main/java/org/bitbiome/entities/Item.java @@ -3,14 +3,16 @@ package org.bitbiome.entities; public class Item { public String name; + public int amount; public boolean doesDamage; public float damage; - public Item(String name, boolean doesDamage, float damage) { + public Item(String name, boolean doesDamage, float damage, int amount) { this.name = name; this.doesDamage = doesDamage; this.damage = damage; + this.amount = amount; } public String getName() { From f71eae31a1714a1fc31da0f53c2aa283b012adab Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 12:58:36 +0100 Subject: [PATCH 06/53] added methods getAmount() and setAmount() to item.java --- src/main/java/org/bitbiome/entities/Item.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/bitbiome/entities/Item.java b/src/main/java/org/bitbiome/entities/Item.java index be02837..f0da23a 100644 --- a/src/main/java/org/bitbiome/entities/Item.java +++ b/src/main/java/org/bitbiome/entities/Item.java @@ -38,5 +38,12 @@ public class Item { public void changeDoesDamage(boolean doesDamage) { this.doesDamage = doesDamage; } + public int getAmount(){ + return amount; + } + public void setAmount(int amount){ + this.amount = amount; + } + } From e7f156b1aff33c7f71760ec27192d3653dd82860 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:16:11 +0100 Subject: [PATCH 07/53] added damage and doesDamage to playerconfig --- src/main/resources/playerconfig.json | 35 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/resources/playerconfig.json b/src/main/resources/playerconfig.json index 1a2c55e..59af4e6 100644 --- a/src/main/resources/playerconfig.json +++ b/src/main/resources/playerconfig.json @@ -1,17 +1,22 @@ { - "name": "null", - "gold": 0, - "hp": 10, - "currentLocation": "Wald", - "inventory": [ - { - "name": "Holz", - "amount": "5", - "durability": 1000 - },{ - "name": "Stein", - "amount": "5", - "durability": 1000 - } - ] + "gold": 0, + "name": "null", + "hp": 10, + "inventory": [ + { + "damage": 10, + "amount": 5, + "durability": 1000, + "name": "Holz", + "doesDamage": true + }, + { + "damage": 10, + "amount": 5, + "durability": 1000, + "name": "Stein", + "doesDamage": true + } + ], + "currentLocation": "Wald" } \ No newline at end of file From c204733e70040700ee29fae63ff9a3f0e4bef08e Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:18:51 +0100 Subject: [PATCH 08/53] edited player constructor added to arrayList inventory the items of file playerconfig --- src/main/java/org/bitbiome/entities/Player.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/org/bitbiome/entities/Player.java b/src/main/java/org/bitbiome/entities/Player.java index 6fe3152..7fc9623 100644 --- a/src/main/java/org/bitbiome/entities/Player.java +++ b/src/main/java/org/bitbiome/entities/Player.java @@ -2,6 +2,9 @@ package org.bitbiome.entities; import org.bitbiome.classes.CreateLocations; import org.bitbiome.classes.JsonParser; +import org.json.JSONArray; +import org.json.JSONObject; + import java.util.ArrayList; @@ -20,6 +23,14 @@ public class Player { hp = 100.0F; location = new Location(jp.getJSONObject("playerconfig.json").getString("currentLocation"), new ArrayList<>(), new ArrayList<>()); inventory = new ArrayList<>(); + JSONArray items = jp.getJSONObject("playerconfig.json").getJSONArray("inventory"); + for (int i = 0; i < items.length(); i++) { + JSONObject o = items.getJSONObject(i); + inventory.add(new Item(o.getString("name"), o.getBoolean("doesDamage"), o.getFloat("damage"), o.getInt("amount"))); + } + + + } public String getName() { From 41555788051c1db1fe0b34003ed0206166e53dc1 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:22:19 +0100 Subject: [PATCH 09/53] edited InventoryCommand: added amount to readInv() --- src/main/java/org/bitbiome/commands/InventoryCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java index da14945..94af13d 100644 --- a/src/main/java/org/bitbiome/commands/InventoryCommand.java +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -23,7 +23,7 @@ public class InventoryCommand implements CommandAPI { ArrayList inventory = travelEngine.getPlayer().getInventory(); s.append("Inventory: \n"); for (int i=0; i < inventory.size(); i++){ - s.append("- ").append(inventory.get(i).getName()).append("\n"); + s.append("- ").append(inventory.get(i).getName()).append(" x").append(inventory.get(i).getAmount()).append("\n"); } return s.toString(); From fdb1744f2022455c7fc3f711de040ec173ad77c4 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:26:13 +0100 Subject: [PATCH 10/53] added InventoryCommand to CommandListener to call inventory in game --- src/main/java/org/bitbiome/commands/CommandListener.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index d59813c..79f2b47 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -18,6 +18,8 @@ public class CommandListener { commands.put("quit", new QuitCommand()); commands.put("location", new LocationCommand()); commands.put("travel", new TravelCommand()); + commands.put("inventory", new InventoryCommand()); + } public HashMap returnCommands() { From 56792352b6fff2d62d45468343586882a363aa54 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 14:00:02 +0100 Subject: [PATCH 11/53] create lookaroundCommand.java --- .../org/bitbiome/commands/LookaroundCommand.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/org/bitbiome/commands/LookaroundCommand.java diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java new file mode 100644 index 0000000..1407700 --- /dev/null +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -0,0 +1,12 @@ +package org.bitbiome.commands; + +import org.bitbiome.classes.TravelEngine; + +import java.util.Scanner; + +public class LookaroundCommand implements CommandAPI{ + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + + } +} From 85b25fae391c50865a0d01e0c67c8ceef077cfde Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 14:27:04 +0100 Subject: [PATCH 12/53] refactoring: added colors --- src/main/java/org/bitbiome/commands/InventoryCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java index 94af13d..0892636 100644 --- a/src/main/java/org/bitbiome/commands/InventoryCommand.java +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -1,5 +1,6 @@ package org.bitbiome.commands; +import org.bitbiome.classes.Colors; import org.bitbiome.classes.JsonParser; import org.bitbiome.classes.TravelEngine; import org.bitbiome.entities.Item; @@ -21,9 +22,9 @@ public class InventoryCommand implements CommandAPI { JSONObject o = jp.getJSONObject("playerconfig.json"); ArrayList inventory = travelEngine.getPlayer().getInventory(); - s.append("Inventory: \n"); + s.append(Colors.ANSI_BRIGHT_RED +"Inventory:\n"+ Colors.ANSI_RESET); for (int i=0; i < inventory.size(); i++){ - s.append("- ").append(inventory.get(i).getName()).append(" x").append(inventory.get(i).getAmount()).append("\n"); + s.append(Colors.ANSI_BRIGHT_BG_RED+ Colors.ANSI_BRIGHT_WHITE+ "- ").append(inventory.get(i).getName()).append(" x").append(inventory.get(i).getAmount()).append(" "+ Colors.ANSI_RESET + "\n" ); } return s.toString(); From 1dfd9f05bdc2c16a63ca91e2482c8a62b9652d15 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 14:29:54 +0100 Subject: [PATCH 13/53] refactoring: edited message of inventoryCommand --- src/main/java/org/bitbiome/commands/InventoryCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java index 0892636..0d6a871 100644 --- a/src/main/java/org/bitbiome/commands/InventoryCommand.java +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -22,7 +22,7 @@ public class InventoryCommand implements CommandAPI { JSONObject o = jp.getJSONObject("playerconfig.json"); ArrayList inventory = travelEngine.getPlayer().getInventory(); - s.append(Colors.ANSI_BRIGHT_RED +"Inventory:\n"+ Colors.ANSI_RESET); + s.append(Colors.ANSI_BRIGHT_RED +"Du möchtest wissen, was in deinem Inventar ist? \nDann lass uns gemeinsam deinen Rucksack öffnen. \nDein Rucksack steckt ja voller Überraschungen! \nDas hast du alles schon gefunden: \n"+ Colors.ANSI_RESET); for (int i=0; i < inventory.size(); i++){ s.append(Colors.ANSI_BRIGHT_BG_RED+ Colors.ANSI_BRIGHT_WHITE+ "- ").append(inventory.get(i).getName()).append(" x").append(inventory.get(i).getAmount()).append(" "+ Colors.ANSI_RESET + "\n" ); } From 8958d30b07eca59e996b680e0758ad99665d443b Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 14:34:21 +0100 Subject: [PATCH 14/53] added inventory command to help command and helpcommandtest --- src/main/java/org/bitbiome/commands/HelpCommand.java | 2 ++ src/test/java/org/bitbiome/commands/HelpCommandTest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java index 90702cc..ce839b0 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -28,6 +28,8 @@ public class HelpCommand implements CommandAPI { .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") + .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") .append("|______________|_____________________________|\n"); return outputMessage.toString(); diff --git a/src/test/java/org/bitbiome/commands/HelpCommandTest.java b/src/test/java/org/bitbiome/commands/HelpCommandTest.java index dab4d90..14f9bcd 100644 --- a/src/test/java/org/bitbiome/commands/HelpCommandTest.java +++ b/src/test/java/org/bitbiome/commands/HelpCommandTest.java @@ -22,6 +22,8 @@ public class HelpCommandTest { .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") + .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") .append("|______________|_____________________________|\n"); assertEquals(outputMessage.toString(), helpMessage); } From 97e004966a8f3d91ddbf706f7ddfc35785838683 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:40:22 +0100 Subject: [PATCH 15/53] Refactoring: deleting unnecessary code in detail: array of items and mobs won't be print out anymore --- src/main/java/org/bitbiome/classes/TravelEngine.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/bitbiome/classes/TravelEngine.java b/src/main/java/org/bitbiome/classes/TravelEngine.java index a8d3213..4eb63d6 100644 --- a/src/main/java/org/bitbiome/classes/TravelEngine.java +++ b/src/main/java/org/bitbiome/classes/TravelEngine.java @@ -59,8 +59,7 @@ public class TravelEngine { //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; From 03979f3fc9ab95084f7fccbcf831f0beda039df5 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:09:56 +0100 Subject: [PATCH 16/53] refactoring: delete unused code --- src/main/java/org/bitbiome/commands/InventoryCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java index 0d6a871..7234eb9 100644 --- a/src/main/java/org/bitbiome/commands/InventoryCommand.java +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -18,8 +18,6 @@ public class InventoryCommand implements CommandAPI { public String readInv(TravelEngine travelEngine) { StringBuilder s = new StringBuilder(); - JsonParser jp = new JsonParser(); - JSONObject o = jp.getJSONObject("playerconfig.json"); ArrayList inventory = travelEngine.getPlayer().getInventory(); s.append(Colors.ANSI_BRIGHT_RED +"Du möchtest wissen, was in deinem Inventar ist? \nDann lass uns gemeinsam deinen Rucksack öffnen. \nDein Rucksack steckt ja voller Überraschungen! \nDas hast du alles schon gefunden: \n"+ Colors.ANSI_RESET); From a74982a065a8313206493b77f2626c0329df0f6f Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:15:36 +0100 Subject: [PATCH 17/53] added new Command: "lookaround" --- src/main/java/org/bitbiome/commands/CommandListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index 79f2b47..99d7caa 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -19,6 +19,7 @@ public class CommandListener { commands.put("location", new LocationCommand()); commands.put("travel", new TravelCommand()); commands.put("inventory", new InventoryCommand()); + commands.put("lookaround", new LookaroundCommand()); } From abb4bf1d464c72a98c03f68ad34836ee67f57a6a Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:19:39 +0100 Subject: [PATCH 18/53] added function set inventory() to Player file --- src/main/java/org/bitbiome/entities/Player.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/bitbiome/entities/Player.java b/src/main/java/org/bitbiome/entities/Player.java index 7fc9623..7eef0fe 100644 --- a/src/main/java/org/bitbiome/entities/Player.java +++ b/src/main/java/org/bitbiome/entities/Player.java @@ -69,4 +69,7 @@ public class Player { this.name = name; } + public void setInventory(ArrayList inventory) { + this.inventory = inventory; + } } From a140d0db325fe23ec19feb51501697b51cdc795a Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:22:00 +0100 Subject: [PATCH 19/53] Unittest: created InventoryTestCommand --- .../commands/InventoryCommandTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/test/java/org/bitbiome/commands/InventoryCommandTest.java diff --git a/src/test/java/org/bitbiome/commands/InventoryCommandTest.java b/src/test/java/org/bitbiome/commands/InventoryCommandTest.java new file mode 100644 index 0000000..aae394b --- /dev/null +++ b/src/test/java/org/bitbiome/commands/InventoryCommandTest.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.Player; +import org.junit.jupiter.api.Test; +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class InventoryCommandTest { + @Test + public void testInventoryCommand(){ + InventoryCommand command = new InventoryCommand(); + Player p = new Player("Unit"); + TravelEngine travelEngine = new TravelEngine(p); + ArrayList inventory = new ArrayList<>(); + Item item1 = new Item("Holz", false, 0,5); + Item item2 = new Item("Stein", true, 10, 5); + inventory.add(item1); + inventory.add(item2); + travelEngine.getPlayer().setInventory(inventory); + + String expectedResult = Colors.ANSI_BRIGHT_RED + "Du möchtest wissen, was in deinem Inventar ist? \n" + + "Dann lass uns gemeinsam deinen Rucksack öffnen. \nDein Rucksack steckt ja voller Überraschungen! \n" + + "Das hast du alles schon gefunden: \n" + Colors.ANSI_RESET + + Colors.ANSI_BRIGHT_BG_RED + Colors.ANSI_BRIGHT_WHITE + "- " + "Holz" + " x" + 5 + " " + Colors.ANSI_RESET + "\n" + + Colors.ANSI_BRIGHT_BG_RED + Colors.ANSI_BRIGHT_WHITE + "- " + "Stein" + " x" + 5 + " " + Colors.ANSI_RESET + "\n"; + + String result = command.readInv(travelEngine); + assertEquals(expectedResult, result); + } + + } + + //was ist, wenn ich mehr im inventar habe?, wie kann ich den anpassen auf den jeweiligen spielstand? + From ac7fd50507575e1fb97534e33f29d0d8d76b3c91 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:23:56 +0100 Subject: [PATCH 20/53] updated Json files: gameconfig.json an items.json --- src/main/resources/gameconfig.json | 6 ++++-- src/main/resources/items.json | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/resources/gameconfig.json b/src/main/resources/gameconfig.json index cb08775..847633e 100644 --- a/src/main/resources/gameconfig.json +++ b/src/main/resources/gameconfig.json @@ -27,7 +27,8 @@ { "name": "Big Foot", "hp": 50, - "damage": "10-15", + "damage": 15, + "isFriendly": true, "items": [ "Fell" ] @@ -44,7 +45,8 @@ { "name": "Big Foot", "hp": 50, - "damage": "10-15", + "damage": 15, + "isFriendly": true, "items": [ "Fell" ] diff --git a/src/main/resources/items.json b/src/main/resources/items.json index 85b3f26..7786427 100644 --- a/src/main/resources/items.json +++ b/src/main/resources/items.json @@ -1,26 +1,30 @@ [ { "name": "Holz", - "damage": "1-3", + "damage": 0, "crafting": true, - "durability": 1000 + "durability": 1000, + "doesDamage": false }, { "name": "Heiliges Schwert der Engel", - "damage": "1000", + "damage": 1000, "crafting": false, - "durability": 1000 + "durability": 1000, + "doesDamage": true }, { "name": "Stein", - "damage": "5-10", + "damage": 10, "crafting": true, - "durability": 1000 + "durability": 1000, + "doesDamage": true }, { "name": "Fell", - "damage": "0", + "damage": 0, "crafting": true, - "durability": 1000 + "durability": 1000, + "doesDamage": false; } ] \ No newline at end of file From b8b4b6ea25e799f65272764e643515eb9c963b29 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Thu, 2 Feb 2023 17:37:16 +0100 Subject: [PATCH 21/53] create CollectCommand.java --- .../java/org/bitbiome/commands/CollectCommand.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/org/bitbiome/commands/CollectCommand.java diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java new file mode 100644 index 0000000..4787179 --- /dev/null +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -0,0 +1,12 @@ +package org.bitbiome.commands; + +import org.bitbiome.classes.TravelEngine; + +import java.util.Scanner; + +public class CollectCommand implements CommandAPI { + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + + } +} From 577c2a61ec43ef02f52788ac008b2c622bd1722c Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Thu, 2 Feb 2023 17:38:39 +0100 Subject: [PATCH 22/53] added CollectCommand to CommandListener --- src/main/java/org/bitbiome/commands/CommandListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index 99d7caa..33d6e6c 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -20,6 +20,7 @@ public class CommandListener { commands.put("travel", new TravelCommand()); commands.put("inventory", new InventoryCommand()); commands.put("lookaround", new LookaroundCommand()); + commands.put("collect", new CollectCommand()); } From 8bb9367d7baae04ed39585bb70f638b9bb9c9ea0 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:05:02 +0100 Subject: [PATCH 23/53] updated LookaroundCommand() get ArrayList of currentLocation of Player --- .../bitbiome/commands/LookaroundCommand.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index 1407700..2f3b77f 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -1,12 +1,42 @@ package org.bitbiome.commands; +import org.bitbiome.classes.JsonParser; 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 org.json.JSONObject; +import org.json.JSONTokener; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Random; import java.util.Scanner; public class LookaroundCommand implements CommandAPI{ @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { - + StringBuilder s = new StringBuilder(); + Location location = travelEngine.getPlayer().getLocation(); + JsonParser jp = new JsonParser(); + JSONObject o = jp.getJSONObject("gameconfig.json"); + JSONArray locations = o.getJSONArray("locations"); + JSONObject locationObject = locations.getJSONObject(0); + + for (int i = 1; i < locations.length(); i++) { + if(locations.getJSONObject(i).getString("name").equals(location.getName())){ + locationObject = locations.getJSONObject(i); + } + } + JSONArray items = locationObject.getJSONArray("items"); + JSONArray mobs = locationObject.getJSONArray("mobs"); + + ArrayList foundItems = location.getItemList(); + ArrayList foundMobs = location.getMobList(); + s.append(foundItems).append(foundMobs); + System.out.println(s); + } + } From f6fb656ecd0267b648c67d1a4c124b2da8c6d036 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:13:24 +0100 Subject: [PATCH 24/53] generate random mobs and items in Lookaround Command() --- .../bitbiome/commands/LookaroundCommand.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index 2f3b77f..e6b632d 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -32,8 +32,39 @@ public class LookaroundCommand implements CommandAPI{ JSONArray items = locationObject.getJSONArray("items"); JSONArray mobs = locationObject.getJSONArray("mobs"); + Random random = new Random(); + int randomNumberItems = random.nextInt(items.length()+1); + int randomNumberMobs = random.nextInt(mobs.length()+1); ArrayList foundItems = location.getItemList(); + foundItems.removeAll(foundItems); ArrayList foundMobs = location.getMobList(); + foundMobs.removeAll(foundMobs); + + for (int i=0; i Date: Fri, 3 Feb 2023 15:20:50 +0100 Subject: [PATCH 25/53] added output of randomItems, randomMobs, and description of location --- .../bitbiome/commands/LookaroundCommand.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index e6b632d..a090061 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -65,7 +65,39 @@ public class LookaroundCommand implements CommandAPI{ Mob randomMob = new Mob (jp2.getString("name"),jp2.getBoolean("isFriendly"),jp2.getFloat("hp"),jp2.getFloat("damage")); foundMobs.add(randomMob); } - s.append(foundItems).append(foundMobs); + if (location.getName().equals("Wald")){ + s.append("Du befindest dich mitten im Wald, um dich herum siehst du hohe Buchen, kleine Sträucher und Farne.\n" + + "Der Boden ist mit weichem Moos, Pilzen und Laub bedeckt, in der Nähe hörst du Vögel munter zwitschern und\n" + + "einen kleinen Bach, der sich durch das dichte Unterholz schlängelt." + + " Schau mal, dort hinten in der Ferne ist ein Eichhörnchen! \n"); + } + if (location.getName().equals("Strand")){ + s.append("Du befindest dich mitten am Strand und blickst auf das Meer, das sich bis zum Horizont erstreckt.\n" + + "Du spürst den Sand an deinen Füßen, du hörst das weiche Rauschen des Meeres und das Lachen der Möwen über dir.\n" + + "Rechts und links von dir erstreckt sich der weite, weiße Sandstrand, dort hinten bauen Kinder eine Sandburg.\n" + + "Es gibt ein paar Palmen, die den Strand säumen und Strandliegen und -schirme, weit in der Ferne ragen Felsen aus dem Meer.\n"); + + } + if (randomNumberItems != 0){ + s.append("Huch, was liegt denn hier rum?\n"); + for (int i = 0; i < foundItems.size(); i++){ + s. append( "- ").append(foundItems.get(i).getName()+"\n"); + } + s.append("Schnell, sammel es ein!\n"); + } + else { + s.append("Hier gibt es leider nichts für dich zum Einsammeln.\n"); + } + if (randomNumberMobs != 0){ + s.append("Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n"); + for (int i = 0; i < foundMobs.size(); i++){ + s. append( "- ").append(foundMobs.get(i).getName()+"\n"); + } + } + //gibt es eigentlich auch Hindernisse, wie zum Beispiel einen umgefallenen Baumstamm, oder Höhle, Hütte, zum Erkunden in der jeweiligen Welt? + if((randomNumberMobs ==0) && (randomNumberItems == 0)){ + s.append("Hier gibt es sonst nichts weiter zu sehen. Reise weiter!\n"); + } System.out.println(s); } From 5d8d6b764e982ab9aec737424c1d7058b23887cb Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:27:30 +0100 Subject: [PATCH 26/53] refactoring: created method getLocationObject() --- .../bitbiome/commands/LookaroundCommand.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index a090061..ce18dda 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -20,15 +20,9 @@ public class LookaroundCommand implements CommandAPI{ StringBuilder s = new StringBuilder(); Location location = travelEngine.getPlayer().getLocation(); JsonParser jp = new JsonParser(); - JSONObject o = jp.getJSONObject("gameconfig.json"); - JSONArray locations = o.getJSONArray("locations"); - JSONObject locationObject = locations.getJSONObject(0); - - for (int i = 1; i < locations.length(); i++) { - if(locations.getJSONObject(i).getString("name").equals(location.getName())){ - locationObject = locations.getJSONObject(i); - } - } + JSONObject gameConfig = jp.getJSONObject("gameconfig.json"); + JSONArray locations = gameConfig.getJSONArray("locations"); + JSONObject locationObject = getLocationObject(location.getName(), locations); JSONArray items = locationObject.getJSONArray("items"); JSONArray mobs = locationObject.getJSONArray("mobs"); @@ -101,5 +95,14 @@ public class LookaroundCommand implements CommandAPI{ System.out.println(s); } + public JSONObject getLocationObject(String locationName, JSONArray locations) { + for (int i = 1; i < locations.length(); i++) { + if(locations.getJSONObject(i).getString("name").equals(locationName)){ + return locations.getJSONObject(i); + } + } + return locations.getJSONObject(0); + } + } From 2d13de8429a279af1cede5b3c451e905781f98bd Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:33:48 +0100 Subject: [PATCH 27/53] refactoring: created new method getRandomItem() --- .../bitbiome/commands/LookaroundCommand.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index ce18dda..49133ab 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -33,27 +33,8 @@ public class LookaroundCommand implements CommandAPI{ foundItems.removeAll(foundItems); ArrayList foundMobs = location.getMobList(); foundMobs.removeAll(foundMobs); + foundItems = getRandomItem(randomNumberItems, random, items, foundItems); - for (int i=0; i getRandomItem(int randomNumberItems, Random random, JSONArray items, ArrayList foundItems ) { + for (int i=0; i Date: Fri, 3 Feb 2023 15:38:10 +0100 Subject: [PATCH 28/53] refactoring: create new method getRandomMob() to LookaroundCommand.java --- .../org/bitbiome/commands/LookaroundCommand.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index 49133ab..047119e 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -34,12 +34,8 @@ public class LookaroundCommand implements CommandAPI{ ArrayList foundMobs = location.getMobList(); foundMobs.removeAll(foundMobs); foundItems = getRandomItem(randomNumberItems, random, items, foundItems); + foundMobs = getRandomMob(randomNumberMobs,random,mobs,foundMobs); - for (int i=0; i getRandomMob(int randomNumberMobs, Random random, JSONArray mobs, ArrayList foundMobs){ + for (int i=0; i Date: Fri, 3 Feb 2023 15:42:33 +0100 Subject: [PATCH 29/53] refactoring: create new method getItemsOutput to lookaroundCommand.java --- .../bitbiome/commands/LookaroundCommand.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index 047119e..2a7448e 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -49,16 +49,7 @@ public class LookaroundCommand implements CommandAPI{ "Es gibt ein paar Palmen, die den Strand säumen und Strandliegen und -schirme, weit in der Ferne ragen Felsen aus dem Meer.\n"); } - if (randomNumberItems != 0){ - s.append("Huch, was liegt denn hier rum?\n"); - for (int i = 0; i < foundItems.size(); i++){ - s. append( "- ").append(foundItems.get(i).getName()+"\n"); - } - s.append("Schnell, sammel es ein!\n"); - } - else { - s.append("Hier gibt es leider nichts für dich zum Einsammeln.\n"); - } + getItemsOutput(randomNumberItems,s,foundItems); if (randomNumberMobs != 0){ s.append("Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n"); for (int i = 0; i < foundMobs.size(); i++){ @@ -110,6 +101,17 @@ public class LookaroundCommand implements CommandAPI{ foundMobs.add(randomMob); } return foundMobs; } - + public void getItemsOutput(int randomNumberItems, StringBuilder s, ArrayList foundItems){ + if (randomNumberItems != 0){ + s.append("Huch, was liegt denn hier rum?\n"); + for (int i = 0; i < foundItems.size(); i++){ + s. append( "- ").append(foundItems.get(i).getName()+"\n"); + } + s.append("Schnell, sammel es ein!\n"); + } + else { + s.append("Hier gibt es leider nichts für dich zum Einsammeln.\n"); + } + } } From b8ddcdd879cb639b68706e3d3632d288cdd6d3e5 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:46:30 +0100 Subject: [PATCH 30/53] refactoring: create new method getMobsOutput() to LookaroundCommand --- .../bitbiome/commands/LookaroundCommand.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index 2a7448e..bdcd1d4 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -50,16 +50,7 @@ public class LookaroundCommand implements CommandAPI{ } getItemsOutput(randomNumberItems,s,foundItems); - if (randomNumberMobs != 0){ - s.append("Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n"); - for (int i = 0; i < foundMobs.size(); i++){ - s. append( "- ").append(foundMobs.get(i).getName()+"\n"); - } - } - //gibt es eigentlich auch Hindernisse, wie zum Beispiel einen umgefallenen Baumstamm, oder Höhle, Hütte, zum Erkunden in der jeweiligen Welt? - if((randomNumberMobs ==0) && (randomNumberItems == 0)){ - s.append("Hier gibt es sonst nichts weiter zu sehen. Reise weiter!\n"); - } + getMobsOutput(randomNumberItems,randomNumberMobs,s, foundMobs); System.out.println(s); } @@ -113,5 +104,17 @@ public class LookaroundCommand implements CommandAPI{ s.append("Hier gibt es leider nichts für dich zum Einsammeln.\n"); } } + public void getMobsOutput(int randomNumberItems, int randomNumberMobs, StringBuilder s, ArrayList foundMobs){ + if (randomNumberMobs != 0){ + s.append("Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n"); + for (int i = 0; i < foundMobs.size(); i++){ + s. append( "- ").append(foundMobs.get(i).getName()+"\n"); + } + } + if((randomNumberMobs ==0) && (randomNumberItems == 0)){ + s.append("Hier gibt es sonst nichts weiter zu sehen. Reise weiter!\n"); + } + } + } From f9a4bef143e49964edae0cd70232c55f3996d16f Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 3 Feb 2023 16:03:04 +0100 Subject: [PATCH 31/53] added lookaroundCommand to helpCommand and helpCommandTest --- .../org/bitbiome/commands/HelpCommand.java | 29 ++++++++++--------- .../bitbiome/commands/HelpCommandTest.java | 29 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java index ce839b0..2f9a5ac 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -18,19 +18,22 @@ public class HelpCommand implements CommandAPI { public static String getHelpMessage() { 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") - .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") - .append("|______________|_____________________________|\n"); + .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") + .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") + .append("|--------------|-------------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " lookaround" + Colors.ANSI_RESET + " | Zeigt dir deine Umgebung, |\n") + .append("|" + Colors.ANSI_GREEN + " " + Colors.ANSI_RESET + " | Items und Mobs in der Nähe |\n") + .append("|______________|_______________________________|\n"); return outputMessage.toString(); } diff --git a/src/test/java/org/bitbiome/commands/HelpCommandTest.java b/src/test/java/org/bitbiome/commands/HelpCommandTest.java index 14f9bcd..afdd7b2 100644 --- a/src/test/java/org/bitbiome/commands/HelpCommandTest.java +++ b/src/test/java/org/bitbiome/commands/HelpCommandTest.java @@ -12,19 +12,22 @@ public class HelpCommandTest { String helpMessage = HelpCommand.getHelpMessage(); 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") - .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") - .append("|______________|_____________________________|\n"); + .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") + .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") + .append("|--------------|-------------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " lookaround" + Colors.ANSI_RESET + " | Zeigt dir deine Umgebung, |\n") + .append("|" + Colors.ANSI_GREEN + " " + Colors.ANSI_RESET + " | Items und Mobs in der Nähe |\n") + .append("|______________|_______________________________|\n"); assertEquals(outputMessage.toString(), helpMessage); } From 841665d081d6617f35582a947c5e32534e5e856e Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 10:36:32 +0100 Subject: [PATCH 32/53] created method collectItem() to collectCommand --- .../java/org/bitbiome/commands/CollectCommand.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index 4787179..e459c49 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -1,12 +1,22 @@ package org.bitbiome.commands; +import org.bitbiome.classes.JsonParser; import org.bitbiome.classes.TravelEngine; +import org.bitbiome.entities.Item; +import org.json.JSONArray; +import org.json.JSONObject; +import java.util.ArrayList; import java.util.Scanner; public class CollectCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { - + + } + + public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, TravelEngine travelEngine) { + } } + From ec1ee44981a9d0b6205506ae0eafc7974c460796 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 10:42:20 +0100 Subject: [PATCH 33/53] edited method collectItem() of CollectCommand --- .../org/bitbiome/commands/CollectCommand.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index e459c49..ea5e07a 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -16,7 +16,37 @@ public class CollectCommand implements CommandAPI { } public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, TravelEngine travelEngine) { - + for (int i = 0; i < location.size(); i++) { + if (item.equals(location.get(i).getName())) { + JSONObject o1 = new JSONObject(); + for (int j = 0; j < travelEngine.getPlayer().getInventory().size(); j++) { + if (travelEngine.getPlayer().getInventory().get(j).getName().equals(item)) { + travelEngine.getPlayer().getInventory().get(j).setAmount(travelEngine.getPlayer().getInventory().get(j).getAmount() + 1); + for (int k = 0; k < inventory.length(); k++) { + if (inventory.getJSONObject(k).getString("name").equals(item)) { + JSONObject o2 = new JSONObject(); + int amountItemsInPlayerconfig = 0; + amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); + inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); + jp.writeObject("playerconfig.json", o); + System.out.println("Du hast das Item eingsammelt."); + return; + } + } + } + } + o1.put("name", location.get(i).getName()); + o1.put("doesDamage", location.get(i).doesDamage()); + o1.put("damage", location.get(i).getDamage()); + o1.put("amount", 1); + o1.put("durability", 1000); + o.getJSONArray("inventory").put(o1); + jp.writeObject("playerconfig.json", o); + travelEngine.getPlayer().getInventory().add(location.get(i)); + location.remove(i); + return; + } + } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); } } From 2deb02b591428e9b9cd1efc26ff587ff3d023354 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 10:46:13 +0100 Subject: [PATCH 34/53] updated CollectCommand.java: generate a user input to collect specific item --- src/main/java/org/bitbiome/commands/CollectCommand.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index ea5e07a..49ef575 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -12,6 +12,11 @@ import java.util.Scanner; public class CollectCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + + System.out.println("Was willst du einsammeln?"); + String item = new String(); + item = scanner.nextLine(); + } From 986151d614b2cba894406747dda747f16c79fff6 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 10:48:52 +0100 Subject: [PATCH 35/53] implementing method collectItem() in collectCommand.java --- .../java/org/bitbiome/commands/CollectCommand.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index 49ef575..19e76bc 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -12,12 +12,18 @@ import java.util.Scanner; public class CollectCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { - + StringBuilder s = new StringBuilder(); + JsonParser jp = new JsonParser(); + JSONObject o = jp.getJSONObject("playerconfig.json"); + JSONArray inventory = o.getJSONArray("inventory"); + + ArrayList location = travelEngine.getPlayer().getLocation().getItemList(); + System.out.println("Was willst du einsammeln?"); String item = new String(); item = scanner.nextLine(); - + collectItem(location, item, jp, o, inventory,travelEngine); } public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, TravelEngine travelEngine) { From 11e9541a1f8c13d376f42e5c291777edfc9bec68 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 10:58:11 +0100 Subject: [PATCH 36/53] refactoring: replace code for more readability --- .../org/bitbiome/commands/CollectCommand.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index 19e76bc..127638e 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -18,21 +18,22 @@ public class CollectCommand implements CommandAPI { JSONArray inventory = o.getJSONArray("inventory"); ArrayList location = travelEngine.getPlayer().getLocation().getItemList(); + ArrayList getInventory = travelEngine.getPlayer().getInventory(); System.out.println("Was willst du einsammeln?"); String item = new String(); item = scanner.nextLine(); - collectItem(location, item, jp, o, inventory,travelEngine); + collectItem(location, item, jp, o, inventory,getInventory); } - public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, TravelEngine travelEngine) { + public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, ArrayList getInventory) { for (int i = 0; i < location.size(); i++) { if (item.equals(location.get(i).getName())) { JSONObject o1 = new JSONObject(); - for (int j = 0; j < travelEngine.getPlayer().getInventory().size(); j++) { - if (travelEngine.getPlayer().getInventory().get(j).getName().equals(item)) { - travelEngine.getPlayer().getInventory().get(j).setAmount(travelEngine.getPlayer().getInventory().get(j).getAmount() + 1); + for (int j = 0; j < getInventory.size(); j++) { + if (getInventory.get(j).getName().equals(item)) { + getInventory.get(j).setAmount(getInventory.get(j).getAmount() + 1); for (int k = 0; k < inventory.length(); k++) { if (inventory.getJSONObject(k).getString("name").equals(item)) { JSONObject o2 = new JSONObject(); @@ -40,7 +41,7 @@ public class CollectCommand implements CommandAPI { amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); jp.writeObject("playerconfig.json", o); - System.out.println("Du hast das Item eingsammelt."); + System.out.println("Du hast das Item eingesammelt."); return; } } @@ -53,9 +54,8 @@ public class CollectCommand implements CommandAPI { o1.put("durability", 1000); o.getJSONArray("inventory").put(o1); jp.writeObject("playerconfig.json", o); - travelEngine.getPlayer().getInventory().add(location.get(i)); + getInventory.add(location.get(i)); location.remove(i); - return; } } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); } From 8fe445b5f8f28da5a5c45959dd17209a870b0713 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 11:01:56 +0100 Subject: [PATCH 37/53] refactoring: created method increaseAmountInPlayerConfig() in CollectCommand.java --- .../org/bitbiome/commands/CollectCommand.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index 127638e..ab29c5a 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -36,12 +36,7 @@ public class CollectCommand implements CommandAPI { getInventory.get(j).setAmount(getInventory.get(j).getAmount() + 1); for (int k = 0; k < inventory.length(); k++) { if (inventory.getJSONObject(k).getString("name").equals(item)) { - JSONObject o2 = new JSONObject(); - int amountItemsInPlayerconfig = 0; - amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); - inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); - jp.writeObject("playerconfig.json", o); - System.out.println("Du hast das Item eingesammelt."); + increaseAmountInPlayerConfig(inventory,k,jp,o); return; } } @@ -59,5 +54,13 @@ public class CollectCommand implements CommandAPI { } } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); } + public void increaseAmountInPlayerConfig(JSONArray inventory, int k, JsonParser jp, JSONObject o){ + JSONObject o2 = new JSONObject(); + int amountItemsInPlayerconfig = 0; + amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); + inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); + jp.writeObject("playerconfig.json", o); + System.out.println("Du hast das Item eingesammelt."); + } } From 346155ab001ae52a3b68d6d0e6d0bb384e7dc8a9 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 11:14:13 +0100 Subject: [PATCH 38/53] refactoring: added new method writeNewItem() to collectCommand.java --- .../org/bitbiome/commands/CollectCommand.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index ab29c5a..e235110 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -42,18 +42,21 @@ public class CollectCommand implements CommandAPI { } } } - o1.put("name", location.get(i).getName()); - o1.put("doesDamage", location.get(i).doesDamage()); - o1.put("damage", location.get(i).getDamage()); - o1.put("amount", 1); - o1.put("durability", 1000); - o.getJSONArray("inventory").put(o1); - jp.writeObject("playerconfig.json", o); - getInventory.add(location.get(i)); - location.remove(i); + writeNewItem(location, getInventory, o1, inventory, i, jp, o); } } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); } + public void writeNewItem(ArrayList location, ArrayList getInventory, JSONObject o1, JSONArray inventory, int i, JsonParser jp, JSONObject o){ + o1.put("name", location.get(i).getName()); + o1.put("doesDamage", location.get(i).doesDamage()); + o1.put("damage", location.get(i).getDamage()); + o1.put("amount", 1); + o1.put("durability", 1000); + o.getJSONArray("inventory").put(o1); + jp.writeObject("playerconfig.json", o); + getInventory.add(location.get(i)); + location.remove(i); + } public void increaseAmountInPlayerConfig(JSONArray inventory, int k, JsonParser jp, JSONObject o){ JSONObject o2 = new JSONObject(); int amountItemsInPlayerconfig = 0; From 43222921981f6639fa1521f06352d85149b46daa Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 11:20:31 +0100 Subject: [PATCH 39/53] added collectCommand to HelpCommand and HelpCommandTest --- src/main/java/org/bitbiome/commands/HelpCommand.java | 2 ++ src/test/java/org/bitbiome/commands/HelpCommandTest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java index 2f9a5ac..82b6763 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -31,6 +31,8 @@ public class HelpCommand implements CommandAPI { .append("|--------------|-------------------------------|\n") .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") .append("|--------------|-------------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " collect " + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") + .append("|--------------|-------------------------------|\n") .append("|" + Colors.ANSI_GREEN + " lookaround" + Colors.ANSI_RESET + " | Zeigt dir deine Umgebung, |\n") .append("|" + Colors.ANSI_GREEN + " " + Colors.ANSI_RESET + " | Items und Mobs in der Nähe |\n") .append("|______________|_______________________________|\n"); diff --git a/src/test/java/org/bitbiome/commands/HelpCommandTest.java b/src/test/java/org/bitbiome/commands/HelpCommandTest.java index afdd7b2..e7caecf 100644 --- a/src/test/java/org/bitbiome/commands/HelpCommandTest.java +++ b/src/test/java/org/bitbiome/commands/HelpCommandTest.java @@ -25,6 +25,8 @@ public class HelpCommandTest { .append("|--------------|-------------------------------|\n") .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") .append("|--------------|-------------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " collect " + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") + .append("|--------------|-------------------------------|\n") .append("|" + Colors.ANSI_GREEN + " lookaround" + Colors.ANSI_RESET + " | Zeigt dir deine Umgebung, |\n") .append("|" + Colors.ANSI_GREEN + " " + Colors.ANSI_RESET + " | Items und Mobs in der Nähe |\n") .append("|______________|_______________________________|\n"); From 363112a36472129b9f9cc88debc2b99c64e34537 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 13:47:31 +0100 Subject: [PATCH 40/53] unittest: test for collect Command testIncreaseAmountOfPlayerConfig() --- .../bitbiome/commands/CollectCommandTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/java/org/bitbiome/commands/CollectCommandTest.java diff --git a/src/test/java/org/bitbiome/commands/CollectCommandTest.java b/src/test/java/org/bitbiome/commands/CollectCommandTest.java new file mode 100644 index 0000000..cb718d1 --- /dev/null +++ b/src/test/java/org/bitbiome/commands/CollectCommandTest.java @@ -0,0 +1,26 @@ +package org.bitbiome.commands; + +import org.bitbiome.classes.JsonParser; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.jupiter.api.Test; + + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CollectCommandTest { + + @Test + public void testIncreaseAmountInPlayerConfig() { + CollectCommand command = new CollectCommand(); + JsonParser jp = new JsonParser(); + JSONObject o = jp.getJSONObject("playerconfig.json"); + JSONArray inventory = o.getJSONArray("inventory"); + int k = 0; + int initialAmount = inventory.getJSONObject(k).getInt("amount"); + command.increaseAmountInPlayerConfig(inventory, k, jp, o); + int finalAmount = inventory.getJSONObject(k).getInt("amount"); + assertEquals(initialAmount + 1, finalAmount); + } + +} \ No newline at end of file From e8842e54cd906f6c67fdc395bd8b99ab3ff18bb3 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 14:00:05 +0100 Subject: [PATCH 41/53] unittest: added testGetLocationObject ro LookaroundCommandTest --- .../commands/LookaroundCommandTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/java/org/bitbiome/commands/LookaroundCommandTest.java diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java new file mode 100644 index 0000000..24e7ba4 --- /dev/null +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -0,0 +1,40 @@ +package org.bitbiome.commands; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + + +public class LookaroundCommandTest { + private JSONArray locations; + + @Test + public void testGetLocationObject(){ + LookaroundCommand command = new LookaroundCommand(); + locations = new JSONArray(); + JSONObject location1 = new JSONObject(); + location1.put("name", "Wald"); + location1.put("description", "Es gibt Bäume und Sträucher"); + JSONObject location2 = new JSONObject(); + location2.put("name", "Strand"); + location2.put("description", "Weiter, weißer Sandstrand am Meer"); + locations.put(location1); + locations.put(location2); + + JSONObject result = command.getLocationObject("Wald", locations); + assertEquals("Wald", result.getString("name")); + assertEquals("Es gibt Bäume und Sträucher", result.getString("description")); + + result = command.getLocationObject("Strand", locations); + assertEquals("Strand", result.getString("name")); + assertEquals("Weiter, weißer Sandstrand am Meer", result.getString("description")); + + result = command.getLocationObject("not existing location", locations); + assertEquals("Wald", result.getString("name")); + assertEquals("Es gibt Bäume und Sträucher", result.getString("description")); + } + +} From 42e710c76d600facba22b8d7653672c4f6d51205 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 14:09:26 +0100 Subject: [PATCH 42/53] unittest: added testGetRandomMob() --- .../commands/LookaroundCommandTest.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index 24e7ba4..b48690f 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -1,11 +1,16 @@ package org.bitbiome.commands; +import org.bitbiome.entities.Item; +import org.bitbiome.entities.Mob; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.ArrayList; +import java.util.Random; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class LookaroundCommandTest { @@ -37,4 +42,31 @@ public class LookaroundCommandTest { assertEquals("Es gibt Bäume und Sträucher", result.getString("description")); } + @Test + public void testGetRandomMob() { + LookaroundCommand command = new LookaroundCommand(); + int randomNumberMobs = 2; + Random random = new Random(); + JSONArray mobs = new JSONArray(); + JSONObject mob1 = new JSONObject(); + mob1.put("name", "BigFoot"); + mob1.put("isFriendly", true); + mob1.put("hp", 10); + mob1.put("damage", 5); + JSONObject mob2 = new JSONObject(); + mob2.put("name", "Yeti"); + mob2.put("isFriendly", false); + mob2.put("hp", 20); + mob2.put("damage", 10); + mobs.put(mob1); + mobs.put(mob2); + ArrayList foundMobs = new ArrayList<>(); + ArrayList result = command.getRandomMob(randomNumberMobs, random, mobs, foundMobs); + + assertEquals(randomNumberMobs, result.size()); + for (Mob mob : result) { + assertTrue(mob.getName().equals("BigFoot") || mob.getName().equals("Yeti")); + } + } + } From 340fb80cc6f52ccf234b0bbeb72ca5e828c1d385 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 14:13:14 +0100 Subject: [PATCH 43/53] unittest: added testGetItemsOutputWithItems() --- .../bitbiome/commands/LookaroundCommandTest.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index b48690f..ac1a1d2 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -68,5 +68,17 @@ public class LookaroundCommandTest { assertTrue(mob.getName().equals("BigFoot") || mob.getName().equals("Yeti")); } } - + @Test + public void testGetItemsOutputWithItems() { + LookaroundCommand command = new LookaroundCommand(); + int randomNumberItems = 3; + StringBuilder outputMessage = new StringBuilder(); + ArrayList foundItems = new ArrayList(); + foundItems.add(new Item("Holz", true, 10, 1)); + foundItems.add(new Item("Stein", true, 10, 1)); + foundItems.add(new Item("Sand", false, 1, 1)); + command.getItemsOutput(randomNumberItems, outputMessage, foundItems); + String expectedOutput = "Huch, was liegt denn hier rum?\n- Holz\n- Stein\n- Sand\nSchnell, sammel es ein!\n"; + assertEquals(expectedOutput, outputMessage.toString()); + } } From fbae51a7169051b6174f5721a0f71d56c1296bb0 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 14:14:24 +0100 Subject: [PATCH 44/53] unittest: added testGetItemsOutputWithoutItems() --- .../org/bitbiome/commands/LookaroundCommandTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index ac1a1d2..e109a94 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -81,4 +81,14 @@ public class LookaroundCommandTest { String expectedOutput = "Huch, was liegt denn hier rum?\n- Holz\n- Stein\n- Sand\nSchnell, sammel es ein!\n"; assertEquals(expectedOutput, outputMessage.toString()); } + @Test + public void testGetItemsOutputWithoutItems() { + LookaroundCommand command = new LookaroundCommand(); + int randomNumberItems = 0; + StringBuilder outputMessage = new StringBuilder(); + ArrayList foundItems = new ArrayList(); + command.getItemsOutput(randomNumberItems, outputMessage, foundItems); + String expectedOutput = "Hier gibt es leider nichts für dich zum Einsammeln.\n"; + assertEquals(expectedOutput, outputMessage.toString()); + } } From d704d962a834e3f2b7d576f63ef569cf4f132222 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 14:16:42 +0100 Subject: [PATCH 45/53] unittest: added testGetMobsOutputWithMobs() --- .../bitbiome/commands/LookaroundCommandTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index e109a94..cc0fa77 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -91,4 +91,19 @@ public class LookaroundCommandTest { String expectedOutput = "Hier gibt es leider nichts für dich zum Einsammeln.\n"; assertEquals(expectedOutput, outputMessage.toString()); } + @Test + public void testGetMobsOutputWithMobs() { + LookaroundCommand command = new LookaroundCommand(); + int randomNumberMobs = 2; + int randomNumberItems = 0; + StringBuilder outputMessage = new StringBuilder(); + ArrayList foundMobs = new ArrayList<>(); + foundMobs.add(new Mob("Big Foot", true, 50, 15)); + foundMobs.add(new Mob("Yeti", false, 70, 30)); + + command.getMobsOutput( randomNumberItems,randomNumberMobs, outputMessage, foundMobs); + + String expectedOutput = "Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n- Big Foot\n- Yeti\n"; + assertEquals(expectedOutput, outputMessage.toString()); + } } From 1cdca21f4fbb95cb1efe435c619252e6bbc1272f Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 14:17:45 +0100 Subject: [PATCH 46/53] unittest: added testGetMobsOutputWithoutMobsAndItems() --- .../bitbiome/commands/LookaroundCommandTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index cc0fa77..45f3887 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -106,4 +106,17 @@ public class LookaroundCommandTest { String expectedOutput = "Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n- Big Foot\n- Yeti\n"; assertEquals(expectedOutput, outputMessage.toString()); } + @Test + public void testGetMobsOutputWithoutMobsAndItems() { + LookaroundCommand command = new LookaroundCommand(); + int randomNumberMobs = 0; + int randomNumberItems = 0; + StringBuilder outputMessage = new StringBuilder(); + ArrayList foundMobs = new ArrayList<>(); + + command.getMobsOutput(randomNumberMobs, randomNumberItems, outputMessage, foundMobs); + + String expectedOutput = "Hier gibt es sonst nichts weiter zu sehen. Reise weiter!\n"; + assertEquals(expectedOutput, outputMessage.toString()); + } } From 366fa9752ba6ee4f70ca66c42224a03e52da9071 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Mon, 6 Feb 2023 09:58:24 +0100 Subject: [PATCH 47/53] unittest: testGetRandomItem() --- .../commands/LookaroundCommandTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index 45f3887..33d08c3 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -1,6 +1,8 @@ package org.bitbiome.commands; +import org.bitbiome.classes.Colors; import org.bitbiome.entities.Item; +import org.bitbiome.entities.Location; import org.bitbiome.entities.Mob; import org.json.JSONArray; import org.json.JSONObject; @@ -119,4 +121,20 @@ public class LookaroundCommandTest { String expectedOutput = "Hier gibt es sonst nichts weiter zu sehen. Reise weiter!\n"; assertEquals(expectedOutput, outputMessage.toString()); } + @Test + void testGetRandomItem() throws Exception { + int randomNumberItems = 2; + JSONArray items = new JSONArray("[{\"name\":\"Holz\",\"doesDamage\":true,\"damage\":1.0},{\"name\":\"Stein\",\"doesDamage\":false,\"damage\":10.0}]"); + ArrayList result = new ArrayList<>(); + for (int i = 0; i < randomNumberItems; i++) { + JSONObject itemObject = items.getJSONObject(i); + Item item = new Item(itemObject.getString("name"), itemObject.getBoolean("doesDamage"), + itemObject.getFloat("damage"), 1); + result.add(item); + } + assertEquals(2, result.size()); + assertEquals("Holz", result.get(0).getName()); + assertEquals("Stein", result.get(1).getName()); + } + } From d61a00001d5b4295b7fb9d4fa48542e2754537da Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Mon, 6 Feb 2023 10:00:11 +0100 Subject: [PATCH 48/53] refactoring: add method getLocationDescription --- .../bitbiome/commands/LookaroundCommand.java | 79 ++++++++++++------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index bdcd1d4..839e25d 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -1,10 +1,9 @@ package org.bitbiome.commands; +import org.bitbiome.classes.Colors; import org.bitbiome.classes.JsonParser; import org.bitbiome.classes.TravelEngine; -import org.bitbiome.entities.Item; -import org.bitbiome.entities.Location; -import org.bitbiome.entities.Mob; +import org.bitbiome.entities.*; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONTokener; @@ -17,7 +16,7 @@ import java.util.Scanner; public class LookaroundCommand implements CommandAPI{ @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { - StringBuilder s = new StringBuilder(); + StringBuilder outputMessage = new StringBuilder(); Location location = travelEngine.getPlayer().getLocation(); JsonParser jp = new JsonParser(); JSONObject gameConfig = jp.getJSONObject("gameconfig.json"); @@ -36,22 +35,10 @@ public class LookaroundCommand implements CommandAPI{ foundItems = getRandomItem(randomNumberItems, random, items, foundItems); foundMobs = getRandomMob(randomNumberMobs,random,mobs,foundMobs); - if (location.getName().equals("Wald")){ - s.append("Du befindest dich mitten im Wald, um dich herum siehst du hohe Buchen, kleine Sträucher und Farne.\n" + - "Der Boden ist mit weichem Moos, Pilzen und Laub bedeckt, in der Nähe hörst du Vögel munter zwitschern und\n" + - "einen kleinen Bach, der sich durch das dichte Unterholz schlängelt." + - " Schau mal, dort hinten in der Ferne ist ein Eichhörnchen! \n"); - } - if (location.getName().equals("Strand")){ - s.append("Du befindest dich mitten am Strand und blickst auf das Meer, das sich bis zum Horizont erstreckt.\n" + - "Du spürst den Sand an deinen Füßen, du hörst das weiche Rauschen des Meeres und das Lachen der Möwen über dir.\n" + - "Rechts und links von dir erstreckt sich der weite, weiße Sandstrand, dort hinten bauen Kinder eine Sandburg.\n" + - "Es gibt ein paar Palmen, die den Strand säumen und Strandliegen und -schirme, weit in der Ferne ragen Felsen aus dem Meer.\n"); - - } - getItemsOutput(randomNumberItems,s,foundItems); - getMobsOutput(randomNumberItems,randomNumberMobs,s, foundMobs); - System.out.println(s); + getLocationDescription(location,outputMessage); + getItemsOutput(randomNumberItems,outputMessage,foundItems); + getMobsOutput(randomNumberItems,randomNumberMobs,outputMessage, foundMobs); + System.out.println(outputMessage); } public JSONObject getLocationObject(String locationName, JSONArray locations) { @@ -92,27 +79,61 @@ public class LookaroundCommand implements CommandAPI{ foundMobs.add(randomMob); } return foundMobs; } - public void getItemsOutput(int randomNumberItems, StringBuilder s, ArrayList foundItems){ + public void getItemsOutput(int randomNumberItems, StringBuilder outputMessage, ArrayList foundItems){ if (randomNumberItems != 0){ - s.append("Huch, was liegt denn hier rum?\n"); + outputMessage.append("Huch, was liegt denn hier rum?\n"); for (int i = 0; i < foundItems.size(); i++){ - s. append( "- ").append(foundItems.get(i).getName()+"\n"); + outputMessage. append("- ").append(foundItems.get(i).getName()+"\n"); } - s.append("Schnell, sammel es ein!\n"); + outputMessage.append("Schnell, sammel es ein!\n"); } else { - s.append("Hier gibt es leider nichts für dich zum Einsammeln.\n"); + outputMessage.append("Hier gibt es leider nichts für dich zum Einsammeln.\n"); } } - public void getMobsOutput(int randomNumberItems, int randomNumberMobs, StringBuilder s, ArrayList foundMobs){ + public void getMobsOutput(int randomNumberItems, int randomNumberMobs, StringBuilder outputMessage, ArrayList foundMobs){ if (randomNumberMobs != 0){ - s.append("Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n"); + outputMessage.append("Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n"); for (int i = 0; i < foundMobs.size(); i++){ - s. append( "- ").append(foundMobs.get(i).getName()+"\n"); + outputMessage. append( "- ").append(foundMobs.get(i).getName()+"\n"); } } if((randomNumberMobs ==0) && (randomNumberItems == 0)){ - s.append("Hier gibt es sonst nichts weiter zu sehen. Reise weiter!\n"); + outputMessage.append("Hier gibt es sonst nichts weiter zu sehen. Reise weiter!\n"); + } + } + public void getLocationDescription(Location location, StringBuilder outputMessage) { + switch (location.getName()) { + case "Wald" -> + outputMessage.append("Du befindest dich mitten im Wald, um dich herum siehst du hohe Buchen, kleine Sträucher und Farne.\n" + + "Der Boden ist mit weichem Moos, Pilzen und Laub bedeckt, in der Nähe hörst du Vögel munter zwitschern und\n" + + "einen kleinen Bach, der sich durch das dichte Unterholz schlängelt." + + " Schau mal, dort hinten in der Ferne ist ein Eichhörnchen! \n"); + case "Strand" -> + outputMessage.append("Du befindest dich mitten am Strand und blickst auf das Meer, das sich bis zum Horizont erstreckt.\n" + + "Du spürst den Sand an deinen Füßen, du hörst das weiche Rauschen des Meeres und das Lachen der Möwen über dir.\n" + + "Rechts und links von dir erstreckt sich der weite, weiße Sandstrand, dort hinten bauen Kinder eine Sandburg.\n" + + "Es gibt ein paar Palmen, die den Strand säumen und weit in der Ferne ragen Felsen aus dem Meer.\n"); + case "Winterland" -> + outputMessage.append("Um dich herum ragen hohe Berge in den Himmel, bedeckt von einer dicken Schicht aus Schnee. Du hörst\n" + + "das Knirschen des Schnees unter deinen Füßen und das Rauschen des eisigen Windes. In der Ferne siehst du Tannenbäume,\n" + + "die sich unter der Last des Schnees biegen, und dichte Flocken fallen sanft aus dem grauen Himmel. Es ist kalt, du siehst,\n" + + "wie dein Atem kleine Wolken bildet. Es ist still, aber auch ein wenig unheimlich.\n"); + case "Berge"-> + outputMessage.append("Du befindest dich in einer majestätischen Berglandschaft mit hohen Gipfen und tiefen Tälern.\n" + + "Die Luft ist frisch und klar, der Klang von rauschenden Bächen und Wasserfällen erfüllt die Umgebung.\n" + + "Die Berge sind mit grünen Wäldern bedeckt und vereinzelt siehst du wilde Tiere herumstreifen.\n"); + case "Grünland"-> + outputMessage.append("Du befindest dich in einer weiten und grünen Landschaft. Überall um dich herum wachsen hohe Gräser und Wildblumen. \n" + + "In der Ferne erkennst du sanfte Hügel mit einer Herde von Schafen und Kühen.Die Luft ist erfüllt von dem Duft der Natur \n" + + "und dem Summen von Insekten. Es herrscht eine friedliche Stille, nur unterbrochen vom gelegentlichen Ruf eines Vogels."); + case "Wüste"-> + outputMessage.append("Du befindest dich mitten in der Wüste. Weit und breit ist nichts anderes zu sehen außer Dünen, vertrocknete Sträucher und Tonnen von Sand.\n" + + "Es ist staubig, der sandige Boden unter deinen Füßen knirscht bei jedem Schritt und die Sonnen brennt auf dich herab. Nimm dich in Acht vor der Wüstenhitze \n" + + "und den Gefahren, die hinter den Dünen lauern. Beeil dich, aus dieser unendlichen Ebene zu entkommen.\n"); + default -> { + } + //location description not found } } From b2145ad89ae547464b1c63676678421b6ddf86ad Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Mon, 6 Feb 2023 10:01:21 +0100 Subject: [PATCH 49/53] unittest: added testWaldDescription() --- .../commands/LookaroundCommandTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index 33d08c3..24c06b4 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -136,5 +136,24 @@ public class LookaroundCommandTest { assertEquals("Holz", result.get(0).getName()); assertEquals("Stein", result.get(1).getName()); } + @Test + public void testWaldDescription() { + LookaroundCommand command = new LookaroundCommand(); + ArrayList enemies = new ArrayList(); + enemies.add(new Mob("Bigfoot", false, 50,20)); + ArrayList items = new ArrayList(); + items.add(new Item("Holz",true, 10, 1)); + Location location = new Location("Wald",enemies, items); + StringBuilder outputMessage = new StringBuilder(); + + command.getLocationDescription(location, outputMessage); + + String expectedDescription = "Du befindest dich mitten im Wald, um dich herum siehst du hohe Buchen, kleine Sträucher und Farne.\n" + + "Der Boden ist mit weichem Moos, Pilzen und Laub bedeckt, in der Nähe hörst du Vögel munter zwitschern und\n" + + "einen kleinen Bach, der sich durch das dichte Unterholz schlängelt." + + " Schau mal, dort hinten in der Ferne ist ein Eichhörnchen! \n"; + + assertEquals(expectedDescription, outputMessage.toString()); + } } From ac71a968c37e121a2406eec00248f7d410117400 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Mon, 6 Feb 2023 10:02:49 +0100 Subject: [PATCH 50/53] unittest: testStrandDescription --- .../commands/LookaroundCommandTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index 24c06b4..acbdf56 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -155,5 +155,24 @@ public class LookaroundCommandTest { assertEquals(expectedDescription, outputMessage.toString()); } + @Test + public void testStrandDescription() { + LookaroundCommand command = new LookaroundCommand(); + ArrayList enemies = new ArrayList(); + enemies.add(new Mob("Bigfoot", false, 50,20)); + ArrayList items = new ArrayList(); + items.add(new Item("Holz",true, 10, 1)); + Location location = new Location("Strand",enemies, items); + StringBuilder outputMessage = new StringBuilder(); + + command.getLocationDescription(location, outputMessage); + + String expectedDescription = "Du befindest dich mitten am Strand und blickst auf das Meer, das sich bis zum Horizont erstreckt.\n" + + "Du spürst den Sand an deinen Füßen, du hörst das weiche Rauschen des Meeres und das Lachen der Möwen über dir.\n" + + "Rechts und links von dir erstreckt sich der weite, weiße Sandstrand, dort hinten bauen Kinder eine Sandburg.\n" + + "Es gibt ein paar Palmen, die den Strand säumen und weit in der Ferne ragen Felsen aus dem Meer.\n"; + + assertEquals(expectedDescription, outputMessage.toString()); + } } From e05936efced13fd94f777a7986cf6d8d33a94e8f Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Mon, 6 Feb 2023 10:04:31 +0100 Subject: [PATCH 51/53] unittest: testUnknownLocationDescription() --- .../bitbiome/commands/LookaroundCommandTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index acbdf56..f298900 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -174,5 +174,19 @@ public class LookaroundCommandTest { assertEquals(expectedDescription, outputMessage.toString()); } + @Test + public void testUnknownLocationDescription() { + LookaroundCommand command = new LookaroundCommand(); + ArrayList enemies = new ArrayList(); + enemies.add(new Mob("unknown", false, 50,20)); + ArrayList items = new ArrayList(); + items.add(new Item("unknown",true, 10, 1)); + Location location = new Location("Unknown",enemies, items); + StringBuilder outputMessage = new StringBuilder(); + + command.getLocationDescription(location, outputMessage); + + assertEquals("", outputMessage.toString()); + } } From 58412a04d65060d517310fea7d3404e8ea3f3c7d Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Mon, 6 Feb 2023 10:11:33 +0100 Subject: [PATCH 52/53] refactoring: added colors --- .../org/bitbiome/commands/CollectCommand.java | 12 +++---- .../bitbiome/commands/InventoryCommand.java | 6 ++-- .../bitbiome/commands/LookaroundCommand.java | 35 ++++++++++--------- .../commands/InventoryCommandTest.java | 21 +++++------ .../commands/LookaroundCommandTest.java | 8 +++-- 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index e235110..41d8fc0 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -1,5 +1,6 @@ package org.bitbiome.commands; +import org.bitbiome.classes.Colors; import org.bitbiome.classes.JsonParser; import org.bitbiome.classes.TravelEngine; import org.bitbiome.entities.Item; @@ -26,7 +27,6 @@ public class CollectCommand implements CommandAPI { collectItem(location, item, jp, o, inventory,getInventory); } - public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, ArrayList getInventory) { for (int i = 0; i < location.size(); i++) { if (item.equals(location.get(i).getName())) { @@ -47,12 +47,8 @@ public class CollectCommand implements CommandAPI { } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); } public void writeNewItem(ArrayList location, ArrayList getInventory, JSONObject o1, JSONArray inventory, int i, JsonParser jp, JSONObject o){ - o1.put("name", location.get(i).getName()); - o1.put("doesDamage", location.get(i).doesDamage()); - o1.put("damage", location.get(i).getDamage()); - o1.put("amount", 1); - o1.put("durability", 1000); - o.getJSONArray("inventory").put(o1); + o1.put("name", location.get(i).getName()).put("doesDamage", location.get(i).doesDamage()).put("damage", location.get(i).getDamage()).put("amount", 1).put("durability", 1000); + inventory.put(o1); jp.writeObject("playerconfig.json", o); getInventory.add(location.get(i)); location.remove(i); @@ -63,7 +59,7 @@ public class CollectCommand implements CommandAPI { amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); jp.writeObject("playerconfig.json", o); - System.out.println("Du hast das Item eingesammelt."); + System.out.println(Colors.ANSI_YELLOW +"Du hast das Item eingesammelt."+ Colors.ANSI_RESET); } } diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java index 7234eb9..08d37a4 100644 --- a/src/main/java/org/bitbiome/commands/InventoryCommand.java +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -20,9 +20,11 @@ public class InventoryCommand implements CommandAPI { StringBuilder s = new StringBuilder(); ArrayList inventory = travelEngine.getPlayer().getInventory(); - s.append(Colors.ANSI_BRIGHT_RED +"Du möchtest wissen, was in deinem Inventar ist? \nDann lass uns gemeinsam deinen Rucksack öffnen. \nDein Rucksack steckt ja voller Überraschungen! \nDas hast du alles schon gefunden: \n"+ Colors.ANSI_RESET); + s.append(Colors.ANSI_PURPLE +"Du möchtest wissen, was in deinem Inventar ist? \n" + + "Dann lass uns gemeinsam deinen Rucksack öffnen. \nDein Rucksack steckt ja voller Überraschungen! \n" + + "Das hast du alles schon gefunden: \n"+ Colors.ANSI_RESET); for (int i=0; i < inventory.size(); i++){ - s.append(Colors.ANSI_BRIGHT_BG_RED+ Colors.ANSI_BRIGHT_WHITE+ "- ").append(inventory.get(i).getName()).append(" x").append(inventory.get(i).getAmount()).append(" "+ Colors.ANSI_RESET + "\n" ); + s.append(Colors.ANSI_BG_PURPLE+ Colors.ANSI_BRIGHT_WHITE+ "- ").append(inventory.get(i).getName()).append(" x").append(inventory.get(i).getAmount()).append(" "+ Colors.ANSI_RESET + "\n" ); } return s.toString(); diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index 839e25d..182e94d 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -79,21 +79,22 @@ public class LookaroundCommand implements CommandAPI{ foundMobs.add(randomMob); } return foundMobs; } + public void getItemsOutput(int randomNumberItems, StringBuilder outputMessage, ArrayList foundItems){ if (randomNumberItems != 0){ - outputMessage.append("Huch, was liegt denn hier rum?\n"); + outputMessage.append(Colors.ANSI_BLUE +"Huch, was liegt denn hier rum?\n"+ Colors.ANSI_RESET); for (int i = 0; i < foundItems.size(); i++){ outputMessage. append("- ").append(foundItems.get(i).getName()+"\n"); } - outputMessage.append("Schnell, sammel es ein!\n"); + outputMessage.append(Colors.ANSI_BLUE +"Schnell, sammel es ein!\n"+ Colors.ANSI_RESET); } else { - outputMessage.append("Hier gibt es leider nichts für dich zum Einsammeln.\n"); + outputMessage.append(Colors.ANSI_BLUE+ "Hier gibt es leider nichts für dich zum Einsammeln.\n"+ Colors.ANSI_RESET); } } public void getMobsOutput(int randomNumberItems, int randomNumberMobs, StringBuilder outputMessage, ArrayList foundMobs){ if (randomNumberMobs != 0){ - outputMessage.append("Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n"); + outputMessage.append(Colors.ANSI_RED+"Achtung, hier lauern Gefahren!"+Colors.ANSI_RESET +"Sei auf der Hut vor: \n"); for (int i = 0; i < foundMobs.size(); i++){ outputMessage. append( "- ").append(foundMobs.get(i).getName()+"\n"); } @@ -115,22 +116,22 @@ public class LookaroundCommand implements CommandAPI{ "Rechts und links von dir erstreckt sich der weite, weiße Sandstrand, dort hinten bauen Kinder eine Sandburg.\n" + "Es gibt ein paar Palmen, die den Strand säumen und weit in der Ferne ragen Felsen aus dem Meer.\n"); case "Winterland" -> - outputMessage.append("Um dich herum ragen hohe Berge in den Himmel, bedeckt von einer dicken Schicht aus Schnee. Du hörst\n" + - "das Knirschen des Schnees unter deinen Füßen und das Rauschen des eisigen Windes. In der Ferne siehst du Tannenbäume,\n" + - "die sich unter der Last des Schnees biegen, und dichte Flocken fallen sanft aus dem grauen Himmel. Es ist kalt, du siehst,\n" + - "wie dein Atem kleine Wolken bildet. Es ist still, aber auch ein wenig unheimlich.\n"); + outputMessage.append("Um dich herum ragen hohe Berge in den Himmel, bedeckt von einer dicken Schicht aus Schnee. Du hörst\n" + + "das Knirschen des Schnees unter deinen Füßen und das Rauschen des eisigen Windes. In der Ferne siehst du Tannenbäume,\n" + + "die sich unter der Last des Schnees biegen, und dichte Flocken fallen sanft aus dem grauen Himmel. Es ist kalt, du siehst,\n" + + "wie dein Atem kleine Wolken bildet. Es ist still, aber auch ein wenig unheimlich.\n"); case "Berge"-> - outputMessage.append("Du befindest dich in einer majestätischen Berglandschaft mit hohen Gipfen und tiefen Tälern.\n" + - "Die Luft ist frisch und klar, der Klang von rauschenden Bächen und Wasserfällen erfüllt die Umgebung.\n" + - "Die Berge sind mit grünen Wäldern bedeckt und vereinzelt siehst du wilde Tiere herumstreifen.\n"); + outputMessage.append("Du befindest dich in einer majestätischen Berglandschaft mit hohen Gipfen und tiefen Tälern.\n" + + "Die Luft ist frisch und klar, der Klang von rauschenden Bächen und Wasserfällen erfüllt die Umgebung.\n" + + "Die Berge sind mit grünen Wäldern bedeckt und vereinzelt siehst du wilde Tiere herumstreifen.\n"); case "Grünland"-> - outputMessage.append("Du befindest dich in einer weiten und grünen Landschaft. Überall um dich herum wachsen hohe Gräser und Wildblumen. \n" + - "In der Ferne erkennst du sanfte Hügel mit einer Herde von Schafen und Kühen.Die Luft ist erfüllt von dem Duft der Natur \n" + - "und dem Summen von Insekten. Es herrscht eine friedliche Stille, nur unterbrochen vom gelegentlichen Ruf eines Vogels."); + outputMessage.append("Du befindest dich in einer weiten und grünen Landschaft. Überall um dich herum wachsen hohe Gräser und Wildblumen. \n" + + "In der Ferne erkennst du sanfte Hügel mit einer Herde von Schafen und Kühen.Die Luft ist erfüllt von dem Duft der Natur \n" + + "und dem Summen von Insekten. Es herrscht eine friedliche Stille, nur unterbrochen vom gelegentlichen Ruf eines Vogels."); case "Wüste"-> - outputMessage.append("Du befindest dich mitten in der Wüste. Weit und breit ist nichts anderes zu sehen außer Dünen, vertrocknete Sträucher und Tonnen von Sand.\n" + - "Es ist staubig, der sandige Boden unter deinen Füßen knirscht bei jedem Schritt und die Sonnen brennt auf dich herab. Nimm dich in Acht vor der Wüstenhitze \n" + - "und den Gefahren, die hinter den Dünen lauern. Beeil dich, aus dieser unendlichen Ebene zu entkommen.\n"); + outputMessage.append("Du befindest dich mitten in der Wüste. Weit und breit ist nichts anderes zu sehen außer Dünen, vertrocknete Sträucher und Tonnen von Sand.\n" + + "Es ist staubig, der sandige Boden unter deinen Füßen knirscht bei jedem Schritt und die Sonnen brennt auf dich herab. Nimm dich in Acht vor der Wüstenhitze \n" + + "und den Gefahren, die hinter den Dünen lauern. Beeil dich, aus dieser unendlichen Ebene zu entkommen.\n"); default -> { } //location description not found diff --git a/src/test/java/org/bitbiome/commands/InventoryCommandTest.java b/src/test/java/org/bitbiome/commands/InventoryCommandTest.java index aae394b..c3521ce 100644 --- a/src/test/java/org/bitbiome/commands/InventoryCommandTest.java +++ b/src/test/java/org/bitbiome/commands/InventoryCommandTest.java @@ -11,28 +11,23 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class InventoryCommandTest { @Test - public void testInventoryCommand(){ + public void testReadInv(){ InventoryCommand command = new InventoryCommand(); - Player p = new Player("Unit"); - TravelEngine travelEngine = new TravelEngine(p); + TravelEngine travelEngine = new TravelEngine(new Player("Unit")); ArrayList inventory = new ArrayList<>(); - Item item1 = new Item("Holz", false, 0,5); - Item item2 = new Item("Stein", true, 10, 5); - inventory.add(item1); - inventory.add(item2); + inventory.add(new Item("Holz", false, 0,5)); + inventory.add(new Item("Stein", true, 10, 5)); travelEngine.getPlayer().setInventory(inventory); - String expectedResult = Colors.ANSI_BRIGHT_RED + "Du möchtest wissen, was in deinem Inventar ist? \n" + + String expectedResult = Colors.ANSI_PURPLE + "Du möchtest wissen, was in deinem Inventar ist? \n" + "Dann lass uns gemeinsam deinen Rucksack öffnen. \nDein Rucksack steckt ja voller Überraschungen! \n" + "Das hast du alles schon gefunden: \n" + Colors.ANSI_RESET + - Colors.ANSI_BRIGHT_BG_RED + Colors.ANSI_BRIGHT_WHITE + "- " + "Holz" + " x" + 5 + " " + Colors.ANSI_RESET + "\n" + - Colors.ANSI_BRIGHT_BG_RED + Colors.ANSI_BRIGHT_WHITE + "- " + "Stein" + " x" + 5 + " " + Colors.ANSI_RESET + "\n"; + Colors.ANSI_BG_PURPLE + Colors.ANSI_BRIGHT_WHITE + "- " + "Holz" + " x" + 5 + " " + Colors.ANSI_RESET + "\n" + + Colors.ANSI_BG_PURPLE + Colors.ANSI_BRIGHT_WHITE + "- " + "Stein" + " x" + 5 + " " + Colors.ANSI_RESET + "\n"; String result = command.readInv(travelEngine); assertEquals(expectedResult, result); } +} - } - - //was ist, wenn ich mehr im inventar habe?, wie kann ich den anpassen auf den jeweiligen spielstand? diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index f298900..c193a73 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -80,7 +80,9 @@ public class LookaroundCommandTest { foundItems.add(new Item("Stein", true, 10, 1)); foundItems.add(new Item("Sand", false, 1, 1)); command.getItemsOutput(randomNumberItems, outputMessage, foundItems); - String expectedOutput = "Huch, was liegt denn hier rum?\n- Holz\n- Stein\n- Sand\nSchnell, sammel es ein!\n"; + String expectedOutput = Colors.ANSI_BLUE+ "Huch, was liegt denn hier rum?\n" + Colors.ANSI_RESET+ + "- Holz\n- Stein\n- Sand\n" + + Colors.ANSI_BLUE +"Schnell, sammel es ein!\n"+ Colors.ANSI_RESET; assertEquals(expectedOutput, outputMessage.toString()); } @Test @@ -90,7 +92,7 @@ public class LookaroundCommandTest { StringBuilder outputMessage = new StringBuilder(); ArrayList foundItems = new ArrayList(); command.getItemsOutput(randomNumberItems, outputMessage, foundItems); - String expectedOutput = "Hier gibt es leider nichts für dich zum Einsammeln.\n"; + String expectedOutput = Colors.ANSI_BLUE+ "Hier gibt es leider nichts für dich zum Einsammeln.\n"+ Colors.ANSI_RESET; assertEquals(expectedOutput, outputMessage.toString()); } @Test @@ -105,7 +107,7 @@ public class LookaroundCommandTest { command.getMobsOutput( randomNumberItems,randomNumberMobs, outputMessage, foundMobs); - String expectedOutput = "Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n- Big Foot\n- Yeti\n"; + String expectedOutput = Colors.ANSI_RED+"Achtung, hier lauern Gefahren!"+Colors.ANSI_RESET +"Sei auf der Hut vor: \n- Big Foot\n- Yeti\n"; assertEquals(expectedOutput, outputMessage.toString()); } @Test From a6ae562464b68507ad1705559f1e1a4ec37c5f27 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Wed, 8 Feb 2023 11:45:22 +0100 Subject: [PATCH 53/53] Merge of branch 'develop' to 'Julia' --- README.md | 27 ++ playerconfig.json | 24 ++ src/main/java/org/bitbiome/Boot.java | 3 +- .../java/org/bitbiome/classes/BlackJack.java | 96 +++++ .../java/org/bitbiome/classes/Colors.java | 106 ++--- .../org/bitbiome/classes/CreateLocations.java | 24 -- .../org/bitbiome/classes/InteractionLoop.java | 37 +- .../java/org/bitbiome/classes/JsonParser.java | 37 +- src/main/java/org/bitbiome/classes/Shop.java | 273 ++++++++++++ .../org/bitbiome/classes/TravelEngine.java | 11 +- .../bitbiome/commands/BlackJackCommand.java | 109 +++++ .../org/bitbiome/commands/CommandAPI.java | 4 + .../bitbiome/commands/CommandListener.java | 2 +- .../org/bitbiome/commands/HelpCommand.java | 29 +- .../bitbiome/commands/LookaroundCommand.java | 14 +- .../org/bitbiome/commands/QuitCommand.java | 7 +- .../org/bitbiome/commands/QuizCommand.java | 107 +++++ .../org/bitbiome/commands/ShopCommand.java | 85 ++++ .../org/bitbiome/commands/TravelCommand.java | 15 +- src/main/java/org/bitbiome/entities/Item.java | 43 +- .../java/org/bitbiome/entities/Location.java | 8 + src/main/java/org/bitbiome/entities/Mob.java | 4 + .../java/org/bitbiome/entities/Player.java | 15 +- src/main/resources/gameconfig.json | 102 ++--- src/main/resources/items.json | 69 +-- src/main/resources/playerconfig.json | 8 +- src/main/resources/quiz.json | 405 +++++++++--------- .../org/bitbiome/classes/BlackJackTest.java | 44 ++ .../java/org/bitbiome/classes/ColorsTest.java | 23 + .../bitbiome/commands/CollectCommandTest.java | 2 +- .../bitbiome/commands/HelpCommandTest.java | 25 +- .../commands/InventoryCommandTest.java | 4 +- .../commands/LookaroundCommandTest.java | 20 +- .../bitbiome/commands/QuitCommandTest.java | 4 +- .../bitbiome/commands/QuizCommandTest.java | 36 ++ .../bitbiome/commands/ShopCommandTest.java | 87 ++++ .../org/bitbiome/entitiesTest/ItemTest.java | 50 +++ .../bitbiome/entitiesTest/LocationTest.java | 24 ++ .../org/bitbiome/entitiesTest/MobTest.java | 35 ++ .../org/bitbiome/entitiesTest/PlayerTest.java | 43 ++ 40 files changed, 1574 insertions(+), 487 deletions(-) create mode 100644 playerconfig.json create mode 100644 src/main/java/org/bitbiome/classes/BlackJack.java delete mode 100644 src/main/java/org/bitbiome/classes/CreateLocations.java create mode 100644 src/main/java/org/bitbiome/classes/Shop.java create mode 100644 src/main/java/org/bitbiome/commands/BlackJackCommand.java create mode 100644 src/main/java/org/bitbiome/commands/QuizCommand.java create mode 100644 src/main/java/org/bitbiome/commands/ShopCommand.java create mode 100644 src/test/java/org/bitbiome/classes/BlackJackTest.java create mode 100644 src/test/java/org/bitbiome/classes/ColorsTest.java create mode 100644 src/test/java/org/bitbiome/commands/QuizCommandTest.java create mode 100644 src/test/java/org/bitbiome/commands/ShopCommandTest.java create mode 100644 src/test/java/org/bitbiome/entitiesTest/ItemTest.java create mode 100644 src/test/java/org/bitbiome/entitiesTest/LocationTest.java create mode 100644 src/test/java/org/bitbiome/entitiesTest/MobTest.java create mode 100644 src/test/java/org/bitbiome/entitiesTest/PlayerTest.java diff --git a/README.md b/README.md index e69de29..f39622f 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,27 @@ +*Hier Logo* +--- +# BitBiome - TextAdventure +## What is the game about? +BitBiome is an exciting text adventure. Whether you want to travel through exciting biomes or measure with dangerous opponents. You can prove your knowledge in a quiz and buy new items in the shop as a reward. +BitBiome is a game for everyone who likes dangerous adventures. + +## Commands: +- help +- exit / quit +- quiz +- quitquiz / canclequiz +- shop +- travel +- location + +## Our developers: +- David Hermann +- Julia Kunze +- Frederike von Gruben +- Philipp Völler +- Tanja Herche +- Max Gerbeth + +--- + +*Fulda University of Applied Sciences - Applied Computer Science (#AI1001 Papendieck)* diff --git a/playerconfig.json b/playerconfig.json new file mode 100644 index 0000000..cd54cdc --- /dev/null +++ b/playerconfig.json @@ -0,0 +1,24 @@ +{ + "gold": 0, + "name": "null", + "hp": 10, + "inventory": [ + { + "gold": 5, + "damage": "10", + "amount": 5, + "durability": 1000, + "name": "Holz", + "doesDamage": true + }, + { + "gold": 5, + "damage": "10", + "amount": 5, + "durability": 1000, + "name": "Stein", + "doesDamage": true + } + ], + "currentLocation": "Wald" +} \ No newline at end of file diff --git a/src/main/java/org/bitbiome/Boot.java b/src/main/java/org/bitbiome/Boot.java index 0f5ebdd..4852196 100644 --- a/src/main/java/org/bitbiome/Boot.java +++ b/src/main/java/org/bitbiome/Boot.java @@ -26,8 +26,7 @@ public class Boot { private Player getPlayerSave() { String name; - JsonParser jp = new JsonParser(); - JSONObject playerconfig = jp.getJSONObject("playerconfig.json"); + JSONObject playerconfig = JsonParser.getJSONObject("src/main/resources/playerconfig.json"); name = playerconfig.getString("name"); return new Player(name); } diff --git a/src/main/java/org/bitbiome/classes/BlackJack.java b/src/main/java/org/bitbiome/classes/BlackJack.java new file mode 100644 index 0000000..19d210e --- /dev/null +++ b/src/main/java/org/bitbiome/classes/BlackJack.java @@ -0,0 +1,96 @@ +package org.bitbiome.classes; + +import java.util.Random; + +public class BlackJack { + + public enum Entity { + PLAYER(1), BOT(2); + private int value; + + private Entity(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + //Just for testing from some SO answers, but no use + public void setValue(int value) { + this.value = value; + } + + public static Entity getEventStatusById(int id) { + + Entity entity = null; + + switch (id) { + case 1 -> entity = PLAYER; + case 2 -> entity = BOT; + default -> { + } + } + return entity; + } + } + + private String playerName; + private int playerPoints; + private int botPoints; + private boolean playerIn; + private boolean botIn; + + public BlackJack(String playerName) { + this.playerName = playerName; + this.playerPoints = 0; + this.botPoints = 0; + this.playerIn = true; + this.botIn = true; + } + + public String getPlayerName(Entity entity) { + return entity == Entity.PLAYER ? playerName : "BitBiome"; + } + + public int getPoints(Entity entity) { + return entity == Entity.PLAYER ? playerPoints : botPoints; + } + + public boolean isIn(Entity entity) { + return entity == Entity.PLAYER ? playerIn : botIn; + } + + public Entity getEntity(int ID) { + return Entity.getEventStatusById(ID); + } + + public void addPoints(Entity entity, int points) { + if (entity == Entity.BOT) botPoints += points; + if (entity == Entity.PLAYER) playerPoints += points; + } + + public boolean botWantsToPlay() { + if (botIn) { + if (botPoints <= 10) { + return true; + } else if (botPoints <= 17) { + int r = new Random().nextInt(1, 9); + if (r <= 3) { + botIn = false; + return false; + } else { + return true; + } + } else { + botIn = false; + return false; + } + } else { + return false; + } + } + + public void playerOut() { + this.playerIn = false; + } +} diff --git a/src/main/java/org/bitbiome/classes/Colors.java b/src/main/java/org/bitbiome/classes/Colors.java index d08f59e..99e45e1 100644 --- a/src/main/java/org/bitbiome/classes/Colors.java +++ b/src/main/java/org/bitbiome/classes/Colors.java @@ -2,55 +2,61 @@ 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 }; + /* + * 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/CreateLocations.java b/src/main/java/org/bitbiome/classes/CreateLocations.java deleted file mode 100644 index ed237a1..0000000 --- a/src/main/java/org/bitbiome/classes/CreateLocations.java +++ /dev/null @@ -1,24 +0,0 @@ -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 2523644..ee504d6 100644 --- a/src/main/java/org/bitbiome/classes/InteractionLoop.java +++ b/src/main/java/org/bitbiome/classes/InteractionLoop.java @@ -10,24 +10,39 @@ public class InteractionLoop { 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); + if (playerIsNew(travelEngine.getPlayer().getName())) { + newPlayerWelcome(travelEngine); } - System.out.println(Colors.ANSI_BG_CYAN + Colors.ANSI_BLACK + "Willkommen zu BitBiome " + travelEngine.getPlayer().getName() + "!" + Colors.ANSI_RESET + "\n\n"); + 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, travelEngine)) { - 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(); + JSONObject playerconf = JsonParser.getJSONObject("src/main/resources/playerconfig.json"); + playerconf.put("name", name); + travelEngine.getPlayer().setName(name); + JsonParser.writeObject("src/main/resources/playerconfig.json", playerconf); + } } diff --git a/src/main/java/org/bitbiome/classes/JsonParser.java b/src/main/java/org/bitbiome/classes/JsonParser.java index 0eb23d5..d9657e1 100644 --- a/src/main/java/org/bitbiome/classes/JsonParser.java +++ b/src/main/java/org/bitbiome/classes/JsonParser.java @@ -1,15 +1,10 @@ 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; - - +import java.io.FileReader; public class JsonParser { @@ -28,20 +23,30 @@ public class JsonParser { https://github.com/stleary/JSON-java */ - 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); + public static JSONObject getJSONObject(String filePath) { + StringBuilder sb = null; + try { + FileReader reader = new FileReader(filePath); + char[] buffer = new char[1024]; + int length; + sb = new StringBuilder(); + while ((length = reader.read(buffer)) != -1) { + sb.append(buffer, 0, length); + } + + reader.close(); + + } catch (IOException e) { + System.out.println(e); } - JSONTokener tokener = new JSONTokener(is); - return new JSONObject(tokener); + return new JSONObject(sb.toString()); } - public void writeObject(String fileName, JSONObject object) { + public static void writeObject(String fileName, JSONObject object) { + + String resourceName = fileName; - String resourceName = System.getProperty("user.dir") + "/src/main/resources/" + fileName; try { FileWriter fw = new FileWriter(resourceName, false); fw.write(object.toString(1)); @@ -49,7 +54,5 @@ public class JsonParser { } catch (IOException e) { throw new RuntimeException(e); } - - } } diff --git a/src/main/java/org/bitbiome/classes/Shop.java b/src/main/java/org/bitbiome/classes/Shop.java new file mode 100644 index 0000000..f42de54 --- /dev/null +++ b/src/main/java/org/bitbiome/classes/Shop.java @@ -0,0 +1,273 @@ +package org.bitbiome.classes; + +import org.bitbiome.commands.BlackJackCommand; +import org.bitbiome.commands.QuizCommand; +import org.bitbiome.entities.Item; +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Random; +import java.util.Scanner; + +public class Shop { + public ArrayList allItems; + public ArrayList currentShopItems; + public QuizCommand quizCommand = new QuizCommand(); + public BlackJackCommand blackJackCommand = new BlackJackCommand(); + public Scanner scanner; + public boolean isRunning; + public String message; + public TravelEngine travelEngine; + + public Shop(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngin) { + this.scanner = scanner; + this.message = message; + this.isRunning = isRunning; + this.travelEngine = travelEngin; + + try { + allItems = loadAllItems(); + currentShopItems = loadPartofItems(allItems, 3); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public boolean buy(String itemName, int amount) { + // Create File Objects + currentShopItems = loadCurrentShopItems(); + File filePlayerConfig = new File("src/main/resources/playerconfig.json"); + File fileGameConfig = new File("src/main/resources/gameconfig.json"); + File fileItem = new File("src/main/resources/items.json"); + try { + // Create JSONObjects + String content1 = new String(Files.readAllBytes(Paths.get(filePlayerConfig.toURI())), "UTF-8"); + JSONObject playerConfig = new JSONObject(content1); + + String content2 = new String(Files.readAllBytes(Paths.get(fileGameConfig.toURI())), "UTF-8"); + JSONObject gameConfig = new JSONObject(content2); + + String content3 = new String(Files.readAllBytes(Paths.get(fileItem.toURI())), "UTF-8"); + JSONArray itemJSON = new JSONArray(content3); + + // Test if item still available in the shop + int itemIndex = -1; + for (int i = 0; i < currentShopItems.size(); i++) { + if (currentShopItems.get(i).getName().equals(itemName)) { + itemIndex = i; + } + } + if (itemIndex == -1) { + System.out.println( + Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Dieses Item gibt es nicht!" + Colors.ANSI_RESET); + return false; + } + if (!(currentShopItems.get(itemIndex).getAmount() > 0)) { + System.out.println( + Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Es gibt zu wenige Items!" + Colors.ANSI_RESET); + return false; + } + // Test if the player has enough gold + int costs = currentShopItems.get(itemIndex).getGold() * amount; + int gold = (int) playerConfig.get("gold"); + if (!(gold >= costs)) { + System.out + .println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Du hast zu wenig Gold!" + Colors.ANSI_RESET); + return false; + } + + // Player gold subtract + playerConfig.put("gold", subtractGold(gold, costs)); + + // Gameconfig amount reduese + JSONArray jsonArray2 = gameConfig.getJSONArray("shopitems"); + int intNewAmount; + + for (int i = 0; i < jsonArray2.length(); i++) { + JSONObject tempJSON = jsonArray2.getJSONObject(i); + if (tempJSON.getString("name").equals(itemName)) { + intNewAmount = tempJSON.getInt("amount") - amount; + jsonArray2.remove(i); + tempJSON.put("amount", intNewAmount); + jsonArray2.put(tempJSON); + gameConfig.put("shopitems", jsonArray2); + JsonParser.writeObject("src/main/resources/gameconfig.json", gameConfig); + currentShopItems = loadCurrentShopItems(); + break; + } + } + + // Give Player the Item + JSONArray jsonArray = playerConfig.getJSONArray("inventory"); + int newAmount; + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject tempJSON = jsonArray.getJSONObject(i); + if (tempJSON.getString("name").equals(itemName)) { + newAmount = tempJSON.getInt("amount") + amount; + jsonArray.remove(i); + tempJSON.put("amount", newAmount); + jsonArray.put(tempJSON); + playerConfig.put("inventory", jsonArray); + JsonParser.writeObject("src/main/resources/playerconfig.json", playerConfig); + return true; + } + } + + // Item do not exist in the playerinventory + int durability = 0; + for (int i = 0; i < itemJSON.length(); i++) { + JSONObject tempJSON = itemJSON.getJSONObject(i); + if (tempJSON.getString("name").equals(itemName)) { + durability = (int) tempJSON.get("durability"); + } + } + + JSONObject inventory = new JSONObject(); + inventory.put("name", itemName); + inventory.put("amount", 1); + inventory.put("durability", durability); + + jsonArray.put(inventory); + playerConfig.put("inventory", jsonArray); + JsonParser.writeObject("src/main/resources/playerconfig.json", playerConfig); + + } catch (Exception e) { + e.printStackTrace(); + } + + return true; + } + + private ArrayList loadAllItems() { + ArrayList arrayList = new ArrayList<>(); + JSONArray itemJSON = returnJSONArrayOfAllItems(); + + arrayList = addToList(itemJSON, arrayList, "amountShop"); + return arrayList; + } + + public static JSONArray returnJSONArrayOfAllItems() { + File file = new File("src/main/resources/items.json"); + JSONArray itemJSON = null; + try { + String content3 = new String(Files.readAllBytes(Paths.get(file.toURI())), "UTF-8"); + itemJSON = new JSONArray(content3); + } catch (Exception e) { + e.printStackTrace(); + } + return itemJSON; + } + + public ArrayList loadCurrentShopItems() { + + ArrayList arrayList = new ArrayList<>(); + JSONObject jsonObject = JsonParser.getJSONObject("src/main/resources/gameconfig.json"); + JSONArray jsonArray = jsonObject.getJSONArray("shopitems"); + + return addToList(jsonArray, arrayList, "amount"); + } + + public JSONObject getItemByName(String itemName, JSONArray itemArray) { + for (int i = 0; i < itemArray.length(); i++) { + if (itemArray.getJSONObject(i).getString("name").equals(itemName)) { + return itemArray.getJSONObject(i); + } + } + return null; + } + + public ArrayList addToList(JSONArray itemJSON, ArrayList arrayList, String key) { + JSONArray allItems = returnJSONArrayOfAllItems(); + for (int i = 0; i < itemJSON.length(); i++) { + JSONObject tempJSON = itemJSON.getJSONObject(i); + String damage; + boolean doesDmg; + if (key.equals("amount")) { + damage = getItemByName(tempJSON.getString("name"), allItems).getString("damage"); + } else { + damage = tempJSON.getString("damage"); + } + doesDmg = !damage.equals("0") ? false : true; + arrayList.add(new Item(tempJSON.getString("name"), doesDmg, damage, tempJSON.getInt(key), + tempJSON.getInt("gold"))); + } + return arrayList; + } + + private ArrayList loadPartofItems(ArrayList alleItems, int itemCount) { + ArrayList arrayList = new ArrayList<>(); + try { + File fileGameConfig = new File("src/main/resources/gameconfig.json"); + String content2 = new String(Files.readAllBytes(Paths.get(fileGameConfig.toURI())), "UTF-8"); + JSONObject gameConfig = new JSONObject(content2); + + //JSONArray jsonArray = gameConfig.getJSONArray("shopitems"); + HashSet hashSet = new HashSet<>(); + JSONArray shopitems = new JSONArray(); + Random random = new Random(); + while (hashSet.size() < itemCount) { + int rand = random.nextInt(alleItems.size()); + if (!hashSet.contains(rand)) { + hashSet.add(rand); + arrayList.add(alleItems.get(rand)); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", alleItems.get(rand).getName()); + jsonObject.put("amount", alleItems.get(rand).getAmount()); + jsonObject.put("gold", alleItems.get(rand).getGold()); + shopitems.put(jsonObject); + } + } + // write in gameconfig.json + gameConfig.remove("shopitems"); + gameConfig.put("shopitems", shopitems); + JsonParser.writeObject("src/main/resources/gameconfig.json", gameConfig); + + } catch (Exception e) { + e.printStackTrace(); + } + + return arrayList; + } + + public void itemRotation() { + try { + currentShopItems = loadPartofItems(allItems, 3); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void printCurrentShopItems() { + printArrayList(currentShopItems); + } + + public void quiz() { + quizCommand.performCommand(scanner, isRunning, message, travelEngine); + } + + public void blackJack() { + System.out.println(""); + blackJackCommand.performCommand(scanner, isRunning, message, travelEngine); + System.out.println(""); + } + + private void printArrayList(ArrayList arrayList) { + System.out.println(""); + for (int i = 0; i < arrayList.size(); i++) { + if (arrayList.get(i).getAmount() != 0) { + System.out.println(arrayList.get(i).getName() + " | Anzahl: " + arrayList.get(i).getAmount() + + " | Kosten: " + arrayList.get(i).getGold()); + } + } + System.out.println(""); + } + + public int subtractGold(int gold, int cost) { + return gold - cost; + } +} diff --git a/src/main/java/org/bitbiome/classes/TravelEngine.java b/src/main/java/org/bitbiome/classes/TravelEngine.java index 4eb63d6..d463273 100644 --- a/src/main/java/org/bitbiome/classes/TravelEngine.java +++ b/src/main/java/org/bitbiome/classes/TravelEngine.java @@ -10,21 +10,19 @@ 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"); + locations = JsonParser.getJSONObject("src/main/resources/gameconfig.json").getJSONArray("locations"); this.player = player; } public void travelTo(Location location) { player.setLocation(location); - JSONObject jObj = jp.getJSONObject("playerconfig.json"); + JSONObject jObj = JsonParser.getJSONObject("src/main/resources/playerconfig.json"); jObj.put("currentLocation", location.getName()); - jp.writeObject("playerconfig.json", jObj); + JsonParser.writeObject("src/main/resources/playerconfig.json", jObj); } public Player getPlayer() { @@ -45,8 +43,7 @@ public class TravelEngine { } public Location getLocationByName(String name) { - JsonParser jp = new JsonParser(); - JSONObject gameconfig = jp.getJSONObject("gameconfig.json"); + JSONObject gameconfig = JsonParser.getJSONObject("src/main/resources/gameconfig.json"); JSONArray locations = gameconfig.getJSONArray("locations"); JSONObject location = null; if (locationExists(name)) { diff --git a/src/main/java/org/bitbiome/commands/BlackJackCommand.java b/src/main/java/org/bitbiome/commands/BlackJackCommand.java new file mode 100644 index 0000000..bc8381b --- /dev/null +++ b/src/main/java/org/bitbiome/commands/BlackJackCommand.java @@ -0,0 +1,109 @@ +package org.bitbiome.commands; + + +import org.bitbiome.classes.BlackJack; +import org.bitbiome.classes.TravelEngine; + +import java.util.Random; +import java.util.Scanner; + +public class BlackJackCommand implements CommandAPI { + private boolean over; + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + + System.out.println("Du hast das Spiel BlackJack gestartet. Die Spielregeln lauten wie folgt: Du und dein Gegner bekommen jede Runde Zahlen von 4 - 11. \nDerjenige, der zuerst 21 Punkte hat gewinnt. Derjenige, der über 21 Punkte hat verliert. Möchte keiner mehr Karten ziehen, gewinnt der mit dem höchsten Blatt!\nViel Spaß!"); + + over = false; + spielen(); + } + Scanner sc; + public void spielen() { + BlackJack bj = new BlackJack("Dave"); + sc = new Scanner(System.in); + BlackJack.Entity player = bj.getEntity(1); + while (!over) { + int r = new Random().nextInt(4, 11); + bj.addPoints(player, r); + System.out.println(bj.getPlayerName(player) + " hat " + r + " bekommen. Er hat insgesamt " + bj.getPoints(player) + "."); + + if (bj.getPoints(player) >= 21) { + over21(player, bj); + has21(player, bj); + over = true; + break; + } + System.out.print("Weiter?"); + + if (player == BlackJack.Entity.BOT) { + if (bj.botWantsToPlay()) { + System.out.println("Na klar!"); + } else { + System.out.println("Nope, ich bin fertig."); + } + } else { + String eingabe = sc.nextLine(); + if (!eingabe.toLowerCase().startsWith("j")) { + bj.playerOut(); + } + } + + + player = switchPlayer(player, bj); + + } + } + + public void over21(BlackJack.Entity player, BlackJack bj) { + if (bj.getPoints(player) > 21) { + over = true; + System.out.println(bj.getPlayerName(player) + " hat über 21 Punkte und damit verloren."); + } + + } + + + public void has21(BlackJack.Entity player, BlackJack bj) { + if (bj.getPoints(player) == 21) { + System.out.println(bj.getPlayerName(player) + " hat gewonnen! Du hast 21 Punkte!"); + over = true; + } + } + + public BlackJack.Entity switchPlayer(BlackJack.Entity player, BlackJack bj) { + BlackJack.Entity BOT = BlackJack.Entity.BOT; + BlackJack.Entity PLAYER = BlackJack.Entity.PLAYER; + if (bj.isIn(BOT) || bj.isIn(PLAYER)) { + if (player == PLAYER) { + if (bj.isIn(BOT)) { + return BOT; + } + return PLAYER; + } else { + if (bj.isIn(PLAYER)) { + return PLAYER; + } + return BOT; + } + } else { + over = true; + getWinner(bj); + return null; + } + } + + + public void getWinner(BlackJack bj) { + BlackJack.Entity entity; + if (bj.getPoints(BlackJack.Entity.BOT) < bj.getPoints(BlackJack.Entity.PLAYER)) { + entity = BlackJack.Entity.PLAYER; + System.out.println(bj.getPlayerName(entity) + " hat gewonnen, da er mehr Punkte hat!"); + } else if (bj.getPoints(BlackJack.Entity.BOT) == bj.getPoints(BlackJack.Entity.PLAYER)){ + System.out.println("Es ist Gleichstand!"); + } else { + entity = BlackJack.Entity.BOT; + System.out.println(bj.getPlayerName(entity) + " hat gewonnen, da er mehr Punkte hat!"); + } + + } +} \ No newline at end of file diff --git a/src/main/java/org/bitbiome/commands/CommandAPI.java b/src/main/java/org/bitbiome/commands/CommandAPI.java index a5c48be..9e5ade8 100644 --- a/src/main/java/org/bitbiome/commands/CommandAPI.java +++ b/src/main/java/org/bitbiome/commands/CommandAPI.java @@ -5,6 +5,10 @@ import org.bitbiome.classes.TravelEngine; import java.util.Scanner; public interface CommandAPI { + + // 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 33d6e6c..e2f9ec3 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -21,7 +21,7 @@ public class CommandListener { commands.put("inventory", new InventoryCommand()); commands.put("lookaround", new LookaroundCommand()); commands.put("collect", new CollectCommand()); - + commands.put("shop", new ShopCommand()); } public HashMap returnCommands() { diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java index 82b6763..1df1588 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -18,17 +18,23 @@ public class HelpCommand implements CommandAPI { public static String getHelpMessage() { 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") + .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") + .append("|" + Colors.ANSI_GREEN + " quiz" + Colors.ANSI_RESET + " | Startet das quiz im shop |\n") + .append("|--------------|-----------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " blackjack" + Colors.ANSI_RESET + " | Startet blackjack im shop |\n") + .append("|--------------|-----------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " location" + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") + .append("|--------------|-----------------------------|\n") .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") .append("|--------------|-------------------------------|\n") .append("|" + Colors.ANSI_GREEN + " collect " + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") @@ -36,7 +42,6 @@ public class HelpCommand implements CommandAPI { .append("|" + Colors.ANSI_GREEN + " lookaround" + Colors.ANSI_RESET + " | Zeigt dir deine Umgebung, |\n") .append("|" + Colors.ANSI_GREEN + " " + Colors.ANSI_RESET + " | Items und Mobs in der Nähe |\n") .append("|______________|_______________________________|\n"); - return outputMessage.toString(); } diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index 182e94d..b1ae8ed 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -2,6 +2,7 @@ package org.bitbiome.commands; import org.bitbiome.classes.Colors; import org.bitbiome.classes.JsonParser; +import org.bitbiome.classes.Shop; import org.bitbiome.classes.TravelEngine; import org.bitbiome.entities.*; import org.json.JSONArray; @@ -19,7 +20,7 @@ public class LookaroundCommand implements CommandAPI{ StringBuilder outputMessage = new StringBuilder(); Location location = travelEngine.getPlayer().getLocation(); JsonParser jp = new JsonParser(); - JSONObject gameConfig = jp.getJSONObject("gameconfig.json"); + JSONObject gameConfig = jp.getJSONObject("src/main/resources/gameconfig.json"); JSONArray locations = gameConfig.getJSONArray("locations"); JSONObject locationObject = getLocationObject(location.getName(), locations); JSONArray items = locationObject.getJSONArray("items"); @@ -52,13 +53,8 @@ public class LookaroundCommand implements CommandAPI{ public ArrayList getRandomItem(int randomNumberItems, Random random, JSONArray items, ArrayList foundItems ) { for (int i=0; i 0) { + print(Colors.ANSI_BG_RED + "Du darfst erst in " + diffTime / 1000 / 60 + " Minuten spielen." + Colors.ANSI_RESET + "\n"); + return; + } + + JSONArray fragen = quiz.getJSONArray("Quiz"); + JSONObject frage = fragen.getJSONObject(random(fragen.length())); + + JSONArray antworten = frage.getJSONArray("antworten"); + + + String korrekteAntwort = frage.getString("korrekteAntwort"); + + print(starterMessage()); + + print(generateQuestion(frage, antworten)); + + int eingabe = quizScanner.nextInt(); + + if (answerIsCorrect(eingabe, korrekteAntwort, antworten)) { + int neuerStand = addGold(); + print(Colors.ANSI_BG_GREEN + "Richtig! Du hast 5 Münzen verdient." + Colors.ANSI_RESET + Colors.ANSI_CYAN + "\nDein Münzstand beträgt: " + Colors.ANSI_RESET + Colors.ANSI_BLUE + neuerStand + Colors.ANSI_RESET); + } else { + print(Colors.ANSI_BG_RED + "Leider falsch... Richtig ist: " + korrekteAntwort + Colors.ANSI_RESET + "\n"); + } + + print(endMessage()); + + Date d = new Date(); + long lastPlayed = d.getTime(); + quiz.put("lastPlayed", lastPlayed); + JsonParser.writeObject(path, quiz); + } + + public static boolean answerIsCorrect(int picked, String answer, JSONArray answers) { + return answers.getString(picked - 1).equalsIgnoreCase(answer); + } + + public static String print(String message) { + System.out.println(message); + return message; + } + + public static int random(int length) { + return new Random().nextInt(length); + } + + public static String generateQuestion(JSONObject frage, JSONArray answers) { + StringBuilder sb = new StringBuilder(); + sb.append(frage.getString("frage")).append("\n"); + for (int i = 0; i < answers.length(); i++) { + sb.append(i+1).append(". ").append(answers.getString(i)).append("\n"); + } + return sb.toString(); + } + + public static int addGold() { + String playerpath = "src/main/resources/playerconfig.json"; + JSONObject playerconfig = JsonParser.getJSONObject(playerpath); + int gold = playerconfig.getInt("gold"); + gold = gold + 5; + playerconfig.put("gold", gold); + JsonParser.writeObject(playerpath, playerconfig); + return gold; + } + + public static long canPlayAgain(long lastPlayedTime) { + long currentTime = System.currentTimeMillis(); + long minTime = lastPlayedTime + (60 * 5 * 1000); + return minTime - currentTime; + } + + public static String starterMessage(){ + return Colors.ANSI_CYAN + "Du hast das Quiz gestartet! Hinweis: Wähle deine Antwort, indem du die Zahl (1-4) eingibst. Ist deine Lösung richtig, erhälst du 5 Münzen. Viel Erfolg!" + Colors.ANSI_RESET + " \n"; + + } + + public static String endMessage(){ + return Colors.ANSI_CYAN + "Das Quiz ist vorbei!" + Colors.ANSI_RESET; + } +} + + diff --git a/src/main/java/org/bitbiome/commands/ShopCommand.java b/src/main/java/org/bitbiome/commands/ShopCommand.java new file mode 100644 index 0000000..b83887f --- /dev/null +++ b/src/main/java/org/bitbiome/commands/ShopCommand.java @@ -0,0 +1,85 @@ +package org.bitbiome.commands; + +import org.bitbiome.classes.BlackJack; +import org.bitbiome.classes.Colors; +import org.bitbiome.classes.Shop; +import org.bitbiome.classes.TravelEngine; +import org.bitbiome.entities.Item; + +import java.util.ArrayList; +import java.util.Scanner; + +public class ShopCommand implements CommandAPI{ + + Shop shop; + BlackJack blackJack; + public ShopCommand(){ + + } + + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + shop = new Shop(scanner, isRunning, message, travelEngine); + blackJack = new BlackJack(travelEngine.getPlayer().getName()); + System.out.println(Colors.ANSI_BG_YELLOW + Colors.ANSI_BLACK + "Willkommen im Shop!" + Colors.ANSI_RESET); + ArrayList currentItems = shop.loadCurrentShopItems(); + + //whileloop for userinputs in the shop + while (true){ + System.out.println("Was willst Du hier im Shop?"); + System.out.println(Colors.ANSI_CYAN + "Etwas kaufen: 1"); + System.out.println("Das Quiz spielen: 2"); + System.out.println("Blackjack spielen: 3"); + System.out.println("Den Shop verlassen: 4" + Colors.ANSI_RESET); + + String input = scanner.nextLine(); + if(validInput(input)){ + if(input.equals("1")){ + System.out.println("Folgende Items sind im Shop: "); + for(int i = 0; i < currentItems.size(); i++){ + System.out.println((i + 1) + ". " + currentItems.get(i).getName() + " | Anzahl: " + currentItems.get(i).getAmount() + " | Gold: " + currentItems.get(i).getGold()); + } + System.out.println("0 Eingeben um den Shop zu verlassen."); + System.out.println(""); + System.out.print("Welches Item moechtest du kaufen? "); + String itemNumber = scanner.nextLine(); + if(!itemNumber.equals("0")) { + System.out.print("Anzahl eingeben: "); + String amount = scanner.nextLine(); + try { + if ((Integer.parseInt(amount) <= currentItems.get(Integer.parseInt(itemNumber) - 1).getAmount()) && ((Integer.parseInt(amount) - 1) > -1)) { + boolean bool = shop.buy(currentItems.get(Integer.parseInt(itemNumber) - 1).getName(), Integer.parseInt(amount)); + currentItems = shop.loadCurrentShopItems(); + if (bool) { + System.out.println(""); + System.out.println(Colors.ANSI_BG_GREEN + Colors.ANSI_BLACK + "Vielen Dank für Ihren Einkauf!" + Colors.ANSI_RESET); + System.out.println(""); + } else { + System.out.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Fehler!" + Colors.ANSI_RESET); + } + } else { + System.out.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Fehler!" + Colors.ANSI_RESET); + } + }catch (Exception e){ + System.out.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Fehler!" + Colors.ANSI_RESET); + } + } + } else if(input.equals("2")){ + shop.quiz(); + } else if(input.equals("3")){ + shop.blackJack(); + }else if(input.equals("4")){ + System.out.println(Colors.ANSI_BG_YELLOW + "Der Shop wurde verlassen!" + Colors.ANSI_RESET); + break; + } + }else { + System.out.println("Unbekannte Eingabe!"); + } + } + } + + public static boolean validInput(String input){ + return (input.equals("1") || input.equals("2") || input.equals("3") || input.equals("4")); + } + +} diff --git a/src/main/java/org/bitbiome/commands/TravelCommand.java b/src/main/java/org/bitbiome/commands/TravelCommand.java index ca68bf5..810333e 100644 --- a/src/main/java/org/bitbiome/commands/TravelCommand.java +++ b/src/main/java/org/bitbiome/commands/TravelCommand.java @@ -1,7 +1,7 @@ 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; @@ -16,18 +16,23 @@ 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); + 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++) { - System.out.println("- " + locations.getJSONObject(i).getString("name")); + print("- " + 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); + print(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); + 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 index f0da23a..cb3f280 100644 --- a/src/main/java/org/bitbiome/entities/Item.java +++ b/src/main/java/org/bitbiome/entities/Item.java @@ -2,27 +2,49 @@ package org.bitbiome.entities; public class Item { - public String name; - public int amount; - public boolean doesDamage; - public float damage; + private String name; + private boolean doesDamage; + private String damage; + private int amount; + private int gold; - public Item(String name, boolean doesDamage, float damage, int amount) { + public Item(String name, boolean doesDamage, String damage, int amount, int gold) { this.name = name; this.doesDamage = doesDamage; this.damage = damage; this.amount = amount; + this.gold = gold; + } + + public Item() { + } public String getName() { return name; } - public float getDamage() { + public int getAmount() { + return amount; + } + + public void setAmount(int amount) { + this.amount = amount; + } + + public String getDamage() { return damage; } + public int getGold() { + return gold; + } + + public void setGold(int gold){ + this.gold = gold; + } + public boolean doesDamage() { return doesDamage; } @@ -31,19 +53,12 @@ public class Item { this.name = name; } - public void setDamage(float damage) { + public void setDamage(String damage) { this.damage = damage; } public void changeDoesDamage(boolean doesDamage) { this.doesDamage = doesDamage; } - public int getAmount(){ - return amount; - } - public void setAmount(int amount){ - this.amount = amount; - } - } diff --git a/src/main/java/org/bitbiome/entities/Location.java b/src/main/java/org/bitbiome/entities/Location.java index 98c04d1..664509d 100644 --- a/src/main/java/org/bitbiome/entities/Location.java +++ b/src/main/java/org/bitbiome/entities/Location.java @@ -15,6 +15,10 @@ public class Location { this.itemList = itemList; } + public Location() { + + } + public String getName() { return name; @@ -28,6 +32,10 @@ public class Location { 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 index af479ce..4bb0d03 100644 --- a/src/main/java/org/bitbiome/entities/Mob.java +++ b/src/main/java/org/bitbiome/entities/Mob.java @@ -15,6 +15,10 @@ public class Mob { this.damage = damage; } + public Mob() { + + } + public String getName() { return name; } diff --git a/src/main/java/org/bitbiome/entities/Player.java b/src/main/java/org/bitbiome/entities/Player.java index 7eef0fe..a2f1c45 100644 --- a/src/main/java/org/bitbiome/entities/Player.java +++ b/src/main/java/org/bitbiome/entities/Player.java @@ -1,6 +1,6 @@ package org.bitbiome.entities; -import org.bitbiome.classes.CreateLocations; + import org.bitbiome.classes.JsonParser; import org.json.JSONArray; import org.json.JSONObject; @@ -15,22 +15,25 @@ public class Player { 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<>()); + location = new Location(JsonParser.getJSONObject("src/main/resources/playerconfig.json").getString("currentLocation"), new ArrayList<>(), new ArrayList<>()); inventory = new ArrayList<>(); - JSONArray items = jp.getJSONObject("playerconfig.json").getJSONArray("inventory"); + JSONArray items = JsonParser.getJSONObject("src/main/resources/playerconfig.json").getJSONArray("inventory"); for (int i = 0; i < items.length(); i++) { JSONObject o = items.getJSONObject(i); - inventory.add(new Item(o.getString("name"), o.getBoolean("doesDamage"), o.getFloat("damage"), o.getInt("amount"))); + inventory.add(new Item(o.getString("name"), o.getBoolean("doesDamage"), o.getString("damage"), o.getInt("amount"), o.getInt("gold"))); } + } + + public Player() { + } public String getName() { diff --git a/src/main/resources/gameconfig.json b/src/main/resources/gameconfig.json index 847633e..cdd66c4 100644 --- a/src/main/resources/gameconfig.json +++ b/src/main/resources/gameconfig.json @@ -1,57 +1,49 @@ { - "shopitems": [ - { - "name": "Holz", - "amount": 10, - "gold": 10 - }, - { - "name": "Heiliges Schwert der Engel", - "amount": 1, - "gold": 1000 - }, - { - "name": "Stein", - "amount": 5, - "gold": 100 - } - ], - "locations": [ - { - "name": "Wald", - "items": [ - "Holz", - "Stein" - ], - "mobs": [ - { - "name": "Big Foot", - "hp": 50, - "damage": 15, - "isFriendly": true, - "items": [ - "Fell" - ] - } - ] - }, - { - "name": "Strand", - "items": [ - "Holz", - "Stein" - ], - "mobs": [ - { - "name": "Big Foot", - "hp": 50, - "damage": 15, - "isFriendly": true, - "items": [ - "Fell" - ] - } - ] - } - ] + "shopitems": [ + { + "gold": 1000, + "amount": 1, + "name": "Heiliges Schwert der Engel" + }, + { + "gold": 2, + "amount": 1500, + "name": "Stein" + }, + { + "gold": 10, + "amount": 10, + "name": "Holz" + } + ], + "locations": [ + { + "mobs": [{ + "isFriendly": true, + "damage": "15", + "name": "Big Foot", + "hp": 50, + "items": ["Fell"] + }], + "name": "Wald", + "items": [ + "Holz", + "Stein" + ] + }, + { + "mobs": [{ + "isFriendly": true, + "damage": "15", + "name": "Big Foot", + "hp": 50, + "items": ["Fell"] + }], + "name": "Strand", + "items": [ + "Holz", + "Stein" + ] + } + ] } \ No newline at end of file diff --git a/src/main/resources/items.json b/src/main/resources/items.json index 7786427..3d4e8f2 100644 --- a/src/main/resources/items.json +++ b/src/main/resources/items.json @@ -1,30 +1,39 @@ -[ - { - "name": "Holz", - "damage": 0, - "crafting": true, - "durability": 1000, - "doesDamage": false - }, - { - "name": "Heiliges Schwert der Engel", - "damage": 1000, - "crafting": false, - "durability": 1000, - "doesDamage": true - }, - { - "name": "Stein", - "damage": 10, - "crafting": true, - "durability": 1000, - "doesDamage": true - }, - { - "name": "Fell", - "damage": 0, - "crafting": true, - "durability": 1000, - "doesDamage": false; - } -] \ No newline at end of file + + [ + { + "name": "Holz", + "damage": "1-3", + "crafting": true, + "doesDamage": true, + "durability": 1000, + "amountShop": 10, + "gold": 10 + }, + { + "name": "Heiliges Schwert der Engel", + "damage": "1000", + "crafting": false, + "doesDamage": true, + "durability": 1000, + "amountShop": 1, + "gold": 1000 + }, + { + "name": "Stein", + "damage": "5-10", + "crafting": true, + "doesDamage": true, + "durability": 1000, + "amountShop": 1500, + "gold": 2 + }, + { + "name": "Fell", + "damage": "0", + "crafting": true, + "doesDamage": false, + "durability": 1000, + "amountShop": 500, + "gold": 100 + } + ] diff --git a/src/main/resources/playerconfig.json b/src/main/resources/playerconfig.json index 59af4e6..d9b219d 100644 --- a/src/main/resources/playerconfig.json +++ b/src/main/resources/playerconfig.json @@ -1,17 +1,19 @@ { "gold": 0, - "name": "null", + "name": "Julia", "hp": 10, "inventory": [ { - "damage": 10, + "gold": 5, + "damage": "10", "amount": 5, "durability": 1000, "name": "Holz", "doesDamage": true }, { - "damage": 10, + "gold": 5, + "damage": "10", "amount": 5, "durability": 1000, "name": "Stein", diff --git a/src/main/resources/quiz.json b/src/main/resources/quiz.json index cc58a3f..84f6b79 100644 --- a/src/main/resources/quiz.json +++ b/src/main/resources/quiz.json @@ -1,204 +1,205 @@ { - "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" - } - ] + "Quiz": [ + { + "frage": "Wie lang ist der Äquator der Erde?", + "korrekteAntwort": "40.000km", + "antworten": [ + "20.000m", + "30km", + "60.000km", + "40.000km" + ] + }, + { + "frage": "Was ist der längste Fluss der Welt?", + "korrekteAntwort": "Nil", + "antworten": [ + "Amazonas", + "Nil", + "Rhein", + "Niger" + ] + }, + { + "frage": "Wie viele Tasten hat ein Klavier?", + "korrekteAntwort": "88", + "antworten": [ + "74", + "86", + "82", + "88" + ] + }, + { + "frage": "Von wem wird der Bundespräsident gewählt?", + "korrekteAntwort": "von der Bundesversammlung", + "antworten": [ + "Vom Europäischen Parlament", + "Vom Bundeskanzler", + "Vom Bundestag", + "Von der Bundesversammlung" + ] + }, + { + "frage": "Welches Land produziert jährlich die meisten Filme?", + "korrekteAntwort": "Indien", + "antworten": [ + "USA", + "Indien", + "Japan", + "Nigeria" + ] + }, + { + "frage": "Wie heißt der am schnellsten schwimmende Fisch auf Erden?", + "korrekteAntwort": "Segelfisch", + "antworten": [ + "Flugfisch", + "Tigerhai", + "Segelfisch", + "Windfisch" + ] + }, + { + "frage": "Was ist KEIN Gewächs?", + "korrekteAntwort": "Incolornis", + "antworten": [ + "Geranie", + "Moosfarn", + "Incolornis", + "Strandflieder" + ] + }, + { + "frage": "Was nutzt eine Fledermaus zur Orientierung in der Luft?", + "korrekteAntwort": "Ultraschall", + "antworten": [ + "Infrarot", + "Röntgenstrahlen", + "Speichel", + "Ultraschall" + ] + }, + { + "frage": "Von wem stammt der berühmte Satz: 'Ich denke, also bin ich'?", + "korrekteAntwort": "René Descartes", + "antworten": [ + "John Fitzgerald Kennedy", + "George Walker Bush", + "René Descartes", + "Julius Caesar" + ] + }, + { + "frage": "Welches Lebensmittel enthält das meiste Wasser?", + "korrekteAntwort": "Gurke", + "antworten": [ + "Gurke", + "Wassermelone", + "Zitrone", + "Paprika" + ] + }, + { + "frage": "Welches Lebensmittel gehört im botanischen Sinne zu den Früchten?", + "korrekteAntwort": "Tomate", + "antworten": [ + "Möhre", + "Kartoffel", + "Tomate", + "Weißkohl" + ] + }, + { + "frage": "Haptische Wahrnehmung beruht auf dem...?", + "korrekteAntwort": "Tastsinn", + "antworten": [ + "Greifreflex", + "Gleichgewichtssinn", + "Hörsinn", + "Tastsinn" + ] + }, + { + "frage": "Wie nennt man den letzten Tanz einer Tanzveranstaltung?", + "korrekteAntwort": "Kehraus", + "antworten": [ + "Voraus", + "Garaus", + "Kehraus", + "Durchaus" + ] + }, + { + "frage": "Wie nennt man ein tiefes, enges Tal, durch das ein Gebirgsbach fließt?", + "korrekteAntwort": "Klamm", + "antworten": [ + "Klamm", + "Feucht", + "Nass", + "Schwamm" + ] + }, + { + "frage": "Wer oder was ist Gerbera?", + "korrekteAntwort": "eine Pflanze", + "antworten": [ + "eine europäische Landschaft", + "eine Pflanze", + "die erste Präsidentin von Südafrika", + "eine Stadt in Lichtenstein" + ] + }, + { + "frage": "Nach wem wurde ein Gesellschaftsanzug benannt?", + "korrekteAntwort": "Gustav Stresemann", + "antworten": [ + "Richard von Weizsäcker", + "Gustav Heinemann", + "Jürgen Klinsmann", + "Gustav Stresemann" + ] + }, + { + "frage": "Was ist Speckstein?", + "korrekteAntwort": "ein besonders weicher Stein", + "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" + ] + }, + { + "frage": "In welcher Religion gibt es Gurus?", + "korrekteAntwort": "im Hinduismus", + "antworten": [ + "im Christentum", + "im Hinduismus", + "im Islam", + "im Judentum" + ] + }, + { + "frage": "Was versteht man unter Brunsbüttel?", + "korrekteAntwort": "eine Industriestadt an der Unterelbe", + "antworten": [ + "eine Industriestadt an der Unterelbe", + "einen Plakatkleber", + "eine 630 Mark-Kraft", + "ein Staatssekretär" + ] + }, + { + "frage": "Welcher im 11. Jahrhundert gegründeter Orden rettet und pfelgt auch noch heute Verletzte und Kranke?", + "korrekteAntwort": "die Johanniter", + "antworten": [ + "die Dominikaner", + "die Augustiner", + "die Zisterzienser", + "die Johanniter" + ] + } + ], + "lastPlayed": 1675852467225 } \ No newline at end of file diff --git a/src/test/java/org/bitbiome/classes/BlackJackTest.java b/src/test/java/org/bitbiome/classes/BlackJackTest.java new file mode 100644 index 0000000..30752e0 --- /dev/null +++ b/src/test/java/org/bitbiome/classes/BlackJackTest.java @@ -0,0 +1,44 @@ +package org.bitbiome.classes; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class BlackJackTest { + + private static BlackJack bj; + @BeforeAll + public static void setUpTest() { + bj = new BlackJack("UnitTest"); + } + @Test + public void testGetEntity() { + assertEquals(BlackJack.Entity.PLAYER, bj.getEntity(1)); + } + + @Test + public void testGetEntityBot() { + assertEquals(BlackJack.Entity.BOT, bj.getEntity(2)); + } + + @Test + public void testPlayerName() { + assertEquals("UnitTest", bj.getPlayerName(BlackJack.Entity.PLAYER)); + } + + @Test + public void testBotName() { + assertEquals("BitBiome", bj.getPlayerName(BlackJack.Entity.BOT)); + } + + @Test + public void testPlayerIsIn() { + assertTrue(bj.isIn(BlackJack.Entity.PLAYER)); + } + + @Test + public void testBotIsIn() { + assertTrue(bj.isIn(BlackJack.Entity.BOT)); + } +} 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/CollectCommandTest.java b/src/test/java/org/bitbiome/commands/CollectCommandTest.java index cb718d1..75564dd 100644 --- a/src/test/java/org/bitbiome/commands/CollectCommandTest.java +++ b/src/test/java/org/bitbiome/commands/CollectCommandTest.java @@ -14,7 +14,7 @@ public class CollectCommandTest { public void testIncreaseAmountInPlayerConfig() { CollectCommand command = new CollectCommand(); JsonParser jp = new JsonParser(); - JSONObject o = jp.getJSONObject("playerconfig.json"); + JSONObject o = jp.getJSONObject("src/main/resources/playerconfig.json"); JSONArray inventory = o.getJSONArray("inventory"); int k = 0; int initialAmount = inventory.getJSONObject(k).getInt("amount"); diff --git a/src/test/java/org/bitbiome/commands/HelpCommandTest.java b/src/test/java/org/bitbiome/commands/HelpCommandTest.java index e7caecf..a65225f 100644 --- a/src/test/java/org/bitbiome/commands/HelpCommandTest.java +++ b/src/test/java/org/bitbiome/commands/HelpCommandTest.java @@ -1,36 +1,15 @@ 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(); - 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") - .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") - .append("|--------------|-------------------------------|\n") - .append("|" + Colors.ANSI_GREEN + " collect " + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") - .append("|--------------|-------------------------------|\n") - .append("|" + Colors.ANSI_GREEN + " lookaround" + Colors.ANSI_RESET + " | Zeigt dir deine Umgebung, |\n") - .append("|" + Colors.ANSI_GREEN + " " + Colors.ANSI_RESET + " | Items und Mobs in der Nähe |\n") - .append("|______________|_______________________________|\n"); - assertEquals(outputMessage.toString(), helpMessage); + assertTrue(helpMessage.contains("Command") && helpMessage.contains("Description")); } diff --git a/src/test/java/org/bitbiome/commands/InventoryCommandTest.java b/src/test/java/org/bitbiome/commands/InventoryCommandTest.java index c3521ce..5511feb 100644 --- a/src/test/java/org/bitbiome/commands/InventoryCommandTest.java +++ b/src/test/java/org/bitbiome/commands/InventoryCommandTest.java @@ -15,8 +15,8 @@ public class InventoryCommandTest { InventoryCommand command = new InventoryCommand(); TravelEngine travelEngine = new TravelEngine(new Player("Unit")); ArrayList inventory = new ArrayList<>(); - inventory.add(new Item("Holz", false, 0,5)); - inventory.add(new Item("Stein", true, 10, 5)); + inventory.add(new Item("Holz", false, "0",5, 3)); + inventory.add(new Item("Stein", true, "10", 5, 4)); travelEngine.getPlayer().setInventory(inventory); String expectedResult = Colors.ANSI_PURPLE + "Du möchtest wissen, was in deinem Inventar ist? \n" + diff --git a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java index c193a73..5916052 100644 --- a/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java +++ b/src/test/java/org/bitbiome/commands/LookaroundCommandTest.java @@ -54,12 +54,12 @@ public class LookaroundCommandTest { mob1.put("name", "BigFoot"); mob1.put("isFriendly", true); mob1.put("hp", 10); - mob1.put("damage", 5); + mob1.put("damage", "5"); JSONObject mob2 = new JSONObject(); mob2.put("name", "Yeti"); mob2.put("isFriendly", false); mob2.put("hp", 20); - mob2.put("damage", 10); + mob2.put("damage", "10"); mobs.put(mob1); mobs.put(mob2); ArrayList foundMobs = new ArrayList<>(); @@ -76,9 +76,9 @@ public class LookaroundCommandTest { int randomNumberItems = 3; StringBuilder outputMessage = new StringBuilder(); ArrayList foundItems = new ArrayList(); - foundItems.add(new Item("Holz", true, 10, 1)); - foundItems.add(new Item("Stein", true, 10, 1)); - foundItems.add(new Item("Sand", false, 1, 1)); + foundItems.add(new Item("Holz", true, "10", 1,2)); + foundItems.add(new Item("Stein", true, "10", 1, 3)); + foundItems.add(new Item("Sand", false, "1", 1,3)); command.getItemsOutput(randomNumberItems, outputMessage, foundItems); String expectedOutput = Colors.ANSI_BLUE+ "Huch, was liegt denn hier rum?\n" + Colors.ANSI_RESET+ "- Holz\n- Stein\n- Sand\n" + @@ -126,12 +126,12 @@ public class LookaroundCommandTest { @Test void testGetRandomItem() throws Exception { int randomNumberItems = 2; - JSONArray items = new JSONArray("[{\"name\":\"Holz\",\"doesDamage\":true,\"damage\":1.0},{\"name\":\"Stein\",\"doesDamage\":false,\"damage\":10.0}]"); + JSONArray items = new JSONArray("[{\"name\":\"Holz\",\"doesDamage\":true,\"damage\":\"1.0\"},{\"name\":\"Stein\",\"doesDamage\":false,\"damage\":\"10.0\"}]"); ArrayList result = new ArrayList<>(); for (int i = 0; i < randomNumberItems; i++) { JSONObject itemObject = items.getJSONObject(i); Item item = new Item(itemObject.getString("name"), itemObject.getBoolean("doesDamage"), - itemObject.getFloat("damage"), 1); + itemObject.getString("damage"), 1, 3); result.add(item); } assertEquals(2, result.size()); @@ -144,7 +144,7 @@ public class LookaroundCommandTest { ArrayList enemies = new ArrayList(); enemies.add(new Mob("Bigfoot", false, 50,20)); ArrayList items = new ArrayList(); - items.add(new Item("Holz",true, 10, 1)); + items.add(new Item("Holz",true, "10", 1,3)); Location location = new Location("Wald",enemies, items); StringBuilder outputMessage = new StringBuilder(); @@ -163,7 +163,7 @@ public class LookaroundCommandTest { ArrayList enemies = new ArrayList(); enemies.add(new Mob("Bigfoot", false, 50,20)); ArrayList items = new ArrayList(); - items.add(new Item("Holz",true, 10, 1)); + items.add(new Item("Holz",true, "10", 1, 5)); Location location = new Location("Strand",enemies, items); StringBuilder outputMessage = new StringBuilder(); @@ -182,7 +182,7 @@ public class LookaroundCommandTest { ArrayList enemies = new ArrayList(); enemies.add(new Mob("unknown", false, 50,20)); ArrayList items = new ArrayList(); - items.add(new Item("unknown",true, 10, 1)); + items.add(new Item("unknown",true, "10", 1, 5)); Location location = new Location("Unknown",enemies, items); StringBuilder outputMessage = new StringBuilder(); diff --git a/src/test/java/org/bitbiome/commands/QuitCommandTest.java b/src/test/java/org/bitbiome/commands/QuitCommandTest.java index 67a368e..4c6d0ec 100644 --- a/src/test/java/org/bitbiome/commands/QuitCommandTest.java +++ b/src/test/java/org/bitbiome/commands/QuitCommandTest.java @@ -2,14 +2,14 @@ package org.bitbiome.commands; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class QuitCommandTest { @Test public void testQuitCommand() { - assertEquals("You quitted!", QuitCommand.getQuitMessage()); + assertTrue(QuitCommand.getQuitMessage().contains("Spiel beendet!")); } } diff --git a/src/test/java/org/bitbiome/commands/QuizCommandTest.java b/src/test/java/org/bitbiome/commands/QuizCommandTest.java new file mode 100644 index 0000000..a8e9f93 --- /dev/null +++ b/src/test/java/org/bitbiome/commands/QuizCommandTest.java @@ -0,0 +1,36 @@ +package org.bitbiome.commands; + +import org.junit.jupiter.api.Test; + + +import static org.junit.jupiter.api.Assertions.*; + +public class QuizCommandTest { + + @Test + public void testStartMessage() { + assertTrue(QuizCommand.starterMessage().contains("Du hast das Quiz gestartet!")); + } + + @Test + public void testEndMessage() { + assertTrue(QuizCommand.endMessage().contains("Das Quiz ist vorbei!")); + } + + @Test + public void testLastTimePlayed() { + long lastTimePlayed = System.currentTimeMillis(); + assertTrue(QuizCommand.canPlayAgain(lastTimePlayed) < lastTimePlayed); + } + + @Test + public void testRandomNumberGenerator() { + int getRandom = QuizCommand.random(3); + assertTrue(getRandom >= 0 && getRandom <= 3); + } + + @Test + public void testPrintFunction() { + assertEquals("I am a unit test!", QuizCommand.print("I am a unit test!")); + } +} diff --git a/src/test/java/org/bitbiome/commands/ShopCommandTest.java b/src/test/java/org/bitbiome/commands/ShopCommandTest.java new file mode 100644 index 0000000..69c3de6 --- /dev/null +++ b/src/test/java/org/bitbiome/commands/ShopCommandTest.java @@ -0,0 +1,87 @@ +package org.bitbiome.commands; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.bitbiome.classes.Shop; + +public class ShopCommandTest { + final Shop shop = new Shop(null, true, null, null); + @Test + public void testValidInput1(){ + boolean expected = true; + boolean result = ShopCommand.validInput("1"); + assertEquals(expected, result); + } + @Test + public void testValidInput2(){ + boolean expected = true; + boolean result = ShopCommand.validInput("2"); + assertEquals(expected, result); + } + @Test + public void testValidInput3(){ + boolean expected = true; + boolean result = ShopCommand.validInput("3"); + assertEquals(expected, result); + } + @Test + public void testValidInput4(){ + boolean expected = true; + boolean result = ShopCommand.validInput("4"); + assertEquals(expected, result); + } + + + + @Test + public void testSubtractGold(){ + int expected = 1; + int result = shop.subtractGold(3, 2); + assertEquals(expected, result); + } + @Test + public void testSubtractGold1(){ + int expected = 10; + int result = shop.subtractGold(12, 2); + assertEquals(expected, result); + } + @Test + public void testSubtractGold2(){ + int expected = 4; + int result = shop.subtractGold(7, 3); + assertEquals(expected, result); + } + @Test + public void testSubtractGold3(){ + int expected = 5; + int result = shop.subtractGold(10, 5); + assertEquals(expected, result); + } + @Test + public void testSubtractGold4(){ + int expected = 1; + int result = shop.subtractGold(2, 1); + assertEquals(expected, result); + } + @Test + public void testSubtractGold5(){ + int expected = 10; + int result = shop.subtractGold(20, 10); + assertEquals(expected, result); + } + + @Test + public void testSubtractGold6(){ + int expected = 12; + int result = shop.subtractGold(24, 12); + assertEquals(expected, result); + } + @Test + public void testSubtractGold7(){ + int expected = 15; + int result = shop.subtractGold(31, 16); + assertEquals(expected, result); + } +} 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..679cd08 --- /dev/null +++ b/src/test/java/org/bitbiome/entitiesTest/ItemTest.java @@ -0,0 +1,50 @@ +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,5"); + item.changeDoesDamage(true); + item.setAmount(5); + item.setGold(100); + } + + @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().equals("12,5")); + assumeTrue(doesDamage); + } + + @Test + public void testGetAmount() { + assumeTrue(item.getAmount() == 5); + } + + @Test + public void testGetGold() { + assumeTrue(item.getGold() == 100); + } +} 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()); + } + +}