Browse Source

Merge branch 'develop' of https://github.com/RedEagle-dh/BitBiome into develop

# Conflicts:
#	src/main/java/org/bitbiome/commands/CommandListener.java
#	src/main/java/org/bitbiome/commands/HelpCommand.java
#	src/main/java/org/bitbiome/entities/Player.java
#	src/main/resources/gameconfig.json
#	src/main/resources/items.json
remotes/origin/develop
Tanja Herche 2 years ago
parent
commit
45e59b4d7b
  1. 24
      playerconfig.json
  2. 2
      src/main/java/org/bitbiome/classes/Shop.java
  3. 3
      src/main/java/org/bitbiome/classes/TravelEngine.java
  4. 65
      src/main/java/org/bitbiome/commands/CollectCommand.java
  5. 4
      src/main/java/org/bitbiome/commands/CommandListener.java
  6. 11
      src/main/java/org/bitbiome/commands/HelpCommand.java
  7. 32
      src/main/java/org/bitbiome/commands/InventoryCommand.java
  8. 138
      src/main/java/org/bitbiome/commands/LookaroundCommand.java
  9. 44
      src/main/resources/items.json
  10. 14
      src/main/resources/playerconfig.json
  11. 2
      src/main/resources/quiz.json
  12. 26
      src/test/java/org/bitbiome/commands/CollectCommandTest.java
  13. 33
      src/test/java/org/bitbiome/commands/InventoryCommandTest.java
  14. 194
      src/test/java/org/bitbiome/commands/LookaroundCommandTest.java

24
playerconfig.json

@ -0,0 +1,24 @@
{
"gold": 0,
"name": "Julia",
"hp": 10,
"inventory": [
{
"gold": 5,
"damage": "10",
"amount": 6,
"durability": 1000,
"name": "Holz",
"doesDamage": true
},
{
"gold": 5,
"damage": "10",
"amount": 5,
"durability": 1000,
"name": "Stein",
"doesDamage": true
}
],
"currentLocation": "Wald"
}

2
src/main/java/org/bitbiome/classes/Shop.java

@ -152,7 +152,7 @@ public class Shop {
return arrayList;
}
public JSONArray returnJSONArrayOfAllItems() {
public static JSONArray returnJSONArrayOfAllItems() {
File file = new File("src/main/resources/items.json");
JSONArray itemJSON = null;
try {

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

@ -108,8 +108,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;

65
src/main/java/org/bitbiome/commands/CollectCommand.java

@ -0,0 +1,65 @@
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.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) {
StringBuilder s = new StringBuilder();
JsonParser jp = new JsonParser();
JSONObject o = jp.getJSONObject("playerconfig.json");
JSONArray inventory = o.getJSONArray("inventory");
ArrayList<Item> location = travelEngine.getPlayer().getLocation().getItemList();
ArrayList<Item> getInventory = travelEngine.getPlayer().getInventory();
System.out.println("Was willst du einsammeln?");
String item = new String();
item = scanner.nextLine();
collectItem(location, item, jp, o, inventory,getInventory);
}
public void collectItem(ArrayList<Item> location, String item, JsonParser jp, JSONObject o, JSONArray inventory, ArrayList<Item> 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 < 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)) {
increaseAmountInPlayerConfig(inventory,k,jp,o);
return;
}
}
}
}
writeNewItem(location, getInventory, o1, inventory, i, jp, o);
}
} System.out.println("Es gibt kein Item, dass du einsammeln kannst.");
}
public void writeNewItem(ArrayList<Item> location, ArrayList<Item> getInventory, JSONObject o1, JSONArray inventory, int i, JsonParser jp, JSONObject o){
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);
}
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(Colors.ANSI_YELLOW +"Du hast das Item eingesammelt."+ Colors.ANSI_RESET);
}
}

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

