|
@ -3,18 +3,22 @@ package org.bitbiome.commands; |
|
|
import org.bitbiome.shop.Item; |
|
|
import org.bitbiome.shop.Item; |
|
|
import org.bitbiome.shop.Shop; |
|
|
import org.bitbiome.shop.Shop; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Scanner; |
|
|
import java.util.Scanner; |
|
|
|
|
|
|
|
|
public class ShopCommand implements CommandAPI{ |
|
|
public class ShopCommand implements CommandAPI{ |
|
|
|
|
|
|
|
|
Shop shop = new Shop(); |
|
|
Shop shop = new Shop(); |
|
|
|
|
|
public ShopCommand(){ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void performCommand(Scanner scanner, boolean isRunning, String message) { |
|
|
public void performCommand(Scanner scanner, boolean isRunning, String message) { |
|
|
System.out.println("Willkommen im Shop!"); |
|
|
System.out.println("Willkommen im Shop!"); |
|
|
System.out.println("Folgende Items sind aktuell im Shop:"); |
|
|
|
|
|
shop.printCurrentShopItems(); |
|
|
|
|
|
ArrayList<Item> currentItems; |
|
|
|
|
|
|
|
|
ArrayList<Item> currentItems = shop.loadCurrentShopItems(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true){ |
|
|
while (true){ |
|
|
System.out.println("Was willst Du hier im Shop?"); |
|
|
System.out.println("Was willst Du hier im Shop?"); |
|
@ -25,34 +29,24 @@ public class ShopCommand implements CommandAPI{ |
|
|
String input = scanner.nextLine(); |
|
|
String input = scanner.nextLine(); |
|
|
if(validInput(input)){ |
|
|
if(validInput(input)){ |
|
|
if(input.equals("1")){ |
|
|
if(input.equals("1")){ |
|
|
currentItems = shop.currentShopItems; |
|
|
|
|
|
String inp = ""; |
|
|
|
|
|
System.out.println(""); |
|
|
|
|
|
System.out.println("Welches Item wollen Sie kaufen? "); |
|
|
|
|
|
|
|
|
System.out.println("Folgende sind folgende Items im Shop: "); |
|
|
for(int i = 0; i < currentItems.size(); i++){ |
|
|
for(int i = 0; i < currentItems.size(); i++){ |
|
|
System.out.println((i + 1) + " eingaben fuer " + currentItems.get(i).name + " | Kosten: " + currentItems.get(i).gold + " | Anzahl: " + currentItems.get(i).amount); |
|
|
|
|
|
} |
|
|
|
|
|
System.out.println("0 eingeben fuer eine andere Option."); |
|
|
|
|
|
|
|
|
|
|
|
while (true){ |
|
|
|
|
|
inp = scanner.nextLine(); |
|
|
|
|
|
if(inp.equals("0")){ |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
System.out.println((i + 1) + ". " + currentItems.get(i).name + " | Anzahl: " + currentItems.get(i).amount + " | Gold: " + currentItems.get(i).gold); |
|
|
} |
|
|
} |
|
|
System.out.print("Anzahl eingeben: "); |
|
|
|
|
|
int existingCount = currentItems.get(Integer.parseInt(inp) - 1).amount; |
|
|
|
|
|
String inpAmount = scanner.nextLine(); |
|
|
|
|
|
if(Integer.parseInt(inpAmount) <= existingCount){ |
|
|
|
|
|
if(shop.buy(currentItems.get(Integer.parseInt(inp) - 1).name, Integer.parseInt(inpAmount))){ |
|
|
|
|
|
|
|
|
System.out.println("0 Eingeben um den Shop zu verlassen."); |
|
|
System.out.println(""); |
|
|
System.out.println(""); |
|
|
System.out.println("Vielen Dank fuer deinen Einkauf!"); |
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
if((Integer.parseInt(amount) <= currentItems.get(Integer.parseInt(itemNumber) - 1).amount) && ((Integer.parseInt(amount) - 1) > -1)){ |
|
|
|
|
|
shop.buy(currentItems.get(Integer.parseInt(itemNumber) - 1).name, Integer.parseInt(amount)); |
|
|
|
|
|
currentItems = shop.loadCurrentShopItems(); |
|
|
System.out.println(""); |
|
|
System.out.println(""); |
|
|
break; |
|
|
|
|
|
}else { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
System.out.println("Error!"); |
|
|
|
|
|
|
|
|
System.out.println("Vielen Dank für Ihren Einkauf!"); |
|
|
|
|
|
}else{ |
|
|
|
|
|
System.out.println("Fehler"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else if(input.equals("2")){ |
|
|
} else if(input.equals("2")){ |
|
|