Browse Source

while input loop and validInput() method

remotes/origin/shop
Max Gerbeth 2 years ago
parent
commit
f51c508b25
  1. 29
      src/main/java/org/bitbiome/commands/ShopCommand.java
  2. 14
      src/main/java/org/bitbiome/shop/Shop.java

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

@ -5,11 +5,38 @@ import org.bitbiome.shop.Shop;
import java.util.Scanner;
public class ShopCommand implements CommandAPI{
Shop shop = new Shop();
@Override
public void performCommand(Scanner scanner, boolean isRunning, String message) {
new Shop();
System.out.println("Willkommen im Shop!");
System.out.println("Folgende Items sind aktuell im Shop:");
shop.getCurrentShopItems();
System.out.println("Was willst Du hier im Shop?");
System.out.println("Etwas kaufen: 1");
System.out.println("Das Quiz spielen: 2");
System.out.println("Den Shop verlassen: 3");
while (true){
String input = scanner.nextLine();
if(validInput(input)){
if(input.equals("1")){
//shop.buy();
} else if(input.equals("2")){
//shop.quiz()
} else if(input.equals("3")){
System.out.println("Der Shop wurde verlassen!");
break;
}
}else {
System.out.println("Unbekannte Eingabe!");
}
}
}
private boolean validInput(String input){
return (input.equals("1") || input.equals("2") || input.equals("3"));
}
}

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

@ -7,7 +7,13 @@ public class Shop {
public ArrayList<Item> currentShopItems;
public Shop(){
allItems = loadItems();
//allItems = loadItems();
allItems = new ArrayList<Item>();
allItems.add(new Item("Holz", 10, 10));
allItems.add(new Item("Holz2", 11, 10));
allItems.add(new Item("Holz3", 12, 10));
allItems.add(new Item("Holz4", 13, 10));
//currentShopItems = itemRotation(allItems, 3);
}
public boolean buy(){
@ -28,8 +34,8 @@ public class Shop {
return null;
}
public ArrayList<Item> getCurrentShopItems(){
return currentShopItems;
public void getCurrentShopItems(){
printArrayList(allItems);
}
public void quiz(){
@ -39,7 +45,7 @@ public class Shop {
private void printArrayList(ArrayList<Item> arrayList){
System.out.println("");
for(int i = 0; i < arrayList.size(); i++){
System.out.println(arrayList.get(i).getName() + " | " + arrayList.get(i).getAmount() + " | " + arrayList.get(i).getGold());
System.out.println(arrayList.get(i).getName() + " | Anzahl: " + arrayList.get(i).getAmount() + " | Kosten: " + arrayList.get(i).getGold());
}
System.out.println("");
}

Loading…
Cancel
Save