@ -18,10 +18,12 @@ public class CommandListener {
commands.put("quit", new QuitCommand());
commands.put("location", new LocationCommand());
commands.put("travel", new TravelCommand());
commands.put("inventory", new InventoryCommand());
commands.put("lookaround", new LookaroundCommand());
commands.put("collect", new CollectCommand());
commands.put("map", new MapCommand());
commands.put("gold", new GoldCommand());
commands.put("shop", new ShopCommand());
}
public HashMap<String, CommandAPI> returnCommands() {

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

@ -33,6 +33,17 @@ public class HelpCommand implements CommandAPI {
.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 + " 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")
.append("|" + Colors.ANSI_GREEN + " map" + Colors.ANSI_RESET + " | Zeigt dir deinen Karte |\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " gold" + Colors.ANSI_RESET + " | Gibt dein Gold an |\n")

32
src/main/java/org/bitbiome/commands/InventoryCommand.java

@ -0,0 +1,32 @@
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.json.JSONObject;
import java.util.ArrayList;
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) {
StringBuilder s = new StringBuilder();
ArrayList<Item> inventory = travelEngine.getPlayer().getInventory();
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_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();
}
}

138
src/main/java/org/bitbiome/commands/LookaroundCommand.java

@ -0,0 +1,138 @@
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;
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 outputMessage = new StringBuilder();
Location location = travelEngine.getPlayer().getLocation();
JsonParser jp = new JsonParser();
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");
JSONArray mobs = locationObject.getJSONArray("mobs");
Random random = new Random();
int randomNumberItems = random.nextInt(items.length()+1);
int randomNumberMobs = random.nextInt(mobs.length()+1);
ArrayList<Item> foundItems = location.getItemList();
foundItems.removeAll(foundItems);
ArrayList<Mob> foundMobs = location.getMobList();
foundMobs.removeAll(foundMobs);
foundItems = getRandomItem(randomNumberItems, random, items, foundItems);
foundMobs = getRandomMob(randomNumberMobs,random,mobs,foundMobs);
getLocationDescription(location,outputMessage);
getItemsOutput(randomNumberItems,outputMessage,foundItems);
getMobsOutput(randomNumberItems,randomNumberMobs,outputMessage, foundMobs);
System.out.println(outputMessage);
}
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);
}
public ArrayList<Item> getRandomItem(int randomNumberItems, Random random, JSONArray items, ArrayList<Item> foundItems ) {
for (int i=0; i<randomNumberItems; i++){
String s1 = items.getString(random.nextInt(items.length()));
JSONArray jp3 = Shop.returnJSONArrayOfAllItems();
JSONObject jp2= jp3.getJSONObject(0);
for (int j=1; j<jp3.length(); j++ ){
if(jp3.getJSONObject(j).getString("name").equals(s1)){
jp2 = jp3.getJSONObject(j);
break;
}
}
Item randomItem = new Item (jp2.getString("name"),jp2.getBoolean("doesDamage"),jp2.getString("damage"),1, jp2.getInt("gold"));
foundItems.add(randomItem);
}
return foundItems;
}
public ArrayList<Mob> getRandomMob(int randomNumberMobs, Random random, JSONArray mobs, ArrayList<Mob> foundMobs){
for (int i=0; i<randomNumberMobs; i++){
JSONObject jp2 = mobs.getJSONObject(random.nextInt(mobs.length()));
Mob randomMob = new Mob (jp2.getString("name"),jp2.getBoolean("isFriendly"),jp2.getFloat("hp"),jp2.getFloat("damage"));
foundMobs.add(randomMob);
} return foundMobs;
}
public void getItemsOutput(int randomNumberItems, StringBuilder outputMessage, ArrayList<Item> foundItems){
if (randomNumberItems != 0){
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(Colors.ANSI_BLUE +"Schnell, sammel es ein!\n"+ Colors.ANSI_RESET);
}
else {
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<Mob> foundMobs){
if (randomNumberMobs != 0){
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");
}
}
if((randomNumberMobs ==0) && (randomNumberItems == 0)){
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
}
}
}

44
src/main/resources/items.json

@ -1,3 +1,4 @@
<<<<<<< HEAD
[
{
"name": "Holz",
@ -179,4 +180,45 @@
"amountShop": 700,
"gold": 2
}
]
]
=======
[
{
"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
}
]
>>>>>>> 1ffe7490e8fd33b80231ec4852d6ca37658dcd5f

14
src/main/resources/playerconfig.json

