234 lines
7.0 KiB
Java
234 lines
7.0 KiB
Java
package tui;
|
|
|
|
import domain.Sheet;
|
|
import domain.sheets.*;
|
|
import fassade.KniffelSystem;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.Scanner;
|
|
import java.util.Set;
|
|
|
|
public class TUI {
|
|
static KniffelSystem gameSystem;
|
|
static Scanner sc = new Scanner(System.in);
|
|
|
|
public static void main(String[] args) {
|
|
System.out.println("Welcome to the PR2 Kniffel game!");
|
|
|
|
// while (true){
|
|
// mainMenuOutput();
|
|
// }
|
|
|
|
|
|
// DEV:
|
|
gameSystem = new KniffelSystem();
|
|
gameSystem.createTestPlayers(6);
|
|
gameLoop();
|
|
}
|
|
|
|
private static int mainMenuOutput(){
|
|
System.out.println("What do you want to do?");
|
|
System.out.println("1 - Play");
|
|
System.out.println("2 - See leaderboard");
|
|
System.out.println("3 - Exit");
|
|
System.out.print("> ");
|
|
String mainMenuUserInput = sc.nextLine().toLowerCase();
|
|
|
|
|
|
if ((mainMenuUserInput.equals("1"))
|
|
|| (mainMenuUserInput.equals("play"))){
|
|
mainMenuPlay();
|
|
System.out.println("play"); // TEST
|
|
return 1;
|
|
}
|
|
else if ((mainMenuUserInput.equals("2"))
|
|
|| (mainMenuUserInput.equals("see leaderboard"))
|
|
|| (mainMenuUserInput.equals("see"))
|
|
|| (mainMenuUserInput.equals("leaderboard"))){
|
|
System.out.println("leaderboard"); // TEST
|
|
mainMenuLeaderBoard();
|
|
return 2;
|
|
}
|
|
else {
|
|
System.out.println("exit"); // TEST
|
|
mainMenuExit();
|
|
return 3;
|
|
}
|
|
}
|
|
|
|
private static void mainMenuPlay(){
|
|
gameSystem = new KniffelSystem();
|
|
|
|
System.out.println("How many players are you? (1-6)");
|
|
System.out.print("> ");
|
|
String mainMenuPlayAmountPlayersInput = sc.nextLine().toLowerCase();
|
|
|
|
int amountPlayers = Integer.parseInt(mainMenuPlayAmountPlayersInput);
|
|
|
|
for (int i = 0; i < amountPlayers; i++){
|
|
System.out.printf("Player %d: ", i + 1);
|
|
System.out.println("Enter your name: ");
|
|
System.out.print("> ");
|
|
String playerName = sc.nextLine();
|
|
|
|
String coloredPlayerName = gameSystem.addPlayer(i+1, playerName);
|
|
System.out.printf("Welcome %s! \n\n", coloredPlayerName);
|
|
}
|
|
|
|
gameLoop();
|
|
}
|
|
|
|
private static void gameLoop(){
|
|
String[] playerStrings = gameSystem.getAllPlayerStrings();
|
|
|
|
System.out.println("Participating players:");
|
|
for (String player : playerStrings){
|
|
System.out.println(player);
|
|
}
|
|
System.out.println();
|
|
|
|
int turncounter = 0;
|
|
int rollscount;
|
|
|
|
while (true){
|
|
rollscount = 0;
|
|
// System.out.printf("Turn Nr.%d\n", turncounter);
|
|
System.out.printf("It's your turn %s!\n\n", gameSystem.getCurrentPlayer());
|
|
|
|
ArrayList<Integer> rolls = new ArrayList<Integer>();
|
|
String keptDice = "";
|
|
|
|
while(rollscount < 3){
|
|
System.out.printf("Roll Nr. %d \n", rollscount); // TEST
|
|
System.out.printf("Kept dice: %s \n\n", keptDice); // TEST
|
|
|
|
|
|
rolls = gameSystem.rollDices(rolls, keptDice);
|
|
String newRollsString = diceArrToString(rolls);
|
|
System.out.println(newRollsString);
|
|
evaluateRoll(rolls);
|
|
|
|
System.out.println("Which dice do you want to keep?");
|
|
System.out.println("Empty for none, single digit for one dice or (1,3,4) for multiple dice.");
|
|
System.out.print("> ");
|
|
keptDice = sc.nextLine();
|
|
|
|
rollscount++;
|
|
}
|
|
|
|
turncounter = triggerNextTurn(turncounter);
|
|
}
|
|
}
|
|
|
|
|
|
private static String evaluateRoll(ArrayList<Integer> rolls){
|
|
HashMap<String, Category> possibleCombinations = createCategorieHashMap();
|
|
ArrayList<Category> validCombinations = new ArrayList<>();
|
|
//TODO Add starwars logic
|
|
|
|
|
|
for (int dice : rolls){
|
|
switch (dice){
|
|
case 1:
|
|
possibleCombinations.get("Aces").addAmount();
|
|
break;
|
|
case 2:
|
|
possibleCombinations.get("Twos").addAmount();
|
|
break;
|
|
case 3:
|
|
possibleCombinations.get("Threes").addAmount();
|
|
break;
|
|
case 4:
|
|
possibleCombinations.get("Fours").addAmount();
|
|
break;
|
|
case 5:
|
|
possibleCombinations.get("Fives").addAmount();
|
|
break;
|
|
case 6:
|
|
possibleCombinations.get("Sixes").addAmount();
|
|
break;
|
|
}
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Possible combinations: \n");
|
|
|
|
Set<String> keys = possibleCombinations.keySet();
|
|
for (String key : keys) {
|
|
Category keyObj = possibleCombinations.get(key);
|
|
int keyAmount = keyObj.getAmount();
|
|
int keyValue = keyObj.getValue();
|
|
|
|
if (keyAmount != 0){
|
|
validCombinations.add(keyObj);
|
|
sb.append(String.format("%s: Amount: %d, Value: %d \n",key, keyAmount, keyValue));
|
|
}
|
|
}
|
|
System.out.println(sb.toString());
|
|
|
|
for(Category categorie : validCombinations){
|
|
if (categorie.getAmount() == 3){
|
|
|
|
}
|
|
}
|
|
|
|
return "TODO";
|
|
}
|
|
|
|
|
|
private static HashMap<String, Category> createCategorieHashMap(){
|
|
// TODO starwars sheet implementieren
|
|
Sheet sheet = new Sheet();
|
|
|
|
return sheet.getAllCategories();
|
|
}
|
|
|
|
|
|
|
|
private static String diceArrToString(ArrayList<Integer> diceArr){
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Your rolls: \n");
|
|
for (int i = 0; i < diceArr.size(); i++){
|
|
sb.append(String.format("Dice %d: %s \n", i+1, Integer.toString(diceArr.get(i))));
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
|
|
private static int triggerNextTurn(int turnCounter){
|
|
turnCounter++;
|
|
System.out.print("Next turn? \n");
|
|
System.out.print("> ");
|
|
sc.nextLine();
|
|
gameSystem.nextPlayer();
|
|
return turnCounter;
|
|
}
|
|
|
|
|
|
|
|
private static void mainMenuLeaderBoard(){
|
|
gameSystem = new KniffelSystem(); // Scorboard System
|
|
System.out.println(gameSystem.LeaderBaordData()); // TODO
|
|
}
|
|
|
|
|
|
private static void mainMenuExit(){
|
|
System.out.println("Do you really want to exit? (Y/n)");
|
|
System.out.print("> ");
|
|
String mainMenuExitUserInput = sc.nextLine().toLowerCase();
|
|
|
|
if ((mainMenuExitUserInput.equals("y"))
|
|
|| (mainMenuExitUserInput.equals("yes"))
|
|
|| mainMenuExitUserInput.isBlank()){
|
|
System.out.print("Exiting, see you next time!");
|
|
System.exit(0);
|
|
}
|
|
else {
|
|
System.out.println("Returning to main menu");
|
|
System.out.println();
|
|
mainMenuOutput();
|
|
}
|
|
}
|
|
}
|