Semesterarbeit-1/main/GameControls.java

285 lines
10 KiB
Java

package minigame;
import java.io.BufferedReader;
import java.io.IOException;
public class GameControls {
private int raceCount;
private boolean hire;
private static Player player;
public GameControls() {
this.raceCount = 0;
}
public String toString() {
return "Races: "+this.raceCount;
}
public static void startInto(GameControls game, BufferedReader ter) throws InterruptedException, IOException {
String intro = "Welcome to Hoof-Hustle\n\nGet CREDITS by having your HORSE win RACES.\nBuy UPGRADES as well as new RACES with the CREDITS Earned.\n\nBut be careful.\nDont lose all your CREDITS!!!\n";
Tools.printSlow30(intro);
while (true) {
System.out.print("\nSYSTEM | Choose a Username: ");
String uname = ter.readLine();
if (uname.toCharArray().length > 15) {
System.out.println("\nSYSTEM | Please Choose a Shorter Username");
} else {
player = new Player(uname);
String info1 = "\nSTRANGER | Welcome to Hoof-Hustle " + player.username + "!";
Tools.printSlow30(info1);
break;
}
}
startGame(game, ter);
}
private static void startGame(GameControls game, BufferedReader ter) {
Tools.printSlow30("\nSTRANGER | Im Jones btw, I sell horses and train riders for a living! I will guide you through the first few steps of Horse Racing.");
while (true) {
Tools.printSlow30("\n\nSYSTEM | Hire Jones for free? y/n: ");
String choice;
try {
choice = String.valueOf(ter.readLine());
if (choice.equalsIgnoreCase("y")) {
game.hire = true;
Tools.printSlow30("\nJONES | Thanks for Hiring me!\n");
break;
} else if (choice.equalsIgnoreCase("n")){
game.hire = false;
break;
} else {
Tools.printSlow30("\nPossible options: y/n");
}
} catch (Exception e) {
Tools.printSlow30("\nPossible options: y/n");
}
}
if (game.hire) {
Tools.printSlow30("JONES | Lets put your racing Skills to the test! But first we need to choose you a horse. How many credits do you have right now?\n");
Tools.waitT(1, "s");
Tools.printSlow30("\nSYSTEM | Check your current CREDITS with \"/p cr\"\nSYSTEM | Try it out: ");
while (true) {
try {
if (ter.readLine().equalsIgnoreCase("/p cr")) {
Tools.printSlow30("SYSTEM | ");
player.showBalance();
break;
} else {
Tools.printSlow30("\nSYSTEM | Tipp: use \"/p cr\": ");
}
} catch (IOException e) {
e.printStackTrace();
}
}
Tools.printSlow30("\nJONES | With that little money you won't really be able to buy a good horse.\nJONES | I can give you a friends-deal on one of my cheaper horses though.\n\n");
Shop.showHorses();
} else {
Tools.printSlow30("\nJONES | No problem mate. See you around!\n\nSYSTEM | Choose a Horse from Jones Store to get started...\n\n");
Shop.showHorses();
}
Tools.printSlow30("\nChoose a horse with \"/buy <ID>\": ");
while (true) {
try {
String [] full_com = ter.readLine().split(" ");
String com = full_com[0];
System.out.println();
if (com.equalsIgnoreCase("/buy")) {
if (!(Integer.valueOf(full_com[1])>4)) {
player.buyHorse(Integer.valueOf(full_com[1]));
break;
} else {
Tools.printSlow30("SYSTEM | Use one of the IDs in range: ");
}
} else {
Tools.printSlow30("SYSTEM | Use one of the IDs in range: ");
}
} catch (Exception e) {
Tools.printSlow30("SYSTEM | Use one of the IDs in range: ");
}
}
Tools.printSlow30("\nJONES | Excelent Choice " + player.username + ".\nJONES | Alright let's see how you do on the track!\nJONES | Your first Race will take place here in Mannheim, but if you do well you can work your way up to known tracks like those in Tokyo and New York!\n\n");
Race.firstRace(player,ter, Player.player_horses.get(1));
runMenu(0, ter);
}
static void runMenu(int status, BufferedReader ter) {
if (status == 0) {
//get help
Tools.printSlow30("\n------------------------------------------------------------------------------------------------------\nSYSTEM | Welcome to the Hoof-Hustle Main Menu " +player.username+"!");
help();
takeInput(ter);
} else if (status == 1){
//no help
takeInput(ter);
}
}
private static void takeInput(BufferedReader ter) {
Tools.printSlow30("\n\nMENU | Player Input: ");
try {
String input = ter.readLine();
String [] full_com = input.split(" ");
String com = full_com[0];
switch (com) {
case "/p":
//info cr name
switch (full_com[1]) {
case "info":
Tools.printSlow30("\nSYSTEM | "+player.toString()+"\n------------------------------------------------------------------------------------------------------");
player.visLevelProgress();
runMenu(1,ter);
break;
case "cr":
Tools.printSlow30("PLAYER | "+String.valueOf(player.getCred()));
runMenu(1,ter);
break;
case "name":
String newName;
if ((newName = player.changeName(ter))!=null) {
player.username = newName;
Tools.printSlow30("SYSTEM | "+player.toString());
} else {
Tools.printSlow30("\nSYSTEM | Canceled \"Name change\"");
runMenu(1,ter);
}
break;
default:
Tools.printSlow30("\nSYSTEM | Unknown Command. Use \"/g help\"");
runMenu(1,ter);
break;
}
break;
case "/h":
//all show <name> sell <name>
switch (full_com[1]) {
case "all":
System.out.println();
player.showHorses();
runMenu(1,ter);
break;
case "show":
try {
player.showOneHorse(Integer.valueOf(full_com[2]));
} catch (Exception e) {
Tools.printSlow30("\nSYSTEM | That didnt seem to work. Use \"/g help\"");
}
runMenu(1,ter);
break;
case "sell":
try {
System.out.println();
player.sellHorse(Integer.valueOf(full_com[2]));
runMenu(1,ter);
break;
} catch (Exception e) {
Tools.printSlow30("\nSYSTEM | That didnt seem to work. Use \"/g help\"");
runMenu(1,ter);
break;
}
default:
Tools.printSlow30("\nSYSTEM | Unknown Command. Use \"/g help\"");
runMenu(1,ter);
break;
}
break;
case "/s":
//open
switch (full_com[1]) {
case "open":
Shop.openShop(player, ter);
break;
default:
Tools.printSlow30("\nSYSTEM | Unknown Command. Use \"/g help\"");
runMenu(1,ter);
break;
}
break;
case "/r":
//hs next start end
switch (full_com[1]) {
case "hs":
Race.showHistory();
runMenu(1,ter);
break;
case "next":
Race.genNextRace(player, ter);
break;
default:
Tools.printSlow30("\nSYSTEM | Unknown Command. Use \"/g help\"");
runMenu(1,ter);
break;
}
break;
case "/g":
//help quit
switch (full_com[1]) {
case "help":
help();
runMenu(1,ter);
break;
case "quit":
Tools.printSlow30("SYSTEM | Saving Progress...");
saveProgress();
Tools.printSlow80("\n\n::::::::::::::::::::::::::::::::::::::::::::::::: | ");
Tools.printSlow15("Save complete!");
Tools.waitT(1, "s");
Tools.printSlow30("\n\nSYSTEM | Quitting the game");
Tools.waitT(800, "m");
Tools.printSlow800("...");
System.exit(0);
break;
}
break;
default:
Tools.printSlow30("\nSYSTEM | Please use a command from the list above or use \"g help\"");
runMenu(0, ter);
}
} catch (Exception e) {
e.printStackTrace();;
}
}
public static void help() {
//Player commands
Tools.printSlow15("\n------------------------------------------------------------------------------------------------------\n\nSYSTEM | Player commands\n");
Tools.explainCommand("p info","Displays all important information about the player");
Tools.explainCommand("p cr","Shows your current Balance");
Tools.explainCommand("p name","Lets you change your current Username");
//HorseCommands
Tools.printSlow15("\n\n------------------------------------------------------------------------------------------------------\n\nSYSTEM | Horse commands\n");
Tools.explainCommand("h all","Shows all the horses you own");
Tools.explainCommand("h show <Name>","Shows the horse with that name");
Tools.explainCommand("h sell <Name>","Sell one of your horses for 80% Original Value");
//Shop commands
Tools.printSlow15("\n\n------------------------------------------------------------------------------------------------------\n\nSYSTEM | Shop commands\n");
Tools.explainCommand("s open","Enter the shop");
//Race commands
Tools.printSlow15("\n\n------------------------------------------------------------------------------------------------------\n\nSYSTEM | Race commands\n");
Tools.explainCommand("r hs","Shows your Race History");
Tools.explainCommand("r next","Starts the next Race");
Tools.explainCommand("r start","Starts the Race");
Tools.explainCommand("r end","Ends the Race");
//Game commands
Tools.printSlow15("\n\n------------------------------------------------------------------------------------------------------\n\nSYSTEM | Game commands\n");
Tools.explainCommand("g quit","Ends the current Game");
Tools.explainCommand("g help","Shows the list of available commands");
}
private static void saveProgress() {
//save mechanism
}
}