@ -4,14 +4,20 @@
"hp": 10,
"inventory": [
{
"amount": "5",
"gold": 5,
"damage": "10",
"amount": 5,
"durability": 1000,
"name": "Holz"
"name": "Holz",
"doesDamage": true
},
{
"amount": "5",
"gold": 5,
"damage": "10",
"amount": 5,
"durability": 1000,
"name": "Stein"
"name": "Stein",
"doesDamage": true
}
],
"currentLocation": "Berge"

2
src/main/resources/quiz.json

@ -201,5 +201,5 @@
]
}
],
"lastPlayed": 1675768444160
"lastPlayed": 1675852467225
}

26
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("src/main/resources/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);
}
}

33
src/test/java/org/bitbiome/commands/InventoryCommandTest.java

@ -0,0 +1,33 @@
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 testReadInv(){
InventoryCommand command = new InventoryCommand();
TravelEngine travelEngine = new TravelEngine(new Player("Unit"));
ArrayList<Item> inventory = new ArrayList<>();
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" +
"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_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);
}
}

194
src/test/java/org/bitbiome/commands/LookaroundCommandTest.java

@ -0,0 +1,194 @@
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;
import org.junit.jupiter.api.Test;
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 {
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"));
}
@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<Mob> foundMobs = new ArrayList<>();
ArrayList<Mob> result = command.getRandomMob(randomNumberMobs, random, mobs, foundMobs);
assertEquals(randomNumberMobs, result.size());
for (Mob mob : result) {
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<Item> foundItems = new ArrayList<Item>();
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" +
Colors.ANSI_BLUE +"Schnell, sammel es ein!\n"+ Colors.ANSI_RESET;
assertEquals(expectedOutput, outputMessage.toString());
}
@Test
public void testGetItemsOutputWithoutItems() {
LookaroundCommand command = new LookaroundCommand();
int randomNumberItems = 0;
StringBuilder outputMessage = new StringBuilder();
ArrayList<Item> foundItems = new ArrayList<Item>();
command.getItemsOutput(randomNumberItems, outputMessage, foundItems);
String expectedOutput = Colors.ANSI_BLUE+ "Hier gibt es leider nichts für dich zum Einsammeln.\n"+ Colors.ANSI_RESET;
assertEquals(expectedOutput, outputMessage.toString());
}
@Test
public void testGetMobsOutputWithMobs() {
LookaroundCommand command = new LookaroundCommand();
int randomNumberMobs = 2;
int randomNumberItems = 0;
StringBuilder outputMessage = new StringBuilder();
ArrayList<Mob> 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 = 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
public void testGetMobsOutputWithoutMobsAndItems() {
LookaroundCommand command = new LookaroundCommand();
int randomNumberMobs = 0;
int randomNumberItems = 0;
StringBuilder outputMessage = new StringBuilder();
ArrayList<Mob> 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());
}
@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<Item> 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.getString("damage"), 1, 3);
result.add(item);
}
assertEquals(2, result.size());
assertEquals("Holz", result.get(0).getName());
assertEquals("Stein", result.get(1).getName());
}
@Test
public void testWaldDescription() {
LookaroundCommand command = new LookaroundCommand();
ArrayList<Mob> enemies = new ArrayList<Mob>();
enemies.add(new Mob("Bigfoot", false, 50,20));
ArrayList<Item> items = new ArrayList<Item>();
items.add(new Item("Holz",true, "10", 1,3));
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());
}
@Test
public void testStrandDescription() {
LookaroundCommand command = new LookaroundCommand();
ArrayList<Mob> enemies = new ArrayList<Mob>();
enemies.add(new Mob("Bigfoot", false, 50,20));
ArrayList<Item> items = new ArrayList<Item>();
items.add(new Item("Holz",true, "10", 1, 5));
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());
}
@Test
public void testUnknownLocationDescription() {
LookaroundCommand command = new LookaroundCommand();
ArrayList<Mob> enemies = new ArrayList<Mob>();
enemies.add(new Mob("unknown", false, 50,20));
ArrayList<Item> items = new ArrayList<Item>();
items.add(new Item("unknown",true, "10", 1, 5));
Location location = new Location("Unknown",enemies, items);
StringBuilder outputMessage = new StringBuilder();
command.getLocationDescription(location, outputMessage);
assertEquals("", outputMessage.toString());
}
}
Loading…
Cancel
Save