114 lines
3.8 KiB
Java
114 lines
3.8 KiB
Java
package minigame;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.util.ArrayList;
|
|
import java.util.TreeMap;
|
|
|
|
public class Shop {
|
|
|
|
public static String owner = "Jones";
|
|
public static TreeMap<Integer, Horse> shop_horses = new TreeMap<>();
|
|
private static int max_id = 0;
|
|
|
|
static {
|
|
Horse [] horses = { new Horse(8, 0.07, 14, "Atlas", "Shop"), new Horse(12, 0.15, 2, "Ember", "Shop"),
|
|
new Horse(17, 0.12, 5, "Spirit", "Shop"), new Horse(20, 0.2, 3, "Zenith", "Shop") };
|
|
for (Horse horse : horses) {
|
|
max_id++;
|
|
shop_horses.put(max_id, horse);
|
|
}
|
|
}
|
|
|
|
public static void showHorses() {
|
|
for (Integer key : shop_horses.keySet()) {
|
|
System.out.println("SHOP | ID: " + key + ", " + shop_horses.get(key));
|
|
}
|
|
}
|
|
|
|
public static void openShop(Player player, BufferedReader ter) {
|
|
Tools.printSlow30("\n------------------------------------------------------------------------------------------------------\nJONES | Welcome to my little store. Here you will find everything you need to become a true Champion.\n------------------------------------------------------------------------------------------------------\n");
|
|
Tools.printSlow30("\nJONES | These are the horses I sell right now:\nINFO | Play races to refresh the Store...\n\n");
|
|
for (Integer key : shop_horses.keySet()) {
|
|
System.out.println("SHOP | ID: " + key + ", " + shop_horses.get(key));
|
|
}
|
|
Tools.printSlow30("\n------------------------------------------------------------------------------------------------------\n");
|
|
shopHelp();
|
|
processInput(player, ter);
|
|
}
|
|
|
|
private static void processInput(Player player, BufferedReader ter) {
|
|
while(true) {
|
|
Tools.printSlow30("\nINFO | Balance: "+player.credits + " crd.");
|
|
Tools.printSlow30("\nSHOP | Player Input: ");
|
|
try {
|
|
String input = ter.readLine();
|
|
String [] full_com = input.split(" ");
|
|
String com = full_com[0];
|
|
switch (com) {
|
|
case "/buy":
|
|
try {
|
|
player.buyHorse(Integer.valueOf(full_com[1]));
|
|
} catch (Exception e) {
|
|
Tools.printSlow30("\nSYSTEM | \""+full_com[1]+"\" does not seem to be a valid Horse ID.\n");
|
|
}
|
|
break;
|
|
case "/refresh":
|
|
if (player.credits>=50) {
|
|
refreshShop(player);
|
|
processInput(player, ter);
|
|
break;
|
|
} else {
|
|
Tools.printSlow30("\nSYSTEM | You dont have enough Credits to do that right now!\n");
|
|
processInput(player, ter);
|
|
break;
|
|
}
|
|
case "/lv":
|
|
GameControls.runMenu(0, ter);
|
|
break;
|
|
case "/horses":
|
|
System.out.println();
|
|
showHorses();
|
|
break;
|
|
default:
|
|
Tools.printSlow30("\nSYSTEM |That doesnt seem to work. Please try again.\n");
|
|
break;
|
|
}
|
|
} catch (Exception e) {
|
|
Tools.printSlow30("\nSYSTEM |That doesnt seem to work. Please try again.\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void refreshShop(Player player) {
|
|
player.credits-=25;
|
|
shop_horses.clear();
|
|
updateShop(player);
|
|
showHorses();
|
|
}
|
|
|
|
private static void shopHelp() {
|
|
Tools.printSlow30("\nPossible Commands:\n");
|
|
Tools.explainCommand("horses", "Shows all available Horses" );
|
|
Tools.explainCommand("buy <ID>", "Buy a horse by ID");
|
|
Tools.explainCommand("refresh", "Refresh the horse store for 25 crd");
|
|
Tools.explainCommand("lv", "Leave the store");
|
|
Tools.printSlow30("\n\n------------------------------------------------------------------------------------------------------\n");
|
|
|
|
}
|
|
|
|
public static void updateShop(Player player) {
|
|
if (shop_horses.size() < 4) {
|
|
fillHorses(player);
|
|
}
|
|
}
|
|
|
|
private static void fillHorses(Player player) {
|
|
ArrayList<Horse> new_hor = new ArrayList<>(Horse.genHorses((4-shop_horses.size()),(player.level+1),"Shop"));
|
|
for (Horse horse : new_hor) {
|
|
max_id++;
|
|
shop_horses.put(max_id, horse);
|
|
}
|
|
}
|
|
|
|
}
|