Browse Source

Merging

remotes/origin/develop
Tanja Herche 2 years ago
parent
commit
95cd3edf0a
  1. 27
      README.md
  2. 2
      pom.xml
  3. 3
      src/main/java/org/bitbiome/Boot.java
  4. 96
      src/main/java/org/bitbiome/classes/BlackJack.java
  5. 106
      src/main/java/org/bitbiome/classes/Colors.java
  6. 24
      src/main/java/org/bitbiome/classes/CreateLocations.java
  7. 38
      src/main/java/org/bitbiome/classes/InteractionLoop.java
  8. 35
      src/main/java/org/bitbiome/classes/JsonParser.java
  9. 274
      src/main/java/org/bitbiome/classes/Shop.java
  10. 11
      src/main/java/org/bitbiome/classes/TravelEngine.java
  11. 109
      src/main/java/org/bitbiome/commands/BlackJackCommand.java
  12. 4
      src/main/java/org/bitbiome/commands/CommandAPI.java
  13. 2
      src/main/java/org/bitbiome/commands/CommandListener.java
  14. 4
      src/main/java/org/bitbiome/commands/HelpCommand.java
  15. 7
      src/main/java/org/bitbiome/commands/QuitCommand.java
  16. 107
      src/main/java/org/bitbiome/commands/QuizCommand.java
  17. 85
      src/main/java/org/bitbiome/commands/ShopCommand.java
  18. 36
      src/main/java/org/bitbiome/entities/Item.java
  19. 8
      src/main/java/org/bitbiome/entities/Location.java
  20. 4
      src/main/java/org/bitbiome/entities/Mob.java
  21. 9
      src/main/java/org/bitbiome/entities/Player.java
  22. BIN
      src/main/resources/LogoBitbiome.png
  23. 146
      src/main/resources/gameconfig.json
  24. 31
      src/main/resources/playerconfig.json
  25. 405
      src/main/resources/quiz.json
  26. 44
      src/test/java/org/bitbiome/classes/BlackJackTest.java
  27. 23
      src/test/java/org/bitbiome/classes/ColorsTest.java
  28. 22
      src/test/java/org/bitbiome/commands/HelpCommandTest.java
  29. 4
      src/test/java/org/bitbiome/commands/QuitCommandTest.java
  30. 36
      src/test/java/org/bitbiome/commands/QuizCommandTest.java
  31. 105
      src/test/java/org/bitbiome/commands/ShopCommandTest.java
  32. 50
      src/test/java/org/bitbiome/entitiesTest/ItemTest.java
  33. 24
      src/test/java/org/bitbiome/entitiesTest/LocationTest.java
  34. 35
      src/test/java/org/bitbiome/entitiesTest/MobTest.java
  35. 43
      src/test/java/org/bitbiome/entitiesTest/PlayerTest.java

27
README.md

@ -0,0 +1,27 @@
![BitBiome Logo](src/main/resources/LogoBitbiome.png)
# BitBiome - TextAdventure
## What is the game about?
BitBiome is an exciting text adventure. Whether you want to travel through exciting biomes or measure with dangerous opponents. You can prove your knowledge in a quiz and buy new items in the shop as a reward.
BitBiome is a game for everyone who likes dangerous adventures.
## Commands:
- help
- exit / quit
- quiz
- quitquiz / canclequiz
- shop
- travel
- location
## Our developers:
- David Hermann
- Julia Kunze
- Frederike von Gruben
- Philipp Völler
- Tanja Herche
- Max Gerbeth
---
*Fulda University of Applied Sciences - Applied Computer Science (#AI1001 Papendieck)*

2
pom.xml

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20180130</version>
<version>20220320</version>
</dependency> </dependency>
</dependencies> </dependencies>

3
src/main/java/org/bitbiome/Boot.java

@ -26,8 +26,7 @@ public class Boot {
private Player getPlayerSave() { private Player getPlayerSave() {
String name; String name;
JsonParser jp = new JsonParser();
JSONObject playerconfig = jp.getJSONObject("playerconfig.json");
JSONObject playerconfig = JsonParser.getJSONObject("src/main/resources/playerconfig.json");
name = playerconfig.getString("name"); name = playerconfig.getString("name");
return new Player(name); return new Player(name);
} }

96
src/main/java/org/bitbiome/classes/BlackJack.java

@ -0,0 +1,96 @@
package org.bitbiome.classes;
import java.util.Random;
public class BlackJack {
public enum Entity {
PLAYER(1), BOT(2);
private int value;
private Entity(int value) {
this.value = value;
}
public int getValue() {
return value;
}
//Just for testing from some SO answers, but no use
public void setValue(int value) {
this.value = value;
}
public static Entity getEventStatusById(int id) {
Entity entity = null;
switch (id) {
case 1 -> entity = PLAYER;
case 2 -> entity = BOT;
default -> {
}
}
return entity;
}
}
private String playerName;
private int playerPoints;
private int botPoints;
private boolean playerIn;
private boolean botIn;
public BlackJack(String playerName) {
this.playerName = playerName;
this.playerPoints = 0;
this.botPoints = 0;
this.playerIn = true;
this.botIn = true;
}
public String getPlayerName(Entity entity) {
return entity == Entity.PLAYER ? playerName : "BitBiome";
}
public int getPoints(Entity entity) {
return entity == Entity.PLAYER ? playerPoints : botPoints;
}
public boolean isIn(Entity entity) {
return entity == Entity.PLAYER ? playerIn : botIn;
}
public Entity getEntity(int ID) {
return Entity.getEventStatusById(ID);
}
public void addPoints(Entity entity, int points) {
if (entity == Entity.BOT) botPoints += points;
if (entity == Entity.PLAYER) playerPoints += points;
}
public boolean botWantsToPlay() {
if (botIn) {
if (botPoints <= 10) {
return true;
} else if (botPoints <= 17) {
int r = new Random().nextInt(1, 9);
if (r <= 3) {
botIn = false;
return false;
} else {
return true;
}
} else {
botIn = false;
return false;
}
} else {
return false;
}
}
public void playerOut() {
this.playerIn = false;
}
}

106
src/main/java/org/bitbiome/classes/Colors.java

@ -2,55 +2,61 @@ package org.bitbiome.classes;
public class Colors { public class Colors {
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
public static final String ANSI_BRIGHT_BLACK = "\u001B[90m";
public static final String ANSI_BRIGHT_RED = "\u001B[91m";
public static final String ANSI_BRIGHT_GREEN = "\u001B[92m";
public static final String ANSI_BRIGHT_YELLOW = "\u001B[93m";
public static final String ANSI_BRIGHT_BLUE = "\u001B[94m";
public static final String ANSI_BRIGHT_PURPLE = "\u001B[95m";
public static final String ANSI_BRIGHT_CYAN = "\u001B[96m";
public static final String ANSI_BRIGHT_WHITE = "\u001B[97m";
public static final String[] FOREGROUNDS = {
ANSI_BLACK, ANSI_RED, ANSI_GREEN, ANSI_YELLOW,
ANSI_BLUE, ANSI_PURPLE, ANSI_CYAN, ANSI_WHITE,
ANSI_BRIGHT_BLACK, ANSI_BRIGHT_RED, ANSI_BRIGHT_GREEN, ANSI_BRIGHT_YELLOW,
ANSI_BRIGHT_BLUE, ANSI_BRIGHT_PURPLE, ANSI_BRIGHT_CYAN, ANSI_BRIGHT_WHITE
};
public static final String ANSI_BG_BLACK = "\u001B[40m";
public static final String ANSI_BG_RED = "\u001B[41m";
public static final String ANSI_BG_GREEN = "\u001B[42m";
public static final String ANSI_BG_YELLOW = "\u001B[43m";
public static final String ANSI_BG_BLUE = "\u001B[44m";
public static final String ANSI_BG_PURPLE = "\u001B[45m";
public static final String ANSI_BG_CYAN = "\u001B[46m";
public static final String ANSI_BG_WHITE = "\u001B[47m";
public static final String ANSI_BRIGHT_BG_BLACK = "\u001B[100m";
public static final String ANSI_BRIGHT_BG_RED = "\u001B[101m";
public static final String ANSI_BRIGHT_BG_GREEN = "\u001B[102m";
public static final String ANSI_BRIGHT_BG_YELLOW = "\u001B[103m";
public static final String ANSI_BRIGHT_BG_BLUE = "\u001B[104m";
public static final String ANSI_BRIGHT_BG_PURPLE = "\u001B[105m";
public static final String ANSI_BRIGHT_BG_CYAN = "\u001B[106m";
public static final String ANSI_BRIGHT_BG_WHITE = "\u001B[107m";
public static final String[] BACKGROUNDS = {
ANSI_BG_BLACK, ANSI_BG_RED, ANSI_BG_GREEN, ANSI_BG_YELLOW,
ANSI_BG_BLUE, ANSI_BG_PURPLE, ANSI_BG_CYAN, ANSI_BG_WHITE,
ANSI_BRIGHT_BG_BLACK, ANSI_BRIGHT_BG_RED, ANSI_BRIGHT_BG_GREEN, ANSI_BRIGHT_BG_YELLOW,
ANSI_BRIGHT_BG_BLUE, ANSI_BRIGHT_BG_PURPLE, ANSI_BRIGHT_BG_CYAN, ANSI_BRIGHT_BG_WHITE };
/*
* This class has only public static mehtods
* Just add a String to your String and finalize it with the ANSI_RESET String
* The Color Codes with BG in the variable name are for the background colors
*/
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
public static final String ANSI_BRIGHT_BLACK = "\u001B[90m";
public static final String ANSI_BRIGHT_RED = "\u001B[91m";
public static final String ANSI_BRIGHT_GREEN = "\u001B[92m";
public static final String ANSI_BRIGHT_YELLOW = "\u001B[93m";
public static final String ANSI_BRIGHT_BLUE = "\u001B[94m";
public static final String ANSI_BRIGHT_PURPLE = "\u001B[95m";
public static final String ANSI_BRIGHT_CYAN = "\u001B[96m";
public static final String ANSI_BRIGHT_WHITE = "\u001B[97m";
public static final String[] FOREGROUNDS = {
ANSI_BLACK, ANSI_RED, ANSI_GREEN, ANSI_YELLOW,
ANSI_BLUE, ANSI_PURPLE, ANSI_CYAN, ANSI_WHITE,
ANSI_BRIGHT_BLACK, ANSI_BRIGHT_RED, ANSI_BRIGHT_GREEN, ANSI_BRIGHT_YELLOW,
ANSI_BRIGHT_BLUE, ANSI_BRIGHT_PURPLE, ANSI_BRIGHT_CYAN, ANSI_BRIGHT_WHITE
};
public static final String ANSI_BG_BLACK = "\u001B[40m";
public static final String ANSI_BG_RED = "\u001B[41m";
public static final String ANSI_BG_GREEN = "\u001B[42m";
public static final String ANSI_BG_YELLOW = "\u001B[43m";
public static final String ANSI_BG_BLUE = "\u001B[44m";
public static final String ANSI_BG_PURPLE = "\u001B[45m";
public static final String ANSI_BG_CYAN = "\u001B[46m";
public static final String ANSI_BG_WHITE = "\u001B[47m";
public static final String ANSI_BRIGHT_BG_BLACK = "\u001B[100m";
public static final String ANSI_BRIGHT_BG_RED = "\u001B[101m";
public static final String ANSI_BRIGHT_BG_GREEN = "\u001B[102m";
public static final String ANSI_BRIGHT_BG_YELLOW = "\u001B[103m";
public static final String ANSI_BRIGHT_BG_BLUE = "\u001B[104m";
public static final String ANSI_BRIGHT_BG_PURPLE = "\u001B[105m";
public static final String ANSI_BRIGHT_BG_CYAN = "\u001B[106m";
public static final String ANSI_BRIGHT_BG_WHITE = "\u001B[107m";
public static final String[] BACKGROUNDS = {
ANSI_BG_BLACK, ANSI_BG_RED, ANSI_BG_GREEN, ANSI_BG_YELLOW,
ANSI_BG_BLUE, ANSI_BG_PURPLE, ANSI_BG_CYAN, ANSI_BG_WHITE,
ANSI_BRIGHT_BG_BLACK, ANSI_BRIGHT_BG_RED, ANSI_BRIGHT_BG_GREEN, ANSI_BRIGHT_BG_YELLOW,
ANSI_BRIGHT_BG_BLUE, ANSI_BRIGHT_BG_PURPLE, ANSI_BRIGHT_BG_CYAN, ANSI_BRIGHT_BG_WHITE };
} }

24
src/main/java/org/bitbiome/classes/CreateLocations.java

@ -1,24 +0,0 @@
package org.bitbiome.classes;
import org.bitbiome.entities.Item;
import org.bitbiome.entities.Location;
import org.bitbiome.entities.Mob;
import java.util.ArrayList;
public class CreateLocations {
public static Location createForest() {
ArrayList<Item> items = new ArrayList<>();
ArrayList<Mob> mobs = new ArrayList<>();
String name = "Wald";
return new Location(name, mobs, items);
}
public static Location createBeach() {
ArrayList<Item> items = new ArrayList<>();
ArrayList<Mob> mobs = new ArrayList<>();
String name = "Strand";
return new Location(name, mobs, items);
}
}

38
src/main/java/org/bitbiome/classes/InteractionLoop.java

@ -4,31 +4,45 @@ import org.bitbiome.Boot;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Scanner; import java.util.Scanner;
public class InteractionLoop { public class InteractionLoop {
Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
public void run(TravelEngine travelEngine) { public void run(TravelEngine travelEngine) {
boolean isRunning = true; boolean isRunning = true;
if (travelEngine.getPlayer().getName().equals("null")) {
System.out.println(Colors.ANSI_BLUE + "Oh, ein Fremder!\nBist du bereit für dein womöglich größtes Abenteuer?\nDann sag mir doch zunächst wie du heißt: " + Colors.ANSI_RESET);
String name = input.nextLine();
JsonParser jp = new JsonParser();
JSONObject playerconf = jp.getJSONObject("playerconfig.json");
playerconf.put("name", name);
travelEngine.getPlayer().setName(name);
jp.writeObject("playerconfig.json", playerconf);
if (playerIsNew(travelEngine.getPlayer().getName())) {
newPlayerWelcome(travelEngine);
} }
System.out.println(Colors.ANSI_BG_CYAN + Colors.ANSI_BLACK + "Willkommen zu BitBiome " + travelEngine.getPlayer().getName() + "!" + Colors.ANSI_RESET + "\n\n");
print(Colors.ANSI_BG_CYAN + Colors.ANSI_BLACK + "Willkommen zu BitBiome " + travelEngine.getPlayer().getName()
+ "!" + Colors.ANSI_RESET + "\n\n");
while (isRunning) { while (isRunning) {
String line = input.nextLine().toLowerCase(); String line = input.nextLine().toLowerCase();
if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line, travelEngine)) {
System.out.println(Colors.ANSI_RED + "Unbekannter Befehl - Siehe " + Colors.ANSI_PURPLE + "help\n" + Colors.ANSI_RESET);
if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line,
travelEngine)) {
print(Colors.ANSI_RED + "Unbekannter Befehl - Siehe " + Colors.ANSI_PURPLE + "help\n"
+ Colors.ANSI_RESET);
} }
} }
} }
public boolean print(String message) {
System.out.println(message);
return true;
}
public boolean playerIsNew(String name) {
return name.equalsIgnoreCase("null");
}
public void newPlayerWelcome(TravelEngine travelEngine) {
print(Colors.ANSI_BLUE
+ "Oh, ein Fremder!\nBist du bereit für dein womöglich größtes Abenteuer?\nDann sag mir doch zunächst wie du heißt: "
+ Colors.ANSI_RESET);
String name = input.nextLine();
JSONObject playerconf = JsonParser.getJSONObject("src/main/resources/playerconfig.json");
playerconf.put("name", name);
travelEngine.getPlayer().setName(name);
JsonParser.writeObject("src/main/resources/playerconfig.json", playerconf);
}
} }

35
src/main/java/org/bitbiome/classes/JsonParser.java

@ -1,13 +1,10 @@
package org.bitbiome.classes; package org.bitbiome.classes;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.FileReader;
public class JsonParser { public class JsonParser {
@ -26,20 +23,30 @@ public class JsonParser {
https://github.com/stleary/JSON-java https://github.com/stleary/JSON-java
*/ */
public JSONObject getJSONObject(String fileName) {
String resourceName = "./../../../" + fileName;
InputStream is = JsonParser.class.getResourceAsStream(resourceName);
if (is == null) {
throw new NullPointerException("Cannot find resource file " + resourceName);
public static JSONObject getJSONObject(String filePath) {
StringBuilder sb = null;
try {
FileReader reader = new FileReader(filePath);
char[] buffer = new char[1024];
int length;
sb = new StringBuilder();
while ((length = reader.read(buffer)) != -1) {
sb.append(buffer, 0, length);
}
reader.close();
} catch (IOException e) {
System.out.println(e);
} }
JSONTokener tokener = new JSONTokener(is);
return new JSONObject(tokener);
return new JSONObject(sb.toString());
} }
public void writeObject(String fileName, JSONObject object) {
public static void writeObject(String fileName, JSONObject object) {
String resourceName = fileName;
String resourceName = System.getProperty("user.dir") + "/src/main/resources/" + fileName;
try { try {
FileWriter fw = new FileWriter(resourceName, false); FileWriter fw = new FileWriter(resourceName, false);
fw.write(object.toString(1)); fw.write(object.toString(1));
@ -47,7 +54,5 @@ public class JsonParser {
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
} }

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

@ -0,0 +1,274 @@
package org.bitbiome.classes;
import org.bitbiome.commands.BlackJackCommand;
import org.bitbiome.commands.QuizCommand;
import org.bitbiome.entities.Item;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
public class Shop {
public ArrayList<Item> allItems;
public ArrayList<Item> currentShopItems;
public QuizCommand quizCommand = new QuizCommand();
public BlackJackCommand blackJackCommand = new BlackJackCommand();
public Scanner scanner;
public boolean isRunning;
public String message;
public TravelEngine travelEngine;
public Shop(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngin) {
this.scanner = scanner;
this.message = message;
this.isRunning = isRunning;
this.travelEngine = travelEngin;
try {
allItems = loadAllItems();
currentShopItems = loadPartofItems(allItems, 3);
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean buy(String itemName, int amount) {
// Create File Objects
currentShopItems = loadCurrentShopItems();
File filePlayerConfig = new File("src/main/resources/playerconfig.json");
File fileGameConfig = new File("src/main/resources/gameconfig.json");
File fileItem = new File("src/main/resources/items.json");
try {
// Create JSONObjects
String content1 = new String(Files.readAllBytes(Paths.get(filePlayerConfig.toURI())), "UTF-8");
JSONObject playerConfig = new JSONObject(content1);
String content2 = new String(Files.readAllBytes(Paths.get(fileGameConfig.toURI())), "UTF-8");
JSONObject gameConfig = new JSONObject(content2);
String content3 = new String(Files.readAllBytes(Paths.get(fileItem.toURI())), "UTF-8");
JSONArray itemJSON = new JSONArray(content3);
// Test if item still available in the shop
int itemIndex = -1;
for (int i = 0; i < currentShopItems.size(); i++) {
if (currentShopItems.get(i).getName().equals(itemName)) {
itemIndex = i;
}
}
if (itemIndex == -1) {
System.out.println(
Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Dieses Item gibt es nicht!" + Colors.ANSI_RESET);
return false;
}
if (!(currentShopItems.get(itemIndex).getAmount() > 0)) {
System.out.println(
Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Es gibt zu wenige Items!" + Colors.ANSI_RESET);
return false;
}
// Test if the player has enough gold
int costs = currentShopItems.get(itemIndex).getGold() * amount;
int gold = (int) playerConfig.get("gold");
if (!(gold >= costs)) {
System.out
.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Du hast zu wenig Gold!" + Colors.ANSI_RESET);
return false;
}
// Player gold subtract
playerConfig.put("gold", subtractGold(gold, costs));
// Gameconfig amount reduese
JSONArray jsonArray2 = gameConfig.getJSONArray("shopitems");
int intNewAmount;
for (int i = 0; i < jsonArray2.length(); i++) {
JSONObject tempJSON = jsonArray2.getJSONObject(i);
if (tempJSON.getString("name").equals(itemName)) {
intNewAmount = tempJSON.getInt("amount") - amount;
jsonArray2.remove(i);
tempJSON.put("amount", intNewAmount);
jsonArray2.put(tempJSON);
gameConfig.put("shopitems", jsonArray2);
JsonParser.writeObject("src/main/resources/gameconfig.json", gameConfig);
currentShopItems = loadCurrentShopItems();
break;
}
}
// Give Player the Item
JSONArray jsonArray = playerConfig.getJSONArray("inventory");
int newAmount;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject tempJSON = jsonArray.getJSONObject(i);
if (tempJSON.getString("name").equals(itemName)) {
newAmount = tempJSON.getInt("amount") + amount;
jsonArray.remove(i);
tempJSON.put("amount", newAmount);
jsonArray.put(tempJSON);
playerConfig.put("inventory", jsonArray);
JsonParser.writeObject("src/main/resources/playerconfig.json", playerConfig);
return true;
}
}
// Item do not exist in the playerinventory
int durability = 0;
for (int i = 0; i < itemJSON.length(); i++) {
JSONObject tempJSON = itemJSON.getJSONObject(i);
if (tempJSON.getString("name").equals(itemName)) {
durability = (int) tempJSON.get("durability");
}
}
JSONObject inventory = new JSONObject();
inventory.put("name", itemName);
inventory.put("amount", 1);
inventory.put("durability", durability);
jsonArray.put(inventory);
playerConfig.put("inventory", jsonArray);
JsonParser.writeObject("src/main/resources/playerconfig.json", playerConfig);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
private ArrayList<Item> loadAllItems() {
ArrayList<Item> arrayList = new ArrayList<>();
JSONArray itemJSON = returnJSONArrayOfAllItems();
arrayList = addToList(itemJSON, arrayList, "amountShop");
return arrayList;
}
public JSONArray returnJSONArrayOfAllItems() {
File file = new File("src/main/resources/items.json");
JSONArray itemJSON = null;
try {
String content3 = new String(Files.readAllBytes(Paths.get(file.toURI())), StandardCharsets.UTF_8);
itemJSON = new JSONArray(content3);
} catch (Exception e) {
e.printStackTrace();
}
return itemJSON;
}
public ArrayList<Item> loadCurrentShopItems() {
ArrayList<Item> arrayList = new ArrayList<>();
JSONObject jsonObject = JsonParser.getJSONObject("src/main/resources/gameconfig.json");
JSONArray jsonArray = jsonObject.getJSONArray("shopitems");
return addToList(jsonArray, arrayList, "amount");
}
public JSONObject getItemByName(String itemName, JSONArray itemArray) {
for (int i = 0; i < itemArray.length(); i++) {
if (itemArray.getJSONObject(i).getString("name").equals(itemName)) {
return itemArray.getJSONObject(i);
}
}
return null;
}
public ArrayList<Item> addToList(JSONArray itemJSON, ArrayList<Item> arrayList, String key) {
JSONArray allItems = returnJSONArrayOfAllItems();
for (int i = 0; i < itemJSON.length(); i++) {
JSONObject tempJSON = itemJSON.getJSONObject(i);
String damage;
boolean doesDmg;
if (key.equals("amount")) {
damage = getItemByName(tempJSON.getString("name"), allItems).getString("damage");
} else {
damage = tempJSON.getString("damage");
}
doesDmg = damage.equals("0");
arrayList.add(new Item(tempJSON.getString("name"), doesDmg, damage, tempJSON.getInt(key),
tempJSON.getInt("gold")));
}
return arrayList;
}
private ArrayList<Item> loadPartofItems(ArrayList<Item> alleItems, int itemCount) {
ArrayList<Item> arrayList = new ArrayList<>();
try {
File fileGameConfig = new File("src/main/resources/gameconfig.json");
String content2 = new String(Files.readAllBytes(Paths.get(fileGameConfig.toURI())), "UTF-8");
JSONObject gameConfig = new JSONObject(content2);
//JSONArray jsonArray = gameConfig.getJSONArray("shopitems");
HashSet<Integer> hashSet = new HashSet<>();
JSONArray shopitems = new JSONArray();
Random random = new Random();
while (hashSet.size() < itemCount) {
int rand = random.nextInt(alleItems.size());
if (!hashSet.contains(rand)) {
hashSet.add(rand);
arrayList.add(alleItems.get(rand));
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", alleItems.get(rand).getName());
jsonObject.put("amount", alleItems.get(rand).getAmount());
jsonObject.put("gold", alleItems.get(rand).getGold());
shopitems.put(jsonObject);
}
}
// write in gameconfig.json
gameConfig.remove("shopitems");
gameConfig.put("shopitems", shopitems);
JsonParser.writeObject("src/main/resources/gameconfig.json", gameConfig);
} catch (Exception e) {
e.printStackTrace();
}
return arrayList;
}
public void itemRotation() {
try {
currentShopItems = loadPartofItems(allItems, 3);
} catch (Exception e) {
e.printStackTrace();
}
}
public void printCurrentShopItems() {
printArrayList(currentShopItems);
}
public void quiz() {
quizCommand.performCommand(scanner, isRunning, message, travelEngine);
}
public void blackJack() {
System.out.println("");
blackJackCommand.performCommand(scanner, isRunning, message, travelEngine);
System.out.println("");
}
private void printArrayList(ArrayList<Item> arrayList) {
System.out.println("");
for (int i = 0; i < arrayList.size(); i++) {
if (arrayList.get(i).getAmount() != 0) {
System.out.println(arrayList.get(i).getName() + " | Anzahl: " + arrayList.get(i).getAmount()
+ " | Kosten: " + arrayList.get(i).getGold());
}
}
System.out.println("");
}
public int subtractGold(int gold, int cost) {
return gold - cost;
}
}

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

@ -14,21 +14,19 @@ import java.util.ArrayList;
public class TravelEngine { public class TravelEngine {
private JSONArray locations; private JSONArray locations;
private JsonParser jp;
private Player player; private Player player;
public TravelEngine(Player player) { public TravelEngine(Player player) {
jp = new JsonParser();
locations = jp.getJSONObject("gameconfig.json").getJSONArray("locations");
locations = JsonParser.getJSONObject("src/main/resources/gameconfig.json").getJSONArray("locations");
this.player = player; this.player = player;
} }
public void travelTo(Location location) { public void travelTo(Location location) {
player.setLocation(location); player.setLocation(location);
JSONObject jObj = jp.getJSONObject("playerconfig.json");
JSONObject jObj = JsonParser.getJSONObject("src/main/resources/playerconfig.json");
jObj.put("currentLocation", location.getName()); jObj.put("currentLocation", location.getName());
jp.writeObject("playerconfig.json", jObj);
JsonParser.writeObject("src/main/resources/playerconfig.json", jObj);
} }
public Player getPlayer() { public Player getPlayer() {
@ -97,8 +95,7 @@ public class TravelEngine {
} }
public Location getLocationByName(String name) { public Location getLocationByName(String name) {
JsonParser jp = new JsonParser();
JSONObject gameconfig = jp.getJSONObject("gameconfig.json");
JSONObject gameconfig = JsonParser.getJSONObject("src/main/resources/gameconfig.json");
JSONArray locations = gameconfig.getJSONArray("locations"); JSONArray locations = gameconfig.getJSONArray("locations");
JSONObject location = null; JSONObject location = null;
if (locationExists(name)) { if (locationExists(name)) {

109
src/main/java/org/bitbiome/commands/BlackJackCommand.java

@ -0,0 +1,109 @@
package org.bitbiome.commands;
import org.bitbiome.classes.BlackJack;
import org.bitbiome.classes.TravelEngine;
import java.util.Random;
import java.util.Scanner;
public class BlackJackCommand implements CommandAPI {
private boolean over;
@Override
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
System.out.println("Du hast das Spiel BlackJack gestartet. Die Spielregeln lauten wie folgt: Du und dein Gegner bekommen jede Runde Zahlen von 4 - 11. \nDerjenige, der zuerst 21 Punkte hat gewinnt. Derjenige, der über 21 Punkte hat verliert. Möchte keiner mehr Karten ziehen, gewinnt der mit dem höchsten Blatt!\nViel Spaß!");
over = false;
spielen();
}
Scanner sc;
public void spielen() {
BlackJack bj = new BlackJack("Dave");
sc = new Scanner(System.in);
BlackJack.Entity player = bj.getEntity(1);
while (!over) {
int r = new Random().nextInt(4, 11);
bj.addPoints(player, r);
System.out.println(bj.getPlayerName(player) + " hat " + r + " bekommen. Er hat insgesamt " + bj.getPoints(player) + ".");
if (bj.getPoints(player) >= 21) {
over21(player, bj);
has21(player, bj);
over = true;
break;
}
System.out.print("Weiter?");
if (player == BlackJack.Entity.BOT) {
if (bj.botWantsToPlay()) {
System.out.println("Na klar!");
} else {
System.out.println("Nope, ich bin fertig.");
}
} else {
String eingabe = sc.nextLine();
if (!eingabe.toLowerCase().startsWith("j")) {
bj.playerOut();
}
}
player = switchPlayer(player, bj);
}
}
public void over21(BlackJack.Entity player, BlackJack bj) {
if (bj.getPoints(player) > 21) {
over = true;
System.out.println(bj.getPlayerName(player) + " hat über 21 Punkte und damit verloren.");
}
}
public void has21(BlackJack.Entity player, BlackJack bj) {
if (bj.getPoints(player) == 21) {
System.out.println(bj.getPlayerName(player) + " hat gewonnen! Du hast 21 Punkte!");
over = true;
}
}
public BlackJack.Entity switchPlayer(BlackJack.Entity player, BlackJack bj) {
BlackJack.Entity BOT = BlackJack.Entity.BOT;
BlackJack.Entity PLAYER = BlackJack.Entity.PLAYER;
if (bj.isIn(BOT) || bj.isIn(PLAYER)) {
if (player == PLAYER) {
if (bj.isIn(BOT)) {
return BOT;
}
return PLAYER;
} else {
if (bj.isIn(PLAYER)) {
return PLAYER;
}
return BOT;
}
} else {
over = true;
getWinner(bj);
return null;
}
}
public void getWinner(BlackJack bj) {
BlackJack.Entity entity;
if (bj.getPoints(BlackJack.Entity.BOT) < bj.getPoints(BlackJack.Entity.PLAYER)) {
entity = BlackJack.Entity.PLAYER;
System.out.println(bj.getPlayerName(entity) + " hat gewonnen, da er mehr Punkte hat!");
} else if (bj.getPoints(BlackJack.Entity.BOT) == bj.getPoints(BlackJack.Entity.PLAYER)){
System.out.println("Es ist Gleichstand!");
} else {
entity = BlackJack.Entity.BOT;
System.out.println(bj.getPlayerName(entity) + " hat gewonnen, da er mehr Punkte hat!");
}
}
}

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

@ -5,6 +5,10 @@ import org.bitbiome.classes.TravelEngine;
import java.util.Scanner; import java.util.Scanner;
public interface CommandAPI { public interface CommandAPI {
// This is the command interface. Every command implements it's run method from here
// This is the API between the commands and the interaction loop/game
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine); public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine);
} }

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

@ -20,6 +20,8 @@ public class CommandListener {
commands.put("travel", new TravelCommand()); commands.put("travel", new TravelCommand());
commands.put("map", new MapCommand()); commands.put("map", new MapCommand());
commands.put("gold", new GoldCommand()); commands.put("gold", new GoldCommand());
commands.put("shop", new ShopCommand());
} }
public HashMap<String, CommandAPI> returnCommands() { public HashMap<String, CommandAPI> returnCommands() {

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

@ -27,6 +27,10 @@ public class HelpCommand implements CommandAPI {
.append("|--------------|-----------------------------|\n") .append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " travel" + Colors.ANSI_RESET + " | Startet das Reise System |\n") .append("|" + Colors.ANSI_GREEN + " travel" + Colors.ANSI_RESET + " | Startet das Reise System |\n")
.append("|--------------|-----------------------------|\n") .append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " quiz" + Colors.ANSI_RESET + " | Startet das quiz im shop |\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " blackjack" + Colors.ANSI_RESET + " | Startet blackjack im shop |\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " location" + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") .append("|" + Colors.ANSI_GREEN + " location" + Colors.ANSI_RESET + " | Gibt deine Location aus |\n")
.append("|--------------|-----------------------------|\n") .append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " map" + Colors.ANSI_RESET + " | Zeigt dir deinen Karte |\n") .append("|" + Colors.ANSI_GREEN + " map" + Colors.ANSI_RESET + " | Zeigt dir deinen Karte |\n")

7
src/main/java/org/bitbiome/commands/QuitCommand.java

@ -1,11 +1,16 @@
package org.bitbiome.commands; package org.bitbiome.commands;
import org.bitbiome.classes.Colors;
import org.bitbiome.classes.TravelEngine; import org.bitbiome.classes.TravelEngine;
import java.util.Scanner; import java.util.Scanner;
public class QuitCommand implements CommandAPI { public class QuitCommand implements CommandAPI {
// This command is used to end the game via command
// When the player quits the game, the game is stopped through System.exit(0)
// That means it is exited with no error status
@Override @Override
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
System.out.println(getQuitMessage()); System.out.println(getQuitMessage());
@ -13,6 +18,6 @@ public class QuitCommand implements CommandAPI {
} }
public static String getQuitMessage() { public static String getQuitMessage() {
return "You quitted!";
return Colors.ANSI_BG_GREEN + "Du hast das Spiel beendet! Bis bald." + Colors.ANSI_RESET;
} }
} }

107
src/main/java/org/bitbiome/commands/QuizCommand.java

@ -0,0 +1,107 @@
package org.bitbiome.commands;
import org.bitbiome.classes.Colors;
import org.bitbiome.classes.JsonParser;
import org.json.JSONArray;
import org.json.JSONObject;
import org.bitbiome.classes.TravelEngine;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;
public class QuizCommand {
private Scanner quizScanner;
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
quizScanner = new Scanner(System.in);
String path = "src/main/resources/quiz.json";
JSONObject quiz = JsonParser.getJSONObject(path);
long diffTime = canPlayAgain(quiz.getLong("lastPlayed"));
if (diffTime > 0) {
print(Colors.ANSI_BG_RED + "Du darfst erst in " + diffTime / 1000 / 60 + " Minuten spielen." + Colors.ANSI_RESET + "\n");
return;
}
JSONArray fragen = quiz.getJSONArray("Quiz");
JSONObject frage = fragen.getJSONObject(random(fragen.length()));
JSONArray antworten = frage.getJSONArray("antworten");
String korrekteAntwort = frage.getString("korrekteAntwort");
print(starterMessage());
print(generateQuestion(frage, antworten));
int eingabe = quizScanner.nextInt();
if (answerIsCorrect(eingabe, korrekteAntwort, antworten)) {
int neuerStand = addGold();
print(Colors.ANSI_BG_GREEN + "Richtig! Du hast 5 Münzen verdient." + Colors.ANSI_RESET + Colors.ANSI_CYAN + "\nDein Münzstand beträgt: " + Colors.ANSI_RESET + Colors.ANSI_BLUE + neuerStand + Colors.ANSI_RESET);
} else {
print(Colors.ANSI_BG_RED + "Leider falsch... Richtig ist: " + korrekteAntwort + Colors.ANSI_RESET + "\n");
}
print(endMessage());
Date d = new Date();
long lastPlayed = d.getTime();
quiz.put("lastPlayed", lastPlayed);
JsonParser.writeObject(path, quiz);
}
public static boolean answerIsCorrect(int picked, String answer, JSONArray answers) {
return answers.getString(picked - 1).equalsIgnoreCase(answer);
}
public static String print(String message) {
System.out.println(message);
return message;
}
public static int random(int length) {
return new Random().nextInt(length);
}
public static String generateQuestion(JSONObject frage, JSONArray answers) {
StringBuilder sb = new StringBuilder();
sb.append(frage.getString("frage")).append("\n");
for (int i = 0; i < answers.length(); i++) {
sb.append(i+1).append(". ").append(answers.getString(i)).append("\n");
}
return sb.toString();
}
public static int addGold() {
String playerpath = "src/main/resources/playerconfig.json";
JSONObject playerconfig = JsonParser.getJSONObject(playerpath);
int gold = playerconfig.getInt("gold");
gold = gold + 5;
playerconfig.put("gold", gold);
JsonParser.writeObject(playerpath, playerconfig);
return gold;
}
public static long canPlayAgain(long lastPlayedTime) {
long currentTime = System.currentTimeMillis();
long minTime = lastPlayedTime + (60 * 5 * 1000);
return minTime - currentTime;
}
public static String starterMessage(){
return Colors.ANSI_CYAN + "Du hast das Quiz gestartet! Hinweis: Wähle deine Antwort, indem du die Zahl (1-4) eingibst. Ist deine Lösung richtig, erhälst du 5 Münzen. Viel Erfolg!" + Colors.ANSI_RESET + " \n";
}
public static String endMessage(){
return Colors.ANSI_CYAN + "Das Quiz ist vorbei!" + Colors.ANSI_RESET;
}
}

85
src/main/java/org/bitbiome/commands/ShopCommand.java

@ -0,0 +1,85 @@
package org.bitbiome.commands;
import org.bitbiome.classes.BlackJack;
import org.bitbiome.classes.Colors;
import org.bitbiome.classes.Shop;
import org.bitbiome.classes.TravelEngine;
import org.bitbiome.entities.Item;
import java.util.ArrayList;
import java.util.Scanner;
public class ShopCommand implements CommandAPI{
Shop shop;
BlackJack blackJack;
public ShopCommand(){
}
@Override
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
shop = new Shop(scanner, isRunning, message, travelEngine);
blackJack = new BlackJack(travelEngine.getPlayer().getName());
System.out.println(Colors.ANSI_BG_YELLOW + Colors.ANSI_BLACK + "Willkommen im Shop!" + Colors.ANSI_RESET);
ArrayList<Item> currentItems = shop.loadCurrentShopItems();
//whileloop for userinputs in the shop
while (true){
System.out.println("Was willst Du hier im Shop?");
System.out.println(Colors.ANSI_CYAN + "Etwas kaufen: 1");
System.out.println("Das Quiz spielen: 2");
System.out.println("Blackjack spielen: 3");
System.out.println("Den Shop verlassen: 4" + Colors.ANSI_RESET);
String input = scanner.nextLine();
if(validInput(input)){
if(input.equals("1")){
System.out.println("Folgende Items sind im Shop: ");
for(int i = 0; i < currentItems.size(); i++){
System.out.println((i + 1) + ". " + currentItems.get(i).getName() + " | Anzahl: " + currentItems.get(i).getAmount() + " | Gold: " + currentItems.get(i).getGold());
}
System.out.println("0 Eingeben um den Shop zu verlassen.");
System.out.println("");
System.out.print("Welches Item moechtest du kaufen? ");
String itemNumber = scanner.nextLine();
if(!itemNumber.equals("0")) {
System.out.print("Anzahl eingeben: ");
String amount = scanner.nextLine();
try {
if ((Integer.parseInt(amount) <= currentItems.get(Integer.parseInt(itemNumber) - 1).getAmount()) && ((Integer.parseInt(amount) - 1) > -1)) {
boolean bool = shop.buy(currentItems.get(Integer.parseInt(itemNumber) - 1).getName(), Integer.parseInt(amount));
currentItems = shop.loadCurrentShopItems();
if (bool) {
System.out.println("");
System.out.println(Colors.ANSI_BG_GREEN + Colors.ANSI_BLACK + "Vielen Dank für Ihren Einkauf!" + Colors.ANSI_RESET);
System.out.println("");
} else {
System.out.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Fehler!" + Colors.ANSI_RESET);
}
} else {
System.out.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Fehler!" + Colors.ANSI_RESET);
}
}catch (Exception e){
System.out.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Fehler!" + Colors.ANSI_RESET);
}
}
} else if(input.equals("2")){
shop.quiz();
} else if(input.equals("3")){
shop.blackJack();
}else if(input.equals("4")){
System.out.println(Colors.ANSI_BG_YELLOW + "Der Shop wurde verlassen!" + Colors.ANSI_RESET);
break;
}
}else {
System.out.println("Unbekannte Eingabe!");
}
}
}
public static boolean validInput(String input){
return (input.equals("1") || input.equals("2") || input.equals("3") || input.equals("4"));
}
}

36
src/main/java/org/bitbiome/entities/Item.java

@ -2,25 +2,49 @@ package org.bitbiome.entities;
public class Item { public class Item {
public String name;
public boolean doesDamage;
public float damage;
private String name;
private boolean doesDamage;
private String damage;
private int amount;
private int gold;
public Item(String name, boolean doesDamage, float damage) {
public Item(String name, boolean doesDamage, String damage, int amount, int gold) {
this.name = name; this.name = name;
this.doesDamage = doesDamage; this.doesDamage = doesDamage;
this.damage = damage; this.damage = damage;
this.amount = amount;
this.gold = gold;
}
public Item() {
} }
public String getName() { public String getName() {
return name; return name;
} }
public float getDamage() {
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public String getDamage() {
return damage; return damage;
} }
public int getGold() {
return gold;
}
public void setGold(int gold){
this.gold = gold;
}
public boolean doesDamage() { public boolean doesDamage() {
return doesDamage; return doesDamage;
} }
@ -29,7 +53,7 @@ public class Item {
this.name = name; this.name = name;
} }
public void setDamage(float damage) {
public void setDamage(String damage) {
this.damage = damage; this.damage = damage;
} }

8
src/main/java/org/bitbiome/entities/Location.java

@ -15,6 +15,10 @@ public class Location {
this.itemList = itemList; this.itemList = itemList;
} }
public Location() {
}
public String getName() { public String getName() {
return name; return name;
@ -28,6 +32,10 @@ public class Location {
return itemList; return itemList;
} }
public void setName(String name) {
this.name = name;
}
} }

4
src/main/java/org/bitbiome/entities/Mob.java

@ -15,6 +15,10 @@ public class Mob {
this.damage = damage; this.damage = damage;
} }
public Mob() {
}
public String getName() { public String getName() {
return name; return name;
} }

9
src/main/java/org/bitbiome/entities/Player.java

@ -16,16 +16,19 @@ public class Player {
private ArrayList<Item> inventory; private ArrayList<Item> inventory;
private JsonParser jp;
public Player(String name) { public Player(String name) {
jp = new JsonParser();
this.name = name; this.name = name;
hp = 100.0F; hp = 100.0F;
location = new Location(jp.getJSONObject("playerconfig.json").getString("currentLocation"), new ArrayList<>(), new ArrayList<>());
location = new Location(JsonParser.getJSONObject("src/main/resources/playerconfig.json").getString("currentLocation"), new ArrayList<>(), new ArrayList<>());
inventory = new ArrayList<>(); inventory = new ArrayList<>();
} }
public Player() {
}
public String getName() { public String getName() {
return name; return name;
} }

BIN
src/main/resources/LogoBitbiome.png

After

Width: 1796  |  Height: 791  |  Size: 98 KiB

146
src/main/resources/gameconfig.json

@ -1,81 +1,69 @@
{ {
"shopitems": [
{
"name": "Holz",
"amount": 10,
"gold": 10
},
{
"name": "Heiliges Schwert der Engel",
"amount": 1,
"gold": 1000
},
{
"name": "Stein",
"amount": 5,
"gold": 100
}
],
"locations": [
{
"name": "Wald",
"items": [
"Holz",
"Stein"
],
"mobs": [
"Big Foot"
]
},
{
"name": "Strand",
"items": [
"Sand",
"Treibholz"
],
"mobs": [
"Riesenkrabbe"
]
},
{
"name": "Winterland",
"items": [
"Eiszapfen",
"Schnee"
],
"mobs": [
"Yeti"
]
},
{
"name": "Berge",
"items": [
"Quellwasser",
"Feuerstein"
],
"mobs": [
"Loewe"
]
},
{
"name": "Gruenland",
"items": [
"Lehm",
"Giftblume"
],
"mobs": [
"Drache"
]
},
{
"name": "Wueste",
"items": [
"Sand",
"Kaktus"
],
"mobs": [
"Mumie"
]
}
]
"shopitems": [
{
"gold": 1000,
"amount": 1,
"name": "Heiliges Schwert der Engel"
},
{
"gold": 2,
"amount": 450,
"name": "Knochen"
},
{
"gold": 1,
"amount": 100,
"name": "Schnee"
}
],
"locations": [
{
"mobs": ["Big Foot"],
"name": "Wald",
"items": [
"Holz",
"Stein"
]
},
{
"mobs": ["Riesenkrabbe"],
"name": "Strand",
"items": [
"Sand",
"Treibholz"
]
},
{
"mobs": ["Yeti"],
"name": "Winterland",
"items": [
"Eiszapfen",
"Schnee"
]
},
{
"mobs": ["Loewe"],
"name": "Berge",
"items": [
"Quellwasser",
"Feuerstein"
]
},
{
"mobs": ["Drache"],
"name": "Gruenland",
"items": [
"Lehm",
"Giftblume"
]
},
{
"mobs": ["Mumie"],
"name": "Wueste",
"items": [
"Sand",
"Kaktus"
]
}
]
} }

31
src/main/resources/playerconfig.json

@ -1,17 +1,18 @@
{ {
"name": "null",
"gold": 0,
"hp": 10,
"currentLocation": "Wald",
"inventory": [
{
"name": "Holz",
"amount": "5",
"durability": 1000
},{
"name": "Stein",
"amount": "5",
"durability": 1000
}
]
"gold": 0,
"name": "null",
"hp": 10,
"inventory": [
{
"amount": "5",
"durability": 1000,
"name": "Holz"
},
{
"amount": "5",
"durability": 1000,
"name": "Stein"
}
],
"currentLocation": "Berge"
} }

405
src/main/resources/quiz.json

@ -1,204 +1,205 @@
{ {
"Quiz": [
{
"frage": "Wie lang ist der Äquator der Erde?",
"antworten": [
"20.000m",
"30km",
"60.000km",
"40.000km"
],
"korrekteAntwort": "40.000km"
},
{
"frage": "Was ist der längste Fluss der Welt?",
"antworten": [
"Amazonas",
"Nil",
"Rhein",
"Niger"
],
"korrekteAntwort": "Nil"
},
{
"frage": "Wie viele Tasten hat ein Klavier?",
"antworten": [
"74",
"86",
"82",
"88"
],
"korrekteAntwort": "88"
},
{
"frage": "Von wem wird der Bundespräsident gewählt?",
"antworten": [
"Vom Europäischen Parlament",
"Vom Bundeskanzler",
"Vom Bundestag",
"Von der Bundesversammlung"
],
"korrekteAntwort": "von der Bundesversammlung"
},
{
"frage": "Welches Land produziert jährlich die meisten Filme?",
"antworten": [
"USA",
"Indien",
"Japan",
"Nigeria"
],
"korrekteAntwort": "Indien"
},
{
"frage": "Wie heißt der am schnellsten schwimmende Fisch auf Erden?",
"antworten": [
"Flugfisch",
"Tigerhai",
"Segelfisch",
"Windfisch"
],
"korrekteAntwort": "Segelfisch"
},
{
"frage": "Was ist KEIN Gewächs?",
"antworten": [
"Geranie",
"Moosfarn",
"Incolornis",
"Strandflieder"
],
"korrekteAntwort": "Incolornis"
},
{
"frage": "Was nutzt eine Fledermaus zur Orientierung in der Luft?",
"antworten": [
"Infrarot",
"Röntgenstrahlen",
"Speichel",
"Ultraschall"
],
"korrekteAntwort": "Ultraschall"
},
{
"frage": "Von wem stammt der berühmte Satz: 'Ich denke, also bin ich'?",
"antworten": [
"John Fitzgerald Kennedy",
"George Walker Bush",
"René Descartes",
"Julius Caesar"
],
"korrekteAntwort": "René Descartes"
},
{
"frage": "Welches Lebensmittel enthält das meiste Wasser?",
"antworten": [
"Gurke",
"Wassermelone",
"Zitrone",
"Paprika"
],
"korrekteAntwort": "Gurke"
},
{
"frage": "Welches Lebensmittel gehört im botanischen Sinne zu den Früchten?",
"antworten": [
"Möhre",
"Kartoffel",
"Tomate",
"Weißkohl"
],
"korrekteAntwort": "Tomate"
},
{
"frage": "Haptische Wahrnehmung beruht auf dem...?",
"antworten": [
"Greifreflex",
"Gleichgewichtssinn",
"Hörsinn",
"Tastsinn"
],
"korrekteAntwort": "Tastsinn"
},
{
"frage": "Wie nennt man den letzten Tanz einer Tanzveranstaltung?",
"antworten": [
"Voraus",
"Garaus",
"Kehraus",
"Durchaus"
],
"korrekteAntwort": "Kehraus"
},
{
"frage": "Wie nennt man ein tiefes, enges Tal, durch das ein Gebirgsbach fließt?",
"antworten": [
"Klamm",
"Feucht",
"Nass",
"Schwamm"
],
"korrekteAntwort": "Klamm"
},
{
"frage": "Wer oder was ist Gerbera?",
"antworten": [
"eine europäische Landschaft",
"eine Pflanze",
"die erste Präsidentin von Südafrika",
"eine Stadt in Lichtenstein"
],
"korrekteAntwort": "eine Pflanze"
},
{
"frage": "Nach wem wurde ein Gesellschaftsanzug benannt?",
"antworten": [
"Richard von Weizsäcker",
"Gustav Heinemann",
"Jürgen Klinsmann",
"Gustav Stresemann"
],
"korrekteAntwort": "Gustav Stresemann"
},
{
"frage": "Was ist Speckstein?",
"antworten": [
"eine Fischart, die sich als Stein tarnt",
"ein Gericht aus dem Mittelalter",
"eine Skulptur im Römischen Reich unter Nero",
"ein besonders weicher Stein"
],
"korrekteAntwort": "ein besonders weicher Stein"
},
{
"frage": "In welcher Religion gibt es Gurus?",
"antworten": [
"im Christentum",
"im Hinduismus",
"im Islam",
"im Judentum"
],
"korrekteAntwort": "im Hinduismus"
},
{
"frage": "Was versteht man unter Brunsbüttel?",
"antworten": [
"eine Industriestadt an der Unterelbe",
"einen Plakatkleber",
"eine 630 Mark-Kraft",
"ein Staatssekretär"
],
"korrekteAntwort": "eine Industriestadt an der Unterelbe"
},
{
"frage": "Welcher im 11. Jahrhundert gegründeter Orden rettet und pfelgt auch noch heute Verletzte und Kranke?",
"antworten": [
"die Dominikaner",
"die Augustiner",
"die Zisterzienser",
"die Johanniter"
],
"korrekteAntwort": "die Johanniter"
}
]
"Quiz": [
{
"frage": "Wie lang ist der Äquator der Erde?",
"korrekteAntwort": "40.000km",
"antworten": [
"20.000m",
"30km",
"60.000km",
"40.000km"
]
},
{
"frage": "Was ist der längste Fluss der Welt?",
"korrekteAntwort": "Nil",
"antworten": [
"Amazonas",
"Nil",
"Rhein",
"Niger"
]
},
{
"frage": "Wie viele Tasten hat ein Klavier?",
"korrekteAntwort": "88",
"antworten": [
"74",
"86",
"82",
"88"
]
},
{
"frage": "Von wem wird der Bundespräsident gewählt?",
"korrekteAntwort": "von der Bundesversammlung",
"antworten": [
"Vom Europäischen Parlament",
"Vom Bundeskanzler",
"Vom Bundestag",
"Von der Bundesversammlung"
]
},
{
"frage": "Welches Land produziert jährlich die meisten Filme?",
"korrekteAntwort": "Indien",
"antworten": [
"USA",
"Indien",
"Japan",
"Nigeria"
]
},
{
"frage": "Wie heißt der am schnellsten schwimmende Fisch auf Erden?",
"korrekteAntwort": "Segelfisch",
"antworten": [
"Flugfisch",
"Tigerhai",
"Segelfisch",
"Windfisch"
]
},
{
"frage": "Was ist KEIN Gewächs?",
"korrekteAntwort": "Incolornis",
"antworten": [
"Geranie",
"Moosfarn",
"Incolornis",
"Strandflieder"
]
},
{
"frage": "Was nutzt eine Fledermaus zur Orientierung in der Luft?",
"korrekteAntwort": "Ultraschall",
"antworten": [
"Infrarot",
"Röntgenstrahlen",
"Speichel",
"Ultraschall"
]
},
{
"frage": "Von wem stammt der berühmte Satz: 'Ich denke, also bin ich'?",
"korrekteAntwort": "René Descartes",
"antworten": [
"John Fitzgerald Kennedy",
"George Walker Bush",
"René Descartes",
"Julius Caesar"
]
},
{
"frage": "Welches Lebensmittel enthält das meiste Wasser?",
"korrekteAntwort": "Gurke",
"antworten": [
"Gurke",
"Wassermelone",
"Zitrone",
"Paprika"
]
},
{
"frage": "Welches Lebensmittel gehört im botanischen Sinne zu den Früchten?",
"korrekteAntwort": "Tomate",
"antworten": [
"Möhre",
"Kartoffel",
"Tomate",
"Weißkohl"
]
},
{
"frage": "Haptische Wahrnehmung beruht auf dem...?",
"korrekteAntwort": "Tastsinn",
"antworten": [
"Greifreflex",
"Gleichgewichtssinn",
"Hörsinn",
"Tastsinn"
]
},
{
"frage": "Wie nennt man den letzten Tanz einer Tanzveranstaltung?",
"korrekteAntwort": "Kehraus",
"antworten": [
"Voraus",
"Garaus",
"Kehraus",
"Durchaus"
]
},
{
"frage": "Wie nennt man ein tiefes, enges Tal, durch das ein Gebirgsbach fließt?",
"korrekteAntwort": "Klamm",
"antworten": [
"Klamm",
"Feucht",
"Nass",
"Schwamm"
]
},
{
"frage": "Wer oder was ist Gerbera?",
"korrekteAntwort": "eine Pflanze",
"antworten": [
"eine europäische Landschaft",
"eine Pflanze",
"die erste Präsidentin von Südafrika",
"eine Stadt in Lichtenstein"
]
},
{
"frage": "Nach wem wurde ein Gesellschaftsanzug benannt?",
"korrekteAntwort": "Gustav Stresemann",
"antworten": [
"Richard von Weizsäcker",
"Gustav Heinemann",
"Jürgen Klinsmann",
"Gustav Stresemann"
]
},
{
"frage": "Was ist Speckstein?",
"korrekteAntwort": "ein besonders weicher Stein",
"antworten": [
"eine Fischart, die sich als Stein tarnt",
"ein Gericht aus dem Mittelalter",
"eine Skulptur im Römischen Reich unter Nero",
"ein besonders weicher Stein"
]
},
{
"frage": "In welcher Religion gibt es Gurus?",
"korrekteAntwort": "im Hinduismus",
"antworten": [
"im Christentum",
"im Hinduismus",
"im Islam",
"im Judentum"
]
},
{
"frage": "Was versteht man unter Brunsbüttel?",
"korrekteAntwort": "eine Industriestadt an der Unterelbe",
"antworten": [
"eine Industriestadt an der Unterelbe",
"einen Plakatkleber",
"eine 630 Mark-Kraft",
"ein Staatssekretär"
]
},
{
"frage": "Welcher im 11. Jahrhundert gegründeter Orden rettet und pfelgt auch noch heute Verletzte und Kranke?",
"korrekteAntwort": "die Johanniter",
"antworten": [
"die Dominikaner",
"die Augustiner",
"die Zisterzienser",
"die Johanniter"
]
}
],
"lastPlayed": 1675768444160
} }

44
src/test/java/org/bitbiome/classes/BlackJackTest.java

@ -0,0 +1,44 @@
package org.bitbiome.classes;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class BlackJackTest {
private static BlackJack bj;
@BeforeAll
public static void setUpTest() {
bj = new BlackJack("UnitTest");
}
@Test
public void testGetEntity() {
assertEquals(BlackJack.Entity.PLAYER, bj.getEntity(1));
}
@Test
public void testGetEntityBot() {
assertEquals(BlackJack.Entity.BOT, bj.getEntity(2));
}
@Test
public void testPlayerName() {
assertEquals("UnitTest", bj.getPlayerName(BlackJack.Entity.PLAYER));
}
@Test
public void testBotName() {
assertEquals("BitBiome", bj.getPlayerName(BlackJack.Entity.BOT));
}
@Test
public void testPlayerIsIn() {
assertTrue(bj.isIn(BlackJack.Entity.PLAYER));
}
@Test
public void testBotIsIn() {
assertTrue(bj.isIn(BlackJack.Entity.BOT));
}
}

23
src/test/java/org/bitbiome/classes/ColorsTest.java

@ -0,0 +1,23 @@
package org.bitbiome.classes;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class ColorsTest {
@Test
public void testResetCode() {
assertEquals("\u001B[0m", Colors.ANSI_RESET);
}
@Test
public void testBlueCode() {
assertEquals("\u001B[34m", Colors.ANSI_BLUE);
}
@Test
public void testCyanCode() {
assertEquals("\u001B[36m", Colors.ANSI_CYAN);
}
}

22
src/test/java/org/bitbiome/commands/HelpCommandTest.java

@ -1,8 +1,7 @@
package org.bitbiome.commands; package org.bitbiome.commands;
import org.bitbiome.classes.Colors;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class HelpCommandTest { public class HelpCommandTest {
@ -10,24 +9,7 @@ public class HelpCommandTest {
@Test @Test
public void testHelpCommand() { public void testHelpCommand() {
String helpMessage = HelpCommand.getHelpMessage(); String helpMessage = HelpCommand.getHelpMessage();
StringBuilder outputMessage = new StringBuilder();
outputMessage
.append("|______________|_____________________________|\n")
.append("|" + Colors.ANSI_PURPLE + " Command" + Colors.ANSI_RESET + " | " + Colors.ANSI_PURPLE + "Description" + Colors.ANSI_RESET + " |\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " help" + Colors.ANSI_RESET + " | Gibt diese Nachricht aus |\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " exit/quit" + Colors.ANSI_RESET + " | Beendet das Spiel |\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " travel" + Colors.ANSI_RESET + " | Startet das Reise System |\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " location" + Colors.ANSI_RESET + " | Gibt deine Location aus |\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " map" + Colors.ANSI_RESET + " | Zeigt dir deinen Karte |\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " gold" + Colors.ANSI_RESET + " | Gibt dein Gold an |\n")
.append("|______________|_____________________________|\n");
assertEquals(outputMessage.toString(), helpMessage);
assertTrue(helpMessage.contains("Command") && helpMessage.contains("Description"));
} }

4
src/test/java/org/bitbiome/commands/QuitCommandTest.java

@ -2,14 +2,14 @@ package org.bitbiome.commands;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class QuitCommandTest { public class QuitCommandTest {
@Test @Test
public void testQuitCommand() { public void testQuitCommand() {
assertEquals("You quitted!", QuitCommand.getQuitMessage());
assertTrue(QuitCommand.getQuitMessage().contains("Spiel beendet!"));
} }
} }

36
src/test/java/org/bitbiome/commands/QuizCommandTest.java

@ -0,0 +1,36 @@
package org.bitbiome.commands;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class QuizCommandTest {
@Test
public void testStartMessage() {
assertTrue(QuizCommand.starterMessage().contains("Du hast das Quiz gestartet!"));
}
@Test
public void testEndMessage() {
assertTrue(QuizCommand.endMessage().contains("Das Quiz ist vorbei!"));
}
@Test
public void testLastTimePlayed() {
long lastTimePlayed = System.currentTimeMillis();
assertTrue(QuizCommand.canPlayAgain(lastTimePlayed) < lastTimePlayed);
}
@Test
public void testRandomNumberGenerator() {
int getRandom = QuizCommand.random(3);
assertTrue(getRandom >= 0 && getRandom <= 3);
}
@Test
public void testPrintFunction() {
assertEquals("I am a unit test!", QuizCommand.print("I am a unit test!"));
}
}

105
src/test/java/org/bitbiome/commands/ShopCommandTest.java

@ -0,0 +1,105 @@
package org.bitbiome.commands;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.bitbiome.classes.Shop;
public class ShopCommandTest {
final Shop shop = new Shop(null, true, null, null);
@Test
public void testValidInput1(){
boolean expected = true;
boolean result = ShopCommand.validInput("1");
assertEquals(expected, result);
}
@Test
public void testValidInput2(){
boolean expected = true;
boolean result = ShopCommand.validInput("2");
assertEquals(expected, result);
}
@Test
public void testValidInput3(){
boolean expected = true;
boolean result = ShopCommand.validInput("3");
assertEquals(expected, result);
}
@Test
public void testValidInput4(){
boolean expected = true;
boolean result = ShopCommand.validInput("4");
assertEquals(expected, result);
}
@Test
public void testSubtractGold(){
int expected = 1;
int result = shop.subtractGold(3, 2);
assertEquals(expected, result);
}
@Test
public void testSubtractGold1(){
int expected = 10;
int result = shop.subtractGold(12, 2);
assertEquals(expected, result);
}
@Test
public void testSubtractGold2(){
int expected = 4;
int result = shop.subtractGold(7, 3);
assertEquals(expected, result);
}
@Test
public void testSubtractGold3(){
int expected = 5;
int result = shop.subtractGold(10, 5);
assertEquals(expected, result);
}
@Test
public void testSubtractGold4(){
int expected = 1;
int result = shop.subtractGold(2, 1);
assertEquals(expected, result);
}
@Test
public void testSubtractGold5(){
int expected = 10;
int result = shop.subtractGold(20, 10);
assertEquals(expected, result);
}
@Test
public void testSubtractGold6(){
int expected = 12;
int result = shop.subtractGold(24, 12);
assertEquals(expected, result);
}
@Test
public void testSubtractGold7(){
int expected = 15;
int result = shop.subtractGold(31, 16);
assertEquals(expected, result);
}
@Test
public void testSubtractGold8(){
int expected = 1;
int result = shop.subtractGold(2, 1);
assertEquals(expected, result);
}
@Test
public void testSubtractGold9(){
int expected = 8;
int result = shop.subtractGold(10, 2);
assertEquals(expected, result);
}
@Test
public void testSubtractGold10(){
int expected = 5;
int result = shop.subtractGold(10, 5);
assertEquals(expected, result);
}
}

50
src/test/java/org/bitbiome/entitiesTest/ItemTest.java

@ -0,0 +1,50 @@
package org.bitbiome.entitiesTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.bitbiome.entities.Item;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class ItemTest {
private static Item item;
@BeforeAll
public static void setItem() {
item = new Item();
item.setName("Unit");
item.setDamage("12,5");
item.changeDoesDamage(true);
item.setAmount(5);
item.setGold(100);
}
@Test
public void testGetName() {
assertEquals("Unit", item.getName());
}
@Test
public void testGetDamage() {
assertEquals("12,5", item.getDamage());
}
@Test
public void testDoesDamage() {
boolean doesDamage = item.doesDamage();
assumeTrue(item.getDamage().equals("12,5"));
assumeTrue(doesDamage);
}
@Test
public void testGetAmount() {
assumeTrue(item.getAmount() == 5);
}
@Test
public void testGetGold() {
assumeTrue(item.getGold() == 100);
}
}

24
src/test/java/org/bitbiome/entitiesTest/LocationTest.java

@ -0,0 +1,24 @@
package org.bitbiome.entitiesTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.bitbiome.entities.Location;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class LocationTest {
private static Location location;
@BeforeAll
public static void setLocation() {
location = new Location();
location.setName("NewUnitWorld");
}
@Test
public void testLocationName() {
assertEquals("NewUnitWorld", location.getName());
}
}

35
src/test/java/org/bitbiome/entitiesTest/MobTest.java

@ -0,0 +1,35 @@
package org.bitbiome.entitiesTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.bitbiome.entities.Mob;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class MobTest {
private static Mob mob;
@BeforeAll
public static void setMob() {
mob = new Mob();
mob.setFriendly(true);
mob.setDamage(0F);
mob.setHp(561.45F);
}
@Test
public void testFriendly() {
assertEquals(mob.isFriendly(), true);
}
@Test
public void testDamage() {
assertEquals(mob.getDamage(), 0F);
}
@Test
public void testHp() {
assertEquals(mob.getHp(), 561.45F);
}
}

43
src/test/java/org/bitbiome/entitiesTest/PlayerTest.java

@ -0,0 +1,43 @@
package org.bitbiome.entitiesTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.bitbiome.entities.Location;
import org.bitbiome.entities.Player;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class PlayerTest {
private static Player player;
private static Location location;
@BeforeAll
public static void setPlayer() {
player = new Player();
location = new Location();
location.setName("NewUnitWorld");
player.setName("UnitPlayer");
player.setLocation(location);
player.setHp(100F);
}
@Test
public void testPlayerName() {
assertEquals("UnitPlayer", player.getName());
}
@Test
public void testPlayerHp() {
assertEquals(100F, player.getHp());
}
@Test
public void testLocationNameFromPlayer() {
assertEquals("NewUnitWorld", player.getLocation().getName());
}
}
Loading…
Cancel
Save