Browse Source

refactoring: added colors

remotes/origin/Julia
Juliakn66 2 years ago
parent
commit
58412a04d6
  1. 12
      src/main/java/org/bitbiome/commands/CollectCommand.java
  2. 6
      src/main/java/org/bitbiome/commands/InventoryCommand.java
  3. 9
      src/main/java/org/bitbiome/commands/LookaroundCommand.java
  4. 21
      src/test/java/org/bitbiome/commands/InventoryCommandTest.java
  5. 8
      src/test/java/org/bitbiome/commands/LookaroundCommandTest.java

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

@ -1,5 +1,6 @@
package org.bitbiome.commands;
import org.bitbiome.classes.Colors;
import org.bitbiome.classes.JsonParser;
import org.bitbiome.classes.TravelEngine;
import org.bitbiome.entities.Item;
@ -26,7 +27,6 @@ public class CollectCommand implements CommandAPI {
collectItem(location, item, jp, o, inventory,getInventory);
}
public void collectItem(ArrayList<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())) {
@ -47,12 +47,8 @@ public class CollectCommand implements CommandAPI {
} 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());
o1.put("doesDamage", location.get(i).doesDamage());
o1.put("damage", location.get(i).getDamage());
o1.put("amount", 1);
o1.put("durability", 1000);
o.getJSONArray("inventory").put(o1);
o1.put("name", location.get(i).getName()).put("doesDamage", location.get(i).doesDamage()).put("damage", location.get(i).getDamage()).put("amount", 1).put("durability", 1000);
inventory.put(o1);
jp.writeObject("playerconfig.json", o);
getInventory.add(location.get(i));
location.remove(i);
@ -63,7 +59,7 @@ public class CollectCommand implements CommandAPI {
amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount");
inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1);
jp.writeObject("playerconfig.json", o);
System.out.println("Du hast das Item eingesammelt.");
System.out.println(Colors.ANSI_YELLOW +"Du hast das Item eingesammelt."+ Colors.ANSI_RESET);
}
}

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

@ -20,9 +20,11 @@ public class InventoryCommand implements CommandAPI {
StringBuilder s = new StringBuilder();
ArrayList<Item> inventory = travelEngine.getPlayer().getInventory();
s.append(Colors.ANSI_BRIGHT_RED +"Du möchtest wissen, was in deinem Inventar ist? \nDann lass uns gemeinsam deinen Rucksack öffnen. \nDein Rucksack steckt ja voller Überraschungen! \nDas hast du alles schon gefunden: \n"+ Colors.ANSI_RESET);
s.append(Colors.ANSI_PURPLE +"Du möchtest wissen, was in deinem Inventar ist? \n" +
"Dann lass uns gemeinsam deinen Rucksack öffnen. \nDein Rucksack steckt ja voller Überraschungen! \n" +
"Das hast du alles schon gefunden: \n"+ Colors.ANSI_RESET);
for (int i=0; i < inventory.size(); i++){
s.append(Colors.ANSI_BRIGHT_BG_RED+ Colors.ANSI_BRIGHT_WHITE+ "- ").append(inventory.get(i).getName()).append(" x").append(inventory.get(i).getAmount()).append(" "+ Colors.ANSI_RESET + "\n" );
s.append(Colors.ANSI_BG_PURPLE+ Colors.ANSI_BRIGHT_WHITE+ "- ").append(inventory.get(i).getName()).append(" x").append(inventory.get(i).getAmount()).append(" "+ Colors.ANSI_RESET + "\n" );
}
return s.toString();

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

@ -79,21 +79,22 @@ public class LookaroundCommand implements CommandAPI{
foundMobs.add(randomMob);
} return foundMobs;
}
public void getItemsOutput(int randomNumberItems, StringBuilder outputMessage, ArrayList<Item> foundItems){
if (randomNumberItems != 0){
outputMessage.append("Huch, was liegt denn hier rum?\n");
outputMessage.append(Colors.ANSI_BLUE +"Huch, was liegt denn hier rum?\n"+ Colors.ANSI_RESET);
for (int i = 0; i < foundItems.size(); i++){
outputMessage. append("- ").append(foundItems.get(i).getName()+"\n");
}
outputMessage.append("Schnell, sammel es ein!\n");
outputMessage.append(Colors.ANSI_BLUE +"Schnell, sammel es ein!\n"+ Colors.ANSI_RESET);
}
else {
outputMessage.append("Hier gibt es leider nichts für dich zum Einsammeln.\n");
outputMessage.append(Colors.ANSI_BLUE+ "Hier gibt es leider nichts für dich zum Einsammeln.\n"+ Colors.ANSI_RESET);
}
}
public void getMobsOutput(int randomNumberItems, int randomNumberMobs, StringBuilder outputMessage, ArrayList<Mob> foundMobs){
if (randomNumberMobs != 0){
outputMessage.append("Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n");
outputMessage.append(Colors.ANSI_RED+"Achtung, hier lauern Gefahren!"+Colors.ANSI_RESET +"Sei auf der Hut vor: \n");
for (int i = 0; i < foundMobs.size(); i++){
outputMessage. append( "- ").append(foundMobs.get(i).getName()+"\n");
}

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

@ -11,28 +11,23 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class InventoryCommandTest {
@Test
public void testInventoryCommand(){
public void testReadInv(){
InventoryCommand command = new InventoryCommand();
Player p = new Player("Unit");
TravelEngine travelEngine = new TravelEngine(p);
TravelEngine travelEngine = new TravelEngine(new Player("Unit"));
ArrayList<Item> inventory = new ArrayList<>();
Item item1 = new Item("Holz", false, 0,5);
Item item2 = new Item("Stein", true, 10, 5);
inventory.add(item1);
inventory.add(item2);
inventory.add(new Item("Holz", false, 0,5));
inventory.add(new Item("Stein", true, 10, 5));
travelEngine.getPlayer().setInventory(inventory);
String expectedResult = Colors.ANSI_BRIGHT_RED + "Du möchtest wissen, was in deinem Inventar ist? \n" +
String expectedResult = Colors.ANSI_PURPLE + "Du möchtest wissen, was in deinem Inventar ist? \n" +
"Dann lass uns gemeinsam deinen Rucksack öffnen. \nDein Rucksack steckt ja voller Überraschungen! \n" +
"Das hast du alles schon gefunden: \n" + Colors.ANSI_RESET +
Colors.ANSI_BRIGHT_BG_RED + Colors.ANSI_BRIGHT_WHITE + "- " + "Holz" + " x" + 5 + " " + Colors.ANSI_RESET + "\n" +
Colors.ANSI_BRIGHT_BG_RED + Colors.ANSI_BRIGHT_WHITE + "- " + "Stein" + " x" + 5 + " " + Colors.ANSI_RESET + "\n";
Colors.ANSI_BG_PURPLE + Colors.ANSI_BRIGHT_WHITE + "- " + "Holz" + " x" + 5 + " " + Colors.ANSI_RESET + "\n" +
Colors.ANSI_BG_PURPLE + Colors.ANSI_BRIGHT_WHITE + "- " + "Stein" + " x" + 5 + " " + Colors.ANSI_RESET + "\n";
String result = command.readInv(travelEngine);
assertEquals(expectedResult, result);
}
}
}
//was ist, wenn ich mehr im inventar habe?, wie kann ich den anpassen auf den jeweiligen spielstand?

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

@ -80,7 +80,9 @@ public class LookaroundCommandTest {
foundItems.add(new Item("Stein", true, 10, 1));
foundItems.add(new Item("Sand", false, 1, 1));
command.getItemsOutput(randomNumberItems, outputMessage, foundItems);
String expectedOutput = "Huch, was liegt denn hier rum?\n- Holz\n- Stein\n- Sand\nSchnell, sammel es ein!\n";
String expectedOutput = Colors.ANSI_BLUE+ "Huch, was liegt denn hier rum?\n" + Colors.ANSI_RESET+
"- Holz\n- Stein\n- Sand\n" +
Colors.ANSI_BLUE +"Schnell, sammel es ein!\n"+ Colors.ANSI_RESET;
assertEquals(expectedOutput, outputMessage.toString());
}
@Test
@ -90,7 +92,7 @@ public class LookaroundCommandTest {
StringBuilder outputMessage = new StringBuilder();
ArrayList<Item> foundItems = new ArrayList<Item>();
command.getItemsOutput(randomNumberItems, outputMessage, foundItems);
String expectedOutput = "Hier gibt es leider nichts für dich zum Einsammeln.\n";
String expectedOutput = Colors.ANSI_BLUE+ "Hier gibt es leider nichts für dich zum Einsammeln.\n"+ Colors.ANSI_RESET;
assertEquals(expectedOutput, outputMessage.toString());
}
@Test
@ -105,7 +107,7 @@ public class LookaroundCommandTest {
command.getMobsOutput( randomNumberItems,randomNumberMobs, outputMessage, foundMobs);
String expectedOutput = "Achtung, hier lauern Gefahren! Sei auf der Hut vor: \n- Big Foot\n- Yeti\n";
String expectedOutput = Colors.ANSI_RED+"Achtung, hier lauern Gefahren!"+Colors.ANSI_RESET +"Sei auf der Hut vor: \n- Big Foot\n- Yeti\n";
assertEquals(expectedOutput, outputMessage.toString());
}
@Test

Loading…
Cancel
Save