From f77ee2b1d0316093d55a319d16d9f3fe11275ae9 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sun, 15 Jan 2023 20:41:05 +0100 Subject: [PATCH 01/52] First of all, don't sync VSCode settings --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c15a9a2..1f00eaf 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ replay_pid* /.idea/ /out/ /target/ -*.iml \ No newline at end of file +*.iml +/.vscode/ \ No newline at end of file From 2f9f9e80de8b77f151086ad53a69decf4521f2b7 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sun, 15 Jan 2023 20:42:26 +0100 Subject: [PATCH 02/52] refactoring: Removed currently unnecessary imports --- src/main/java/org/bitbiome/commands/HelpCommand.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java index 4d88e3a..f4439df 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -1,8 +1,5 @@ package org.bitbiome.commands; -import org.bitbiome.Boot; - -import java.util.HashMap; import java.util.Scanner; public class HelpCommand implements CommandAPI { From ebfcbc1e7e94c84e61db465685b032c1031ed660 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sun, 15 Jan 2023 20:56:37 +0100 Subject: [PATCH 03/52] Added class for use command --- src/main/java/org/bitbiome/commands/UseCommand.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/org/bitbiome/commands/UseCommand.java diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java new file mode 100644 index 0000000..a014a99 --- /dev/null +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -0,0 +1,9 @@ +package org.bitbiome.commands; + +import java.util.Scanner; + +public class UseCommand implements CommandAPI { + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message) { + } +} From 72dc8a87f757adaa8ca7804873b72e5f84b58ffd Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sun, 15 Jan 2023 20:57:09 +0100 Subject: [PATCH 04/52] Added use command to CommandListener --- 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 2e62105..545eae9 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -14,6 +14,8 @@ public class CommandListener { commands.put("exit", new QuitCommand()); commands.put("quit", new QuitCommand()); + + commands.put("use", new UseCommand()); } public HashMap returnCommands() { From 80197d15f5a767431107783d050c1bff1aea161f Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sun, 15 Jan 2023 21:21:31 +0100 Subject: [PATCH 05/52] Added function for executing use command --- src/main/java/org/bitbiome/commands/UseCommand.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index a014a99..c9f120e 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -3,7 +3,12 @@ package org.bitbiome.commands; import java.util.Scanner; public class UseCommand implements CommandAPI { + private String getUseMessage(String msg) { + return ""; + } + @Override public void performCommand(Scanner scanner, boolean isRunning, String message) { + System.out.println(getUseMessage(message.split(" ", 2)[1])); } } From 4b6717e2ddc134b4ada5eb27693600a1ed80f4af Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sun, 15 Jan 2023 21:23:22 +0100 Subject: [PATCH 06/52] refactoring: Changed order of functions --- src/main/java/org/bitbiome/commands/UseCommand.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index c9f120e..9ccc961 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -3,12 +3,12 @@ package org.bitbiome.commands; import java.util.Scanner; public class UseCommand implements CommandAPI { - private String getUseMessage(String msg) { - return ""; - } - @Override public void performCommand(Scanner scanner, boolean isRunning, String message) { System.out.println(getUseMessage(message.split(" ", 2)[1])); } -} + + private String getUseMessage(String msg) { + return ""; + } +} \ No newline at end of file From 9d58257ab8fc941c5076cf32c66618a361318d35 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sun, 15 Jan 2023 21:36:20 +0100 Subject: [PATCH 07/52] Added output to getUseMessage() --- src/main/java/org/bitbiome/commands/UseCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 9ccc961..135b669 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -9,6 +9,10 @@ public class UseCommand implements CommandAPI { } private String getUseMessage(String msg) { - return ""; + String message[] = msg.split(" on "); + String returnString = "You used " + msg; + if(message.length == 1) + returnString+=" on yourself"; + return returnString; } } \ No newline at end of file From 1033a02a2972c0ae1c948e6392166dcfec21beef Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Mon, 16 Jan 2023 10:43:37 +0100 Subject: [PATCH 08/52] refactoring: Pulled the actual using of the item into its own function --- src/main/java/org/bitbiome/commands/UseCommand.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 135b669..041d4e4 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -10,9 +10,11 @@ public class UseCommand implements CommandAPI { private String getUseMessage(String msg) { String message[] = msg.split(" on "); - String returnString = "You used " + msg; - if(message.length == 1) - returnString+=" on yourself"; + String returnString = useItem(message[0], message[1]); return returnString; } + + private String useItem(String item, String target) { + return "You used " + item + " on " + target; + } } \ No newline at end of file From 5304e84c6cb4a11247f4dc119bdf1c0d2e3de850 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Mon, 16 Jan 2023 10:59:32 +0100 Subject: [PATCH 09/52] refactoring: compressed return of getUseMessage() --- src/main/java/org/bitbiome/commands/UseCommand.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 041d4e4..59f951f 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -10,8 +10,7 @@ public class UseCommand implements CommandAPI { private String getUseMessage(String msg) { String message[] = msg.split(" on "); - String returnString = useItem(message[0], message[1]); - return returnString; + return useItem(message[0], message[1]); } private String useItem(String item, String target) { From 5a95b338787fdfcb42c4beb992ba7afd268c3767 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Mon, 16 Jan 2023 11:05:40 +0100 Subject: [PATCH 10/52] Created function for getting name of item from command argument --- src/main/java/org/bitbiome/commands/UseCommand.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 59f951f..69da5bd 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -9,11 +9,16 @@ public class UseCommand implements CommandAPI { } private String getUseMessage(String msg) { - String message[] = msg.split(" on "); - return useItem(message[0], message[1]); + String item = getItemName(msg); + String target = msg.replaceFirst(item + " on ", ""); + return useItem(item, target); } private String useItem(String item, String target) { return "You used " + item + " on " + target; } + + private String getItemName(String msg) { + return ""; + } } \ No newline at end of file From bb177c42f0d4f740d860e353b2b5ec7bf9f9b770 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Mon, 16 Jan 2023 11:32:28 +0100 Subject: [PATCH 11/52] No item or location containing " on " will exist, thus does not need to be supported --- src/main/java/org/bitbiome/commands/UseCommand.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 69da5bd..a827597 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -9,16 +9,12 @@ public class UseCommand implements CommandAPI { } private String getUseMessage(String msg) { - String item = getItemName(msg); - String target = msg.replaceFirst(item + " on ", ""); + String item = msg.split(" on ")[0]; + String target = msg.split(" on ")[1]; return useItem(item, target); } private String useItem(String item, String target) { return "You used " + item + " on " + target; } - - private String getItemName(String msg) { - return ""; - } } \ No newline at end of file From 78fc6bf0c5ec83b1ddab2b0c0ad7f5f13d27188e Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Mon, 23 Jan 2023 10:42:02 +0100 Subject: [PATCH 12/52] Added getItem() function --- src/main/java/org/bitbiome/commands/UseCommand.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index a827597..ca3f582 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -2,6 +2,9 @@ package org.bitbiome.commands; import java.util.Scanner; +import org.bitbiome.classes.JsonParser; +import org.json.*; + public class UseCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message) { @@ -17,4 +20,14 @@ public class UseCommand implements CommandAPI { private String useItem(String item, String target) { return "You used " + item + " on " + target; } + + private JSONObject getItem(String item) { + JSONArray inventory = JsonParser.getJSONObject("playerconfig.json").getJSONArray("inventory"); + for(int i = 0; i < inventory.length(); i++) { + JSONObject currentItem = inventory.getJSONObject(i); + if(currentItem.getString("name").equals(item)) + return currentItem; + } + return null; + } } \ No newline at end of file From b4bc493d0599174cb82a00c19c423b80c064294d Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Mon, 23 Jan 2023 10:42:31 +0100 Subject: [PATCH 13/52] Added getTarget() function --- .../java/org/bitbiome/commands/UseCommand.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index ca3f582..53e4f98 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -30,4 +30,22 @@ public class UseCommand implements CommandAPI { } return null; } + + private JSONObject getTarget(String target) { + String currentLocation = JsonParser.getJSONObject("playerconfig").getString("currentLocation"); + JSONArray locations = JsonParser.getJSONObject("gameconfig").getJSONArray("locations"); + for(int i = 0; i < locations.length(); i++) { + JSONObject location = locations.getJSONObject(i); + if(locations.getJSONObject(i).getString("name").equals(currentLocation)) { + JSONArray targets = location.getJSONArray("mobs"); + for(int j = 0; j < targets.length(); j++) { + JSONObject mob = targets.getJSONObject(j); + if(mob.getString("name").equals(target)) + return mob; + } + break; + } + } + return null; + } } \ No newline at end of file From 34f0b127b105261f1475f4990e32c09ace760ca5 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Mon, 23 Jan 2023 10:44:23 +0100 Subject: [PATCH 14/52] Implemented getUseMessage() --- .../java/org/bitbiome/commands/UseCommand.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 53e4f98..ceef595 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -12,12 +12,24 @@ public class UseCommand implements CommandAPI { } private String getUseMessage(String msg) { - String item = msg.split(" on ")[0]; - String target = msg.split(" on ")[1]; + String message[] = msg.split(" on "); + String itemName = message[0]; + JSONObject item = getItem(itemName), target; + + if(item == null) + return "You don't have that item."; + if(item.getBoolean("attack")) + return "You can't attack with this."; + if(message.length == 1) + target = JsonParser.getJSONObject("playerconfig.json"); + else + target = getTarget(message[1]); + if(target == null) + return "That target is not available."; return useItem(item, target); } - private String useItem(String item, String target) { + private String useItem(JSONObject item, JSONObject target) { return "You used " + item + " on " + target; } From e68f5314e15b7bbba755011782727d746497a330 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Tue, 24 Jan 2023 12:50:41 +0100 Subject: [PATCH 15/52] Adapted to f8926e04962cffd427a2ea5754b0d9f909c83596 --- .../org/bitbiome/commands/UseCommand.java | 75 +++++++------------ 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 61eb376..4302f7d 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -1,67 +1,48 @@ package org.bitbiome.commands; +import java.util.ArrayList; import java.util.Scanner; -import org.bitbiome.classes.JsonParser; -import org.bitbiome.classes.TravelEngine; -import org.json.*; +import org.bitbiome.classes.*; +import org.bitbiome.entities.*; public class UseCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { - System.out.println(getUseMessage(message.split(" ", 2)[1])); + System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); } - private String getUseMessage(String msg) { + private String getUseMessage(String msg, TravelEngine engine) { + Player player = engine.getPlayer(); String message[] = msg.split(" on "); String itemName = message[0]; - JSONObject item = getItem(itemName), target; - JsonParser p = new JsonParser(); + ArrayList inv = player.getInventory(); - if(item == null) - return "You don't have that item."; - if(item.getBoolean("attack")) - return "You can't attack with this."; - if(message.length == 1) - target = p.getJSONObject("playerconfig.json"); - else - target = getTarget(message[1]); - if(target == null) - return "That target is not available."; - return useItem(item, target); + for(int i = 0; i mobs = player.getLocation().getMobList(); + for(int j = 0; j Date: Wed, 25 Jan 2023 10:30:32 +0100 Subject: [PATCH 16/52] =?UTF-8?q?Implemented=20useItem(=E2=80=A6=20Mob)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/bitbiome/commands/UseCommand.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 4302f7d..d35b331 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -26,11 +26,12 @@ public class UseCommand implements CommandAPI { if(message.length == 1) return useItem(item, player); String targetName = message[1]; - ArrayList mobs = player.getLocation().getMobList(); + Location loc = player.getLocation(); + ArrayList mobs = loc.getMobList(); for(int j = 0; j=hp) { + location.getMobList().remove(target); + return "You killed " + target.getName() + " with " + item.getName(); + } + target.setHp(hp-dmg); + target.setFriendly(false); + return "You used " + item.getName() + " on " + target.getName(); } } \ No newline at end of file From 2604815f3e26bc84b811cac2c78151d37995b18a Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Wed, 25 Jan 2023 10:31:50 +0100 Subject: [PATCH 17/52] =?UTF-8?q?Implemented=20useItem(=E2=80=A6=20Player)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/bitbiome/commands/UseCommand.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index d35b331..1ec7bbf 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -10,6 +10,8 @@ public class UseCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); + if(engine.getPlayer().getHp() <= 0) + System.exit(0); } private String getUseMessage(String msg, TravelEngine engine) { @@ -40,7 +42,15 @@ public class UseCommand implements CommandAPI { } private String useItem(Item item, Player target) { - return "You used " + item + " on " + target; + float hp = target.getHp(); + hp -= item.getDamage(); + String retString = "You used " + item.getName() + " on yourself"; + if(hp <= 0) { + target.setHp(0); + return retString + " and died."; + } + target.setHp(hp); + return retString; } private String useItem(Item item, Mob target, Location location) { From 56b2b46a1ab35f51b634e797ca2605d833d91b6b Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 28 Jan 2023 14:01:48 +0100 Subject: [PATCH 18/52] Added loop in UseCommand.performCommand() which only ends when every enemy has been slain --- .../org/bitbiome/commands/UseCommand.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 1ec7bbf..bf09152 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -9,9 +9,11 @@ import org.bitbiome.entities.*; public class UseCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { - System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); - if(engine.getPlayer().getHp() <= 0) - System.exit(0); + do { + System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); + if(engine.getPlayer().getHp() <= 0) + System.exit(0); + } while(getNumOfEnemyMobs(engine) > 0); } private String getUseMessage(String msg, TravelEngine engine) { @@ -64,4 +66,16 @@ public class UseCommand implements CommandAPI { target.setFriendly(false); return "You used " + item.getName() + " on " + target.getName(); } + + private int getNumOfEnemyMobs(TravelEngine engine) { + Location loc = engine.getPlayer().getLocation(); + ArrayList mobs = loc.getMobList(); + int count = 0; + for(int i = 0; i Date: Sat, 28 Jan 2023 14:06:51 +0100 Subject: [PATCH 19/52] Enemy mobs now attack player when in combat --- .../java/org/bitbiome/commands/UseCommand.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index bf09152..8c4d555 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -13,6 +13,22 @@ public class UseCommand implements CommandAPI { System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); if(engine.getPlayer().getHp() <= 0) System.exit(0); + Location loc = engine.getPlayer().getLocation(); + ArrayList mobs = loc.getMobList(); + for(int i = 0; i 0); } From 2b44d99b7a30618c58785ca08f6cbe8c91cc8a7c Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 28 Jan 2023 14:15:25 +0100 Subject: [PATCH 20/52] refactoring: Created ArrayList for all enemy mobs --- .../org/bitbiome/commands/UseCommand.java | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 8c4d555..4bfe3c5 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -7,29 +7,33 @@ import org.bitbiome.classes.*; import org.bitbiome.entities.*; public class UseCommand implements CommandAPI { +ArrayList enemies = new ArrayList(); + @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { + ArrayList allMobs = engine.getPlayer().getLocation().getMobList(); + for(int i = 0; i mobs = loc.getMobList(); - for(int i = 0; i 0); + } while(enemies.size() > 0); } private String getUseMessage(String msg, TravelEngine engine) { @@ -72,26 +76,17 @@ public class UseCommand implements CommandAPI { } private String useItem(Item item, Mob target, Location location) { + if(target.isFriendly()) + enemies.add(target); float hp = target.getHp(); float dmg = item.getDamage(); if(dmg>=hp) { location.getMobList().remove(target); + enemies.remove(target); return "You killed " + target.getName() + " with " + item.getName(); } target.setHp(hp-dmg); target.setFriendly(false); return "You used " + item.getName() + " on " + target.getName(); } - - private int getNumOfEnemyMobs(TravelEngine engine) { - Location loc = engine.getPlayer().getLocation(); - ArrayList mobs = loc.getMobList(); - int count = 0; - for(int i = 0; i Date: Sat, 28 Jan 2023 14:33:46 +0100 Subject: [PATCH 21/52] refactoring: Pulled getting enemies from location into its own function --- .../java/org/bitbiome/commands/UseCommand.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 4bfe3c5..52ac913 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -11,12 +11,7 @@ ArrayList enemies = new ArrayList(); @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { - ArrayList allMobs = engine.getPlayer().getLocation().getMobList(); - for(int i = 0; i enemies = new ArrayList(); target.setFriendly(false); return "You used " + item.getName() + " on " + target.getName(); } + + private void getEnemies(ArrayList allMobs) { + for(int i = 0; i Date: Sat, 28 Jan 2023 14:35:57 +0100 Subject: [PATCH 22/52] refactoring: Added access modifier for enemies ArrayList --- src/main/java/org/bitbiome/commands/UseCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 52ac913..a25a279 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -7,7 +7,7 @@ import org.bitbiome.classes.*; import org.bitbiome.entities.*; public class UseCommand implements CommandAPI { -ArrayList enemies = new ArrayList(); +private ArrayList enemies = new ArrayList(); @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { From 6426ea06c78c80b4a36c4e6a085608de8cd9bba2 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 28 Jan 2023 14:42:34 +0100 Subject: [PATCH 23/52] Combat only starts when player actually attacks someone --- src/main/java/org/bitbiome/commands/UseCommand.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index a25a279..e734d8c 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -8,12 +8,13 @@ import org.bitbiome.entities.*; public class UseCommand implements CommandAPI { private ArrayList enemies = new ArrayList(); +private boolean combat = false; @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { getEnemies(engine.getPlayer().getLocation().getMobList()); - do { - System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); + System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); + while(enemies.size() > 0 && combat) { if(engine.getPlayer().getHp() <= 0) System.exit(0); for(int i = 0; i enemies = new ArrayList(); } engine.getPlayer().setHp(hp); } - } while(enemies.size() > 0); + //TODO get input from player + } } private String getUseMessage(String msg, TravelEngine engine) { @@ -71,6 +73,7 @@ private ArrayList enemies = new ArrayList(); } private String useItem(Item item, Mob target, Location location) { + combat = true; if(target.isFriendly()) enemies.add(target); float hp = target.getHp(); From e5dcc5e566aa4d41cffd5d0d97e912f91302d332 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 28 Jan 2023 14:48:34 +0100 Subject: [PATCH 24/52] Made functions in UseCommand public so they can be accessed for testing --- src/main/java/org/bitbiome/commands/UseCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index e734d8c..88ea8cb 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -33,7 +33,7 @@ private boolean combat = false; } } - private String getUseMessage(String msg, TravelEngine engine) { + public String getUseMessage(String msg, TravelEngine engine) { Player player = engine.getPlayer(); String message[] = msg.split(" on "); String itemName = message[0]; @@ -60,7 +60,7 @@ private boolean combat = false; return "That item is not in your inventory."; } - private String useItem(Item item, Player target) { + public String useItem(Item item, Player target) { float hp = target.getHp(); hp -= item.getDamage(); String retString = "You used " + item.getName() + " on yourself"; @@ -72,7 +72,7 @@ private boolean combat = false; return retString; } - private String useItem(Item item, Mob target, Location location) { + public String useItem(Item item, Mob target, Location location) { combat = true; if(target.isFriendly()) enemies.add(target); @@ -88,7 +88,7 @@ private boolean combat = false; return "You used " + item.getName() + " on " + target.getName(); } - private void getEnemies(ArrayList allMobs) { + public void getEnemies(ArrayList allMobs) { for(int i = 0; i Date: Sat, 28 Jan 2023 14:59:53 +0100 Subject: [PATCH 25/52] If something does damage, you can attack with it, not the other way around. --- src/main/java/org/bitbiome/commands/UseCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 88ea8cb..5da2190 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -42,7 +42,7 @@ private boolean combat = false; for(int i = 0; i Date: Sat, 28 Jan 2023 15:09:31 +0100 Subject: [PATCH 26/52] Added test for getUseMessage() --- .../org/bitbiome/commands/UseCommandTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/java/org/bitbiome/commands/UseCommandTest.java diff --git a/src/test/java/org/bitbiome/commands/UseCommandTest.java b/src/test/java/org/bitbiome/commands/UseCommandTest.java new file mode 100644 index 0000000..49c185d --- /dev/null +++ b/src/test/java/org/bitbiome/commands/UseCommandTest.java @@ -0,0 +1,34 @@ +package org.bitbiome.commands; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.bitbiome.classes.TravelEngine; +import org.bitbiome.entities.Item; +import org.bitbiome.entities.Mob; +import org.bitbiome.entities.Player; +import org.junit.jupiter.api.Test; + +public class UseCommandTest { + public void testUseCommand() { + testGetUseMessage(); + } + + @Test + public void testGetUseMessage() { + UseCommand com = new UseCommand(); + TravelEngine engine = new TravelEngine(new Player("test")); + assertEquals("That item is not in your inventory.", com.getUseMessage("", engine)); + assertEquals("That item is not in your inventory.", com.getUseMessage("Fell", engine)); + engine.getPlayer().addToInventory(new Item("Fell", false, 0)); + assertEquals("You can't attack with this.", com.getUseMessage("Fell", engine)); + engine.getPlayer().addToInventory(new Item("Sword", true, 10)); + assertEquals("You used Sword on yourself", com.getUseMessage("Sword", engine)); + assertEquals("That target is not available.", com.getUseMessage("Sword on Wolf", engine)); + engine.getPlayer().getLocation().getMobList().add(new Mob("Wolf", false, 11, 10)); + assertEquals("You used Sword on Wolf", com.getUseMessage("Sword on Wolf", engine)); + assertEquals("You killed Wolf with Sword", com.getUseMessage("Sword on Wolf", engine)); + assertEquals("That target is not available.", com.getUseMessage("Sword on Wolf", engine)); + engine.getPlayer().addToInventory(new Item("Heiliges Schwert der Erzengel", true, 3000)); + assertEquals("You used Heiliges Schwert der Erzengel on yourself and died.", com.getUseMessage("Heiliges Schwert der Erzengel", engine)); + } +} From 5aa9a17f3743e230c36ab4754deceaf6adff806e Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 28 Jan 2023 17:04:10 +0100 Subject: [PATCH 27/52] Added test for testUseItem() (Mob version) --- .../java/org/bitbiome/commands/UseCommandTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/UseCommandTest.java b/src/test/java/org/bitbiome/commands/UseCommandTest.java index 49c185d..b846d9e 100644 --- a/src/test/java/org/bitbiome/commands/UseCommandTest.java +++ b/src/test/java/org/bitbiome/commands/UseCommandTest.java @@ -13,6 +13,19 @@ public class UseCommandTest { testGetUseMessage(); } + @Test + public void testUseItemMob() { + UseCommand com = new UseCommand(); + Player player = new Player("test"); + Mob mob = new Mob("Wolf", false, 11, 10); + player.getLocation().getMobList().add(mob); + Item sword = new Item("Sword", true, 10); + assertEquals("You used Sword on Wolf", com.useItem(sword, mob, player.getLocation())); + assertEquals(1, player.getLocation().getMobList().size()); + assertEquals("You killed Wolf with Sword", com.useItem(sword, mob, player.getLocation())); + assertEquals(0, player.getLocation().getMobList().size()); + } + @Test public void testGetUseMessage() { UseCommand com = new UseCommand(); From ac09973e1f3b332e8b57eb1b98c6031c418d95af Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 28 Jan 2023 17:06:28 +0100 Subject: [PATCH 28/52] Added test for testUseItem() (Player version) --- .../java/org/bitbiome/commands/UseCommandTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/UseCommandTest.java b/src/test/java/org/bitbiome/commands/UseCommandTest.java index b846d9e..04fdf71 100644 --- a/src/test/java/org/bitbiome/commands/UseCommandTest.java +++ b/src/test/java/org/bitbiome/commands/UseCommandTest.java @@ -26,6 +26,17 @@ public class UseCommandTest { assertEquals(0, player.getLocation().getMobList().size()); } + @Test + public void testUseItemPlayer() { + UseCommand com = new UseCommand(); + Player player = new Player("test"); + Item sword = new Item("Sword", true, 10); + assertEquals("You used Sword on yourself", com.useItem(sword, player)); + assertEquals(90, player.getHp()); + Item sword2 = new Item("Heiliges Schwert der Engel", true, 1000); + assertEquals("You used Heiliges Schwert der Engel on yourself and died.", com.useItem(sword2, player)); + } + @Test public void testGetUseMessage() { UseCommand com = new UseCommand(); From 29141ac7aa9d1b000bd95904907e76d60d0bd78e Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 28 Jan 2023 19:29:52 +0100 Subject: [PATCH 29/52] Optimized tests --- .../java/org/bitbiome/commands/UseCommandTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/bitbiome/commands/UseCommandTest.java b/src/test/java/org/bitbiome/commands/UseCommandTest.java index 04fdf71..267de3f 100644 --- a/src/test/java/org/bitbiome/commands/UseCommandTest.java +++ b/src/test/java/org/bitbiome/commands/UseCommandTest.java @@ -45,14 +45,10 @@ public class UseCommandTest { assertEquals("That item is not in your inventory.", com.getUseMessage("Fell", engine)); engine.getPlayer().addToInventory(new Item("Fell", false, 0)); assertEquals("You can't attack with this.", com.getUseMessage("Fell", engine)); - engine.getPlayer().addToInventory(new Item("Sword", true, 10)); - assertEquals("You used Sword on yourself", com.getUseMessage("Sword", engine)); - assertEquals("That target is not available.", com.getUseMessage("Sword on Wolf", engine)); - engine.getPlayer().getLocation().getMobList().add(new Mob("Wolf", false, 11, 10)); - assertEquals("You used Sword on Wolf", com.getUseMessage("Sword on Wolf", engine)); - assertEquals("You killed Wolf with Sword", com.getUseMessage("Sword on Wolf", engine)); - assertEquals("That target is not available.", com.getUseMessage("Sword on Wolf", engine)); engine.getPlayer().addToInventory(new Item("Heiliges Schwert der Erzengel", true, 3000)); - assertEquals("You used Heiliges Schwert der Erzengel on yourself and died.", com.getUseMessage("Heiliges Schwert der Erzengel", engine)); + assertEquals("That target is not available.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); + engine.getPlayer().getLocation().getMobList().add(new Mob("Wolf", false, 11, 10)); + assertEquals("You killed Wolf with Heiliges Schwert der Erzengel", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); + assertEquals("That target is not available.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); } } From 0ba9bd4e7b37d0d2ff08a767d0a0acef848867dc Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Mon, 30 Jan 2023 10:16:52 +0100 Subject: [PATCH 30/52] refactoring: Added Player object in performCommand() --- src/main/java/org/bitbiome/commands/UseCommand.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 5da2190..633fc22 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -12,22 +12,23 @@ private boolean combat = false; @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { - getEnemies(engine.getPlayer().getLocation().getMobList()); + Player player = engine.getPlayer(); + getEnemies(player.getLocation().getMobList()); System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); while(enemies.size() > 0 && combat) { - if(engine.getPlayer().getHp() <= 0) + if(player.getHp() <= 0) System.exit(0); for(int i = 0; i Date: Mon, 30 Jan 2023 10:44:15 +0100 Subject: [PATCH 31/52] Items and target should not be provided as arguments by player but instead be requested --- src/main/java/org/bitbiome/commands/UseCommand.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 633fc22..c0e5444 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -14,7 +14,14 @@ private boolean combat = false; public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { Player player = engine.getPlayer(); getEnemies(player.getLocation().getMobList()); - System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); + System.out.println("Which item would you like to use?"); + String item = scanner.nextLine(); + System.out.println("On who? (leave blank for self)"); + String target = scanner.nextLine(); + if(target.equals("")) + System.out.println(getUseMessage(item, engine)); + else + System.out.println(getUseMessage(item + " on " + target, engine)); while(enemies.size() > 0 && combat) { if(player.getHp() <= 0) System.exit(0); From eac126198b61f5785b3761a75dd7cbafba4c3caa Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 17:26:03 +0100 Subject: [PATCH 32/52] refactoring: Made UseCommand.java compliant to POSIX 3.206 --- src/main/java/org/bitbiome/commands/UseCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index c0e5444..9133f8d 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -103,4 +103,4 @@ private boolean combat = false; enemies.add(mob); } } -} \ No newline at end of file +} From d47b77c1eab5c65f2402ef1b1a16979cda48c199 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 17:39:15 +0100 Subject: [PATCH 33/52] Made input for getUseMessage() case insensitive --- src/main/java/org/bitbiome/commands/UseCommand.java | 4 ++-- src/test/java/org/bitbiome/commands/UseCommandTest.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 9133f8d..183ba33 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -49,7 +49,7 @@ private boolean combat = false; for(int i = 0; i mobs = loc.getMobList(); for(int j = 0; j Date: Sat, 4 Feb 2023 17:52:57 +0100 Subject: [PATCH 34/52] refactoring: Pulled asking which item to use and on which enemy into its own function --- .../org/bitbiome/commands/UseCommand.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 183ba33..25684a4 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -14,14 +14,7 @@ private boolean combat = false; public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { Player player = engine.getPlayer(); getEnemies(player.getLocation().getMobList()); - System.out.println("Which item would you like to use?"); - String item = scanner.nextLine(); - System.out.println("On who? (leave blank for self)"); - String target = scanner.nextLine(); - if(target.equals("")) - System.out.println(getUseMessage(item, engine)); - else - System.out.println(getUseMessage(item + " on " + target, engine)); + use(scanner, engine); while(enemies.size() > 0 && combat) { if(player.getHp() <= 0) System.exit(0); @@ -41,6 +34,17 @@ private boolean combat = false; } } + public void use(Scanner scanner, TravelEngine engine) { + System.out.println("Which item would you like to use?"); + String item = scanner.nextLine(); + System.out.println("On who? (leave blank for self)"); + String target = scanner.nextLine(); + if(target.equals("")) + System.out.println(getUseMessage(item, engine)); + else + System.out.println(getUseMessage(item + " on " + target, engine)); + } + public String getUseMessage(String msg, TravelEngine engine) { Player player = engine.getPlayer(); String message[] = msg.split(" on "); From 0de3c01e11ada1f691108a35b81cb69e1b5dab2c Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:07:36 +0100 Subject: [PATCH 35/52] Added combat loop --- src/main/java/org/bitbiome/commands/UseCommand.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 25684a4..2fcda38 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -31,6 +31,18 @@ private boolean combat = false; player.setHp(hp); } //TODO get input from player + do { + System.out.println("What do you want to do?"); + String input = scanner.nextLine(); + switch(input) { + case "use": + use(scanner, engine); + break; + default: + System.out.println("That is not a valid command."); + break; + } + } while(true); } } From 6a2c1f96c6f0bafd49dac048956d167c249c36b3 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:08:34 +0100 Subject: [PATCH 36/52] Added ability to run away in combat --- .../java/org/bitbiome/commands/UseCommand.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 2fcda38..4361b74 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -31,13 +31,19 @@ private boolean combat = false; player.setHp(hp); } //TODO get input from player - do { + COMBAT_LOOP:do { System.out.println("What do you want to do?"); String input = scanner.nextLine(); switch(input) { case "use": use(scanner, engine); break; + case "runaway": + if(runawaySucceeds()) { + combat = false; + break COMBAT_LOOP; + } + break; default: System.out.println("That is not a valid command."); break; @@ -46,6 +52,13 @@ private boolean combat = false; } } + public boolean runawaySucceeds() { + int chance = (int)(Math.random()*100); + if(chance < 50) + return true; + return false; + } + public void use(Scanner scanner, TravelEngine engine) { System.out.println("Which item would you like to use?"); String item = scanner.nextLine(); From 7bc0e96f9e74396a09a7a8b1cd3efc80eb7cc92b Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:12:03 +0100 Subject: [PATCH 37/52] Added runaway command to general command listener --- .../org/bitbiome/commands/CommandListener.java | 1 + .../org/bitbiome/commands/RunAwayCommand.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/main/java/org/bitbiome/commands/RunAwayCommand.java diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index 4c67d71..64dc12c 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("use", new UseCommand()); commands.put("location", new LocationCommand()); commands.put("travel", new TravelCommand()); + commands.put("runaway", new RunAwayCommand()); } public HashMap returnCommands() { diff --git a/src/main/java/org/bitbiome/commands/RunAwayCommand.java b/src/main/java/org/bitbiome/commands/RunAwayCommand.java new file mode 100644 index 0000000..882223a --- /dev/null +++ b/src/main/java/org/bitbiome/commands/RunAwayCommand.java @@ -0,0 +1,15 @@ +package org.bitbiome.commands; + +import java.util.Scanner; + +import org.bitbiome.classes.TravelEngine; + +public class RunAwayCommand implements CommandAPI { + + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + // TODO Auto-generated method stub + + } + +} From df1d57aa8b77f319856c2f5f88a12edc1f308a49 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:14:43 +0100 Subject: [PATCH 38/52] Added output to runaway command --- src/main/java/org/bitbiome/commands/RunAwayCommand.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/RunAwayCommand.java b/src/main/java/org/bitbiome/commands/RunAwayCommand.java index 882223a..0e5b9bf 100644 --- a/src/main/java/org/bitbiome/commands/RunAwayCommand.java +++ b/src/main/java/org/bitbiome/commands/RunAwayCommand.java @@ -8,8 +8,11 @@ public class RunAwayCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { - // TODO Auto-generated method stub - + System.out.println(getRunAwayMessage()); + } + + public String getRunAwayMessage() { + return "You can only run away when you're fighting someone."; } } From 566f9797f703832e32032ba8aa6843b160d2a6af Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:16:38 +0100 Subject: [PATCH 39/52] unittest: Added test for RunAwayCommand.java --- .../org/bitbiome/commands/RunAwayCommandTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/test/java/org/bitbiome/commands/RunAwayCommandTest.java diff --git a/src/test/java/org/bitbiome/commands/RunAwayCommandTest.java b/src/test/java/org/bitbiome/commands/RunAwayCommandTest.java new file mode 100644 index 0000000..ab516b1 --- /dev/null +++ b/src/test/java/org/bitbiome/commands/RunAwayCommandTest.java @@ -0,0 +1,12 @@ +package org.bitbiome.commands; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class RunAwayCommandTest { + @Test + public void testRunAwayCommand() { + assertEquals("You can only run away when you're fighting someone.", new RunAwayCommand().getRunAwayMessage()); + } +} From 05d55304723251dc641276424ae4c57434478677 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:20:23 +0100 Subject: [PATCH 40/52] refactoring: Made use() return the final output and print it when the function is called --- src/main/java/org/bitbiome/commands/UseCommand.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 4361b74..4af63bc 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -14,7 +14,7 @@ private boolean combat = false; public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { Player player = engine.getPlayer(); getEnemies(player.getLocation().getMobList()); - use(scanner, engine); + System.out.println(use(scanner, engine)); while(enemies.size() > 0 && combat) { if(player.getHp() <= 0) System.exit(0); @@ -36,7 +36,7 @@ private boolean combat = false; String input = scanner.nextLine(); switch(input) { case "use": - use(scanner, engine); + System.out.println(use(scanner, engine)); break; case "runaway": if(runawaySucceeds()) { @@ -59,15 +59,15 @@ private boolean combat = false; return false; } - public void use(Scanner scanner, TravelEngine engine) { + public String use(Scanner scanner, TravelEngine engine) { System.out.println("Which item would you like to use?"); String item = scanner.nextLine(); System.out.println("On who? (leave blank for self)"); String target = scanner.nextLine(); if(target.equals("")) - System.out.println(getUseMessage(item, engine)); + return getUseMessage(item, engine); else - System.out.println(getUseMessage(item + " on " + target, engine)); + return getUseMessage(item + " on " + target, engine); } public String getUseMessage(String msg, TravelEngine engine) { From eee18034e06397d01baa415e8311a26ee673615a Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:30:33 +0100 Subject: [PATCH 41/52] refactoring: Removed obsolete function in UseCommandTest.java --- src/test/java/org/bitbiome/commands/UseCommandTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/java/org/bitbiome/commands/UseCommandTest.java b/src/test/java/org/bitbiome/commands/UseCommandTest.java index c14562f..0cc69d3 100644 --- a/src/test/java/org/bitbiome/commands/UseCommandTest.java +++ b/src/test/java/org/bitbiome/commands/UseCommandTest.java @@ -9,10 +9,6 @@ import org.bitbiome.entities.Player; import org.junit.jupiter.api.Test; public class UseCommandTest { - public void testUseCommand() { - testGetUseMessage(); - } - @Test public void testUseItemMob() { UseCommand com = new UseCommand(); From 0689c30a621e8eef80dd3eff1ce1f12a6b00f013 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:57:42 +0100 Subject: [PATCH 42/52] refactoring: Created function for dynamically getting runaway chance --- .../org/bitbiome/commands/UseCommand.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 4af63bc..8d3a496 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -39,7 +39,7 @@ private boolean combat = false; System.out.println(use(scanner, engine)); break; case "runaway": - if(runawaySucceeds()) { + if(runawaySucceeds(getRunawayChance())) { combat = false; break COMBAT_LOOP; } @@ -52,13 +52,24 @@ private boolean combat = false; } } - public boolean runawaySucceeds() { - int chance = (int)(Math.random()*100); - if(chance < 50) + public boolean runawaySucceeds(int chance) { + int random = (int)(Math.random()*100); + if(random >= chance) return true; return false; } + public int getRunawayChance() { + int chance = 10; + for(int i = 0; i 100) + chance = 100; + return chance; + } + public String use(Scanner scanner, TravelEngine engine) { System.out.println("Which item would you like to use?"); String item = scanner.nextLine(); From 2d71a5a016da6614bb9a320c014ae51b5b0b973c Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 18:58:25 +0100 Subject: [PATCH 43/52] unittest: Added test for getRunawayChance() --- .../org/bitbiome/commands/UseCommandTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/UseCommandTest.java b/src/test/java/org/bitbiome/commands/UseCommandTest.java index 0cc69d3..343c1b5 100644 --- a/src/test/java/org/bitbiome/commands/UseCommandTest.java +++ b/src/test/java/org/bitbiome/commands/UseCommandTest.java @@ -2,6 +2,8 @@ package org.bitbiome.commands; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.ArrayList; + import org.bitbiome.classes.TravelEngine; import org.bitbiome.entities.Item; import org.bitbiome.entities.Mob; @@ -9,6 +11,30 @@ import org.bitbiome.entities.Player; import org.junit.jupiter.api.Test; public class UseCommandTest { + @Test + public void testGetRunawayChance() { + UseCommand com = new UseCommand(); + assertEquals(10, com.getRunawayChance()); + ArrayList enemies = new ArrayList(); + enemies.add(new Mob("Wolf", false, 11, 10)); + com.getEnemies(enemies); + assertEquals(17, com.getRunawayChance()); + enemies.add(new Mob("Drache", false, 55, 20)); + com.getEnemies(enemies); + assertEquals(41, com.getRunawayChance()); + enemies.add(new Mob("Drache", false, 55, 20)); + enemies.add(new Mob("Drache", false, 55, 20)); + enemies.add(new Mob("Drache", false, 55, 20)); + enemies.add(new Mob("Drache", false, 55, 20)); + enemies.add(new Mob("Drache", false, 55, 20)); + com.getEnemies(enemies); + assertEquals(96, com.getRunawayChance()); + enemies = new ArrayList(); + enemies.add(new Mob("Cthulhu", false, 15000, 10000)); + com.getEnemies(enemies); + assertEquals(100, com.getRunawayChance()); + } + @Test public void testUseItemMob() { UseCommand com = new UseCommand(); From 0fbbac75bc5d9ded5ce057b37315885e3bde55d8 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 19:52:58 +0100 Subject: [PATCH 44/52] Added answers for the other commands during combat --- src/main/java/org/bitbiome/commands/UseCommand.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 8d3a496..6c0887a 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -44,6 +44,19 @@ private boolean combat = false; break COMBAT_LOOP; } break; + case "help": + new HelpCommand().performCommand(scanner, isRunning, message, engine); + break; + case "exit": + case "quit": + System.out.println("You cannot quit while in combat."); + break; + case "location": + new LocationCommand().performCommand(scanner, isRunning, message, engine); + break; + case "travel": + System.out.println("You cannot travel while in combat."); + break; default: System.out.println("That is not a valid command."); break; From c392ee6c26600a9a10960878019ea35637846b76 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 19:53:37 +0100 Subject: [PATCH 45/52] unittest: Added test for testRunawaySucceeds() --- .../java/org/bitbiome/commands/UseCommandTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/org/bitbiome/commands/UseCommandTest.java b/src/test/java/org/bitbiome/commands/UseCommandTest.java index 343c1b5..d9a1710 100644 --- a/src/test/java/org/bitbiome/commands/UseCommandTest.java +++ b/src/test/java/org/bitbiome/commands/UseCommandTest.java @@ -1,6 +1,7 @@ package org.bitbiome.commands; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; @@ -35,6 +36,15 @@ public class UseCommandTest { assertEquals(100, com.getRunawayChance()); } + @Test + public void testRunawaySucceeds() { + UseCommand com = new UseCommand(); + assertEquals(true, com.runawaySucceeds(0)); + assertEquals(false, com.runawaySucceeds(101)); + int random = (int)(Math.random()*100); + assertTrue(com.runawaySucceeds(random) || !com.runawaySucceeds(random)); + } + @Test public void testUseItemMob() { UseCommand com = new UseCommand(); From 9ed2f1a825b0660aa2b296ff4a70a21edc722437 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 19:54:46 +0100 Subject: [PATCH 46/52] refactoring: Fixed use command not jumping out of COMBAT_LOOP --- src/main/java/org/bitbiome/commands/UseCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 6c0887a..cdef2f5 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -37,7 +37,7 @@ private boolean combat = false; switch(input) { case "use": System.out.println(use(scanner, engine)); - break; + break COMBAT_LOOP; case "runaway": if(runawaySucceeds(getRunawayChance())) { combat = false; From 51c5b408271213d961368d7685738a93e365edbb Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 20:18:28 +0100 Subject: [PATCH 47/52] Removed useless test --- src/test/java/org/bitbiome/commands/UseCommandTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/org/bitbiome/commands/UseCommandTest.java b/src/test/java/org/bitbiome/commands/UseCommandTest.java index d9a1710..a131e68 100644 --- a/src/test/java/org/bitbiome/commands/UseCommandTest.java +++ b/src/test/java/org/bitbiome/commands/UseCommandTest.java @@ -1,7 +1,6 @@ package org.bitbiome.commands; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; @@ -41,8 +40,6 @@ public class UseCommandTest { UseCommand com = new UseCommand(); assertEquals(true, com.runawaySucceeds(0)); assertEquals(false, com.runawaySucceeds(101)); - int random = (int)(Math.random()*100); - assertTrue(com.runawaySucceeds(random) || !com.runawaySucceeds(random)); } @Test From 868eb67c39b06e682e87f364829318a9c4c30e9d Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 20:22:47 +0100 Subject: [PATCH 48/52] Added use to help command --- 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 ee4f237..d9c7b40 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 + " use" + Colors.ANSI_RESET + " | Benutze ein Item |\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 5caac07..d294c25 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 + " use" + Colors.ANSI_RESET + " | Benutze ein Item |\n") .append("|______________|_____________________________|\n"); assertEquals(outputMessage.toString(), helpMessage); } From fad85807f24da092eda0f6d002671bbd85edbfa5 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 20:48:59 +0100 Subject: [PATCH 49/52] refactoring: Made a function which executes one cycle of combat --- src/main/java/org/bitbiome/commands/UseCommand.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index cdef2f5..fe57e5c 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -16,7 +16,12 @@ private boolean combat = false; getEnemies(player.getLocation().getMobList()); System.out.println(use(scanner, engine)); while(enemies.size() > 0 && combat) { - if(player.getHp() <= 0) + combat(player, scanner, engine); + } + } + + public void combat(Player player, Scanner scanner, TravelEngine engine) { + if(player.getHp() <= 0) System.exit(0); for(int i = 0; i Date: Sat, 4 Feb 2023 20:31:01 +0100 Subject: [PATCH 50/52] Added output to runaway input while in combat --- src/main/java/org/bitbiome/commands/UseCommand.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index fe57e5c..296f535 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -44,9 +44,11 @@ private boolean combat = false; break COMBAT_LOOP; case "runaway": if(runawaySucceeds(getRunawayChance())) { + System.out.println("You successfully ran away."); combat = false; break COMBAT_LOOP; } + System.out.println("You failed to run away."); break; case "help": new HelpCommand().performCommand(scanner, true, "", engine); From 5e4cb1f890646464406547bf7333cd2d97f9def6 Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 20:31:54 +0100 Subject: [PATCH 51/52] Added runaway to help command --- 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 d9c7b40..cc6f023 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -30,6 +30,8 @@ public class HelpCommand implements CommandAPI { .append("|" + Colors.ANSI_GREEN + " location" + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") .append("|______________|_____________________________|\n") .append("|" + Colors.ANSI_GREEN + " use" + Colors.ANSI_RESET + " | Benutze ein Item |\n") + .append("|______________|_____________________________|\n") + .append("|" + Colors.ANSI_GREEN + " runaway" + Colors.ANSI_RESET + " | Fliehe aus einem Kampf |\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 d294c25..93f0e23 100644 --- a/src/test/java/org/bitbiome/commands/HelpCommandTest.java +++ b/src/test/java/org/bitbiome/commands/HelpCommandTest.java @@ -24,6 +24,8 @@ public class HelpCommandTest { .append("|" + Colors.ANSI_GREEN + " location" + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") .append("|______________|_____________________________|\n") .append("|" + Colors.ANSI_GREEN + " use" + Colors.ANSI_RESET + " | Benutze ein Item |\n") + .append("|______________|_____________________________|\n") + .append("|" + Colors.ANSI_GREEN + " runaway" + Colors.ANSI_RESET + " | Fliehe aus einem Kampf |\n") .append("|______________|_____________________________|\n"); assertEquals(outputMessage.toString(), helpMessage); } From 6539908e62d0ffb7274457bda61c3a2fecae87ec Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 4 Feb 2023 20:42:21 +0100 Subject: [PATCH 52/52] Translated all the outputs to German --- .../org/bitbiome/commands/UseCommand.java | 36 +++++++++---------- .../org/bitbiome/commands/UseCommandTest.java | 24 ++++++------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 296f535..a570a68 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -27,16 +27,16 @@ private boolean combat = false; Mob mob = enemies.get(i); float hp = player.getHp(); hp -= mob.getDamage(); - System.out.println(mob.getName() + " attacked you for " + mob.getDamage() + " damage."); + System.out.println(mob.getName() + " hat dich angegriffen und " + mob.getDamage() + " Schaden zugefügt."); if(hp <= 0) { player.setHp(0); - System.out.println("You died."); + System.out.println("Du bist gestorben."); System.exit(0); } player.setHp(hp); } COMBAT_LOOP:do { - System.out.println("What do you want to do?"); + System.out.println("Was willst du tun?"); String input = scanner.nextLine(); switch(input) { case "use": @@ -44,27 +44,27 @@ private boolean combat = false; break COMBAT_LOOP; case "runaway": if(runawaySucceeds(getRunawayChance())) { - System.out.println("You successfully ran away."); + System.out.println("Du bist erfolgreich geflüchtet."); combat = false; break COMBAT_LOOP; } - System.out.println("You failed to run away."); + System.out.println("Dein Fluchtversuch ist fehlgeschlagen."); break; case "help": new HelpCommand().performCommand(scanner, true, "", engine); break; case "exit": case "quit": - System.out.println("You cannot quit while in combat."); + System.out.println("Du kannst nicht während eines Kampfes das Spiel verlassen."); break; case "location": new LocationCommand().performCommand(scanner, true, "", engine); break; case "travel": - System.out.println("You cannot travel while in combat."); + System.out.println("Du kannst nicht während eines Kampfes reisen."); break; default: - System.out.println("That is not a valid command."); + System.out.println("Unbekannter Befehl - Siehe " + Colors.ANSI_PURPLE + "help" + Colors.ANSI_RESET); break; } } while(true); @@ -89,9 +89,9 @@ private boolean combat = false; } public String use(Scanner scanner, TravelEngine engine) { - System.out.println("Which item would you like to use?"); + System.out.println("Welches Item willst du benutzen?"); String item = scanner.nextLine(); - System.out.println("On who? (leave blank for self)"); + System.out.println("Auf welchen Gegner willst du es benutzen? (Leer lassen, um es auf dich selbst anzuwenden)"); String target = scanner.nextLine(); if(target.equals("")) return getUseMessage(item, engine); @@ -109,7 +109,7 @@ private boolean combat = false; Item item = inv.get(i); if(item.getName().toLowerCase().equals(itemName.toLowerCase())) { if(!item.doesDamage()) - return "You can't attack with this."; + return "Damit kannst du nicht angreifen."; if(message.length == 1) return useItem(item, player); String targetName = message[1]; @@ -120,22 +120,22 @@ private boolean combat = false; if(mob.getName().toLowerCase().equals(targetName.toLowerCase())) return useItem(item, mob, loc); } - return "That target is not available."; + return "Dieses Ziel ist nicht verfügbar."; } } - return "That item is not in your inventory."; + return "Du bist nicht im Besitz dieses Items."; } public String useItem(Item item, Player target) { float hp = target.getHp(); hp -= item.getDamage(); - String retString = "You used " + item.getName() + " on yourself"; + String retString = "Du hast " + item.getName() + " auf dich selbst angewandt"; if(hp <= 0) { target.setHp(0); - return retString + " and died."; + return retString + " und bist gestorben."; } target.setHp(hp); - return retString; + return retString + "."; } public String useItem(Item item, Mob target, Location location) { @@ -147,11 +147,11 @@ private boolean combat = false; if(dmg>=hp) { location.getMobList().remove(target); enemies.remove(target); - return "You killed " + target.getName() + " with " + item.getName(); + return "Du hast " + target.getName() + " mit " + item.getName() + " getötet."; } target.setHp(hp-dmg); target.setFriendly(false); - return "You used " + item.getName() + " on " + target.getName(); + return "Du hast " + item.getName() + " auf " + target.getName() + " angewandt."; } public void getEnemies(ArrayList allMobs) { diff --git a/src/test/java/org/bitbiome/commands/UseCommandTest.java b/src/test/java/org/bitbiome/commands/UseCommandTest.java index a131e68..a8081ba 100644 --- a/src/test/java/org/bitbiome/commands/UseCommandTest.java +++ b/src/test/java/org/bitbiome/commands/UseCommandTest.java @@ -49,9 +49,9 @@ public class UseCommandTest { Mob mob = new Mob("Wolf", false, 11, 10); player.getLocation().getMobList().add(mob); Item sword = new Item("Sword", true, 10); - assertEquals("You used Sword on Wolf", com.useItem(sword, mob, player.getLocation())); + assertEquals("Du hast Sword auf Wolf angewandt.", com.useItem(sword, mob, player.getLocation())); assertEquals(1, player.getLocation().getMobList().size()); - assertEquals("You killed Wolf with Sword", com.useItem(sword, mob, player.getLocation())); + assertEquals("Du hast Wolf mit Sword getötet.", com.useItem(sword, mob, player.getLocation())); assertEquals(0, player.getLocation().getMobList().size()); } @@ -60,27 +60,27 @@ public class UseCommandTest { UseCommand com = new UseCommand(); Player player = new Player("test"); Item sword = new Item("Sword", true, 10); - assertEquals("You used Sword on yourself", com.useItem(sword, player)); + assertEquals("Du hast Sword auf dich selbst angewandt.", com.useItem(sword, player)); assertEquals(90, player.getHp()); Item sword2 = new Item("Heiliges Schwert der Engel", true, 1000); - assertEquals("You used Heiliges Schwert der Engel on yourself and died.", com.useItem(sword2, player)); + assertEquals("Du hast Heiliges Schwert der Engel auf dich selbst angewandt und bist gestorben.", com.useItem(sword2, player)); } @Test public void testGetUseMessage() { UseCommand com = new UseCommand(); TravelEngine engine = new TravelEngine(new Player("test")); - assertEquals("That item is not in your inventory.", com.getUseMessage("", engine)); - assertEquals("That item is not in your inventory.", com.getUseMessage("Fell", engine)); + assertEquals("Du bist nicht im Besitz dieses Items.", com.getUseMessage("", engine)); + assertEquals("Du bist nicht im Besitz dieses Items.", com.getUseMessage("Fell", engine)); engine.getPlayer().addToInventory(new Item("Fell", false, 0)); - assertEquals("You can't attack with this.", com.getUseMessage("Fell", engine)); + assertEquals("Damit kannst du nicht angreifen.", com.getUseMessage("Fell", engine)); engine.getPlayer().addToInventory(new Item("Heiliges Schwert der Erzengel", true, 3000)); - assertEquals("That target is not available.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); - assertEquals("That target is not available.", com.getUseMessage("hEiLiGeS sChWeRt DeR eRzEnGeL on WoLf", engine)); + assertEquals("Dieses Ziel ist nicht verfügbar.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); + assertEquals("Dieses Ziel ist nicht verfügbar.", com.getUseMessage("hEiLiGeS sChWeRt DeR eRzEnGeL on WoLf", engine)); engine.getPlayer().getLocation().getMobList().add(new Mob("Wolf", false, 11, 10)); - assertEquals("You killed Wolf with Heiliges Schwert der Erzengel", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); - assertEquals("That target is not available.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); + assertEquals("Du hast Wolf mit Heiliges Schwert der Erzengel getötet.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); + assertEquals("Dieses Ziel ist nicht verfügbar.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); engine.getPlayer().getLocation().getMobList().add(new Mob("Wolf", false, 11, 10)); - assertEquals("You killed Wolf with Heiliges Schwert der Erzengel", com.getUseMessage("hEiLiGeS sChWeRt DeR eRzEnGeL on WoLf", engine)); + assertEquals("Du hast Wolf mit Heiliges Schwert der Erzengel getötet.", com.getUseMessage("hEiLiGeS sChWeRt DeR eRzEnGeL on WoLf", engine)); } }