Browse Source

adding Colors to prints on the console

remotes/origin/shop
Max Gerbeth 2 years ago
parent
commit
6d837c934c
  1. 24
      src/main/java/org/bitbiome/commands/ShopCommand.java
  2. 7
      src/main/java/org/bitbiome/shop/Shop.java

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

@ -1,5 +1,6 @@
package org.bitbiome.commands;
import org.bitbiome.classes.Colors;
import org.bitbiome.classes.TravelEngine;
import org.bitbiome.shop.Item;
import org.bitbiome.shop.Shop;
@ -16,7 +17,7 @@ public class ShopCommand implements CommandAPI{
@Override
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
System.out.println("Willkommen im Shop!");
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
@ -37,20 +38,25 @@ public class ShopCommand implements CommandAPI{
System.out.println("");
System.out.print("Welches Item moechtest du kaufen? ");
String itemNumber = scanner.nextLine();
if(!itemNumber.equals("0")){
if(!itemNumber.equals("0")) {
System.out.print("Anzahl eingeben: ");
String amount = scanner.nextLine();
if((Integer.parseInt(amount) <= currentItems.get(Integer.parseInt(itemNumber) - 1).amount) && ((Integer.parseInt(amount) - 1) > -1)){
try {
if ((Integer.parseInt(amount) <= currentItems.get(Integer.parseInt(itemNumber) - 1).amount) && ((Integer.parseInt(amount) - 1) > -1)) {
boolean bool = shop.buy(currentItems.get(Integer.parseInt(itemNumber) - 1).name, Integer.parseInt(amount));
currentItems = shop.loadCurrentShopItems();
if(bool){
if (bool) {
System.out.println("");
System.out.println("Vielen Dank für Ihren Einkauf!");
}else{
System.out.println("Fehler");
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);
}
}else{
System.out.println("Fehler");
}catch (Exception e){
System.out.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Fehler!h" + Colors.ANSI_RESET);
}
}
} else if(input.equals("2")){

7
src/main/java/org/bitbiome/shop/Shop.java

@ -1,5 +1,6 @@
package org.bitbiome.shop;
import org.bitbiome.classes.Colors;
import org.bitbiome.classes.JsonParser;
import org.json.JSONArray;
import org.json.JSONObject;
@ -51,18 +52,18 @@ public class Shop {
}
}
if(itemIndex == -1){
System.out.println("Dieses Item gibt es nicht");
System.out.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Dieses Item gibt es nicht!" + Colors.ANSI_RESET);
return false;
}
if(!(currentShopItems.get(itemIndex).amount > 0)){
System.out.println("Es gibt zu wenige Items");
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).gold * amount;
int gold = (int) playerConfig.get("gold");
if(!(gold >= costs)){
System.out.println("Du hast zu wenig Gold!");
System.out.println(Colors.ANSI_BG_RED + Colors.ANSI_BLACK + "Du hast zu wenig Gold!" + Colors.ANSI_RESET);
return false;
}

Loading…
Cancel
Save