Dateien nach "main" hochladen

main
Michel Joris Hombrecher 2024-01-09 02:11:49 +01:00
parent 204f0548cd
commit f7e684b1bb
2 changed files with 186 additions and 0 deletions

113
main/Shop.java 100644
View File

@ -0,0 +1,113 @@
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);
}
}
}

73
main/Tools.java 100644
View File

@ -0,0 +1,73 @@
package minigame;
public class Tools {
public static void printSlow30(String x) {
for (char y : x.toCharArray()) {
System.out.print(y);
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void printSlow15(String x) {
for (char y : x.toCharArray()) {
System.out.print(y);
try {
Thread.sleep(15);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void printSlow80(String x) {
for (char y : x.toCharArray()) {
System.out.print(y);
try {
Thread.sleep(80);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void printSlow800(String x) {
for (char y : x.toCharArray()) {
System.out.print(y);
try {
Thread.sleep(800);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void waitT(int time, String type) {
if (type.equalsIgnoreCase("s")) {
try {
Thread.sleep(time * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else if (type.equalsIgnoreCase("m")){
try {
Thread.sleep(time);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void explainCommand(String com, String info) {
Tools.printSlow30("\nINFO | \"/"+com+"\" - "+info);
}
public static String lineGap() {
return "------------------------------------------------------------------------------------------------------";
}
}