From f51c508b2554d9d96a60929a0151482f6c7721c0 Mon Sep 17 00:00:00 2001 From: Max Gerbeth Date: Mon, 9 Jan 2023 18:19:56 +0100 Subject: [PATCH] while input loop and validInput() method --- .../org/bitbiome/commands/ShopCommand.java | 29 ++++++++++++++++++- src/main/java/org/bitbiome/shop/Shop.java | 14 ++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/ShopCommand.java b/src/main/java/org/bitbiome/commands/ShopCommand.java index 9d5c950..3cc6337 100644 --- a/src/main/java/org/bitbiome/commands/ShopCommand.java +++ b/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")); + } } diff --git a/src/main/java/org/bitbiome/shop/Shop.java b/src/main/java/org/bitbiome/shop/Shop.java index 83d33ef..193e0ee 100644 --- a/src/main/java/org/bitbiome/shop/Shop.java +++ b/src/main/java/org/bitbiome/shop/Shop.java @@ -7,7 +7,13 @@ public class Shop { public ArrayList currentShopItems; public Shop(){ - allItems = loadItems(); + //allItems = loadItems(); + allItems = new ArrayList(); + 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 getCurrentShopItems(){ - return currentShopItems; + public void getCurrentShopItems(){ + printArrayList(allItems); } public void quiz(){ @@ -39,7 +45,7 @@ public class Shop { private void printArrayList(ArrayList 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(""); }