2 seperate highscore tables and final fixes

main
selim 2024-04-30 15:49:59 +02:00
parent 936474c659
commit 9c3c0a7f89
14 changed files with 167 additions and 92 deletions

View File

@ -1,10 +1,10 @@
2024-04-30: Selim: 172 2024-04-30 Selim 254
___: ___: 0 2024-04-30 Enes 127
___: ___: 0 2024-04-30 David 82
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0

1 2024-04-30: Selim: 172 2024-04-30 Selim 254
2 ___: ___: 0 2024-04-30 Enes 127
3 ___: ___: 0 2024-04-30 David 82
4 ___: ___: 0 ___ ___ 0
5 ___: ___: 0 ___ ___ 0
6 ___: ___: 0 ___ ___ 0
7 ___: ___: 0 ___ ___ 0
8 ___: ___: 0 ___ ___ 0
9 ___: ___: 0 ___ ___ 0
10 ___: ___: 0 ___ ___ 0

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,10 +1,10 @@
2024-04-30: Selim: 172 2024-04-30 Selim 254
___: ___: 0 2024-04-30 Enes 127
___: ___: 0 2024-04-30 David 82
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0
___: ___: 0 ___ ___ 0

1 2024-04-30: Selim: 172 2024-04-30 Selim 254
2 ___: ___: 0 2024-04-30 Enes 127
3 ___: ___: 0 2024-04-30 David 82
4 ___: ___: 0 ___ ___ 0
5 ___: ___: 0 ___ ___ 0
6 ___: ___: 0 ___ ___ 0
7 ___: ___: 0 ___ ___ 0
8 ___: ___: 0 ___ ___ 0
9 ___: ___: 0 ___ ___ 0
10 ___: ___: 0 ___ ___ 0

View File

View File

@ -153,10 +153,10 @@ public class Box {
} }
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (counter[i] == 1 && counter[i + 1] == 1 && counter[i + 2] == 1 && counter[i + 3] == 1 && counter[i + 3] == 1) if (counter[i] == 1 && counter[i + 1] == 1 && counter[i + 2] == 1 && counter[i + 3] == 1
&& counter[i + 3] == 1)
categoryBigStreet = 40; categoryBigStreet = 40;
} }
@ -247,10 +247,17 @@ public class Box {
if (setCategoryR2D2 == null && savedGamemode.equals("Special8")) if (setCategoryR2D2 == null && savedGamemode.equals("Special8"))
res.add("R2D2: " + categoryR2D2); res.add("R2D2: " + categoryR2D2);
} }
return res; return res;
} }
public boolean onlyOneOption() {
return getAllOptions().size() == 1;
}
public void selectOption(String option) { public void selectOption(String option) {
if (option.equals("One")) if (option.equals("One"))
@ -363,14 +370,17 @@ public class Box {
if (savedGamemode.equals("Special8")) { if (savedGamemode.equals("Special8")) {
if(nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour) if (nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(setCategorySeven) + nullCheckInt(setCategoryEight) >= 108){ + nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(setCategorySeven)
+ nullCheckInt(setCategoryEight) >= 108) {
this.bonus = 35; this.bonus = 35;
} }
} else } else
if(nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour) if (nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree)
+ nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) >= 63) { + nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) >= 63) {
this.bonus = 35; this.bonus = 35;
} }
@ -381,7 +391,8 @@ public class Box {
if (savedGamemode.equals("Special8")) if (savedGamemode.equals("Special8"))
return setCategoryOne + setCategoryTwo + setCategoryThree + setCategoryFour + setCategoryFive return setCategoryOne + setCategoryTwo + setCategoryThree + setCategoryFour + setCategoryFive
+ setCategorySix + setCategorySeven + setCategoryEight + nullCheckInt(bonus) + setCategoryTripleMatch + setCategorySix + setCategorySeven + setCategoryEight + nullCheckInt(bonus)
+ setCategoryTripleMatch
+ setCategoryFourOfAKind + setCategoryFourOfAKind
+ setCategoryFullHouse + setCategorySmallStreet + setCategoryBigStreet + setCategoryYahtzee + setCategoryFullHouse + setCategorySmallStreet + setCategoryBigStreet + setCategoryYahtzee
+ setCategoryChance + setCategoryStarWarsDay + setCategoryChance + setCategoryStarWarsDay
@ -455,33 +466,35 @@ public class Box {
if (savedGamemode.equals("Special8")) if (savedGamemode.equals("Special8"))
this.upperBoxScore = nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour) this.upperBoxScore = nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(setCategorySeven) + nullCheckInt(setCategoryEight) + nullCheckInt(bonus); + nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(setCategorySeven)
+ nullCheckInt(setCategoryEight) + nullCheckInt(bonus);
else else
this.upperBoxScore = nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour) this.upperBoxScore = nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo)
+ nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(bonus); + nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(bonus);
} }
public void updateLowerBoxScore() { public void updateLowerBoxScore() {
if (savedGamemode.equals("Special8")) if (savedGamemode.equals("Special8"))
this.lowerBoxScore = nullCheckInt(setCategoryTripleMatch) + nullCheckInt(setCategoryFourOfAKind) + nullCheckInt(setCategoryFullHouse) + nullCheckInt(setCategorySmallStreet) this.lowerBoxScore = nullCheckInt(setCategoryTripleMatch) + nullCheckInt(setCategoryFourOfAKind)
+ nullCheckInt(setCategoryBigStreet) + nullCheckInt(setCategoryYahtzee) + nullCheckInt(setCategoryChance) + nullCheckInt(setCategoryStarWarsDay) + nullCheckInt(setCategoryR2D2); + nullCheckInt(setCategoryFullHouse) + nullCheckInt(setCategorySmallStreet)
+ nullCheckInt(setCategoryBigStreet) + nullCheckInt(setCategoryYahtzee)
+ nullCheckInt(setCategoryChance) + nullCheckInt(setCategoryStarWarsDay)
+ nullCheckInt(setCategoryR2D2);
else else
this.lowerBoxScore = nullCheckInt(setCategoryTripleMatch) + nullCheckInt(setCategoryFourOfAKind) + nullCheckInt(setCategoryFullHouse) + nullCheckInt(setCategorySmallStreet) this.lowerBoxScore = nullCheckInt(setCategoryTripleMatch) + nullCheckInt(setCategoryFourOfAKind)
+ nullCheckInt(setCategoryBigStreet) + nullCheckInt(setCategoryYahtzee) + nullCheckInt(setCategoryChance) + nullCheckInt(setCategoryStarWarsDay); + nullCheckInt(setCategoryFullHouse) + nullCheckInt(setCategorySmallStreet)
+ nullCheckInt(setCategoryBigStreet) + nullCheckInt(setCategoryYahtzee)
+ nullCheckInt(setCategoryChance) + nullCheckInt(setCategoryStarWarsDay);
} }

View File

@ -68,6 +68,11 @@ public class YahtzeeGame {
} }
public int getLockedInDiceAmount(int player) {
return players.get(player).hand.getLockedInDiceAmount();
}
public void lockInDices(int player, String... dices) { public void lockInDices(int player, String... dices) {
if (dices[0].equals("none")) if (dices[0].equals("none"))
@ -138,6 +143,12 @@ public class YahtzeeGame {
} }
public boolean onlyOneOption(int player) {
return players.get(player).box.onlyOneOption();
}
public String selectedOptionsPrinted(int player) { public String selectedOptionsPrinted(int player) {
return players.get(player).box.selectedOptionsPrinted(player); return players.get(player).box.selectedOptionsPrinted(player);
@ -172,8 +183,29 @@ public class YahtzeeGame {
String highscores[][] = new String[10][3]; String highscores[][] = new String[10][3];
Scanner sc = new Scanner(new File("src/csv/highscores.csv")); Scanner sc = new Scanner(new File("src/csv/highscores.csv"));
Scanner scSp = new Scanner(new File("src/csv/highscoresSpecial8.csv"));
String mem[] = new String[3]; String mem[] = new String[3];
if (savedGamemode.equals("Special8"))
for (int i = 0; i < 10; i++) {
if (scSp.hasNextLine()) {
mem = scSp.nextLine().split(" ");
highscores[i][0] = mem[0];
highscores[i][1] = mem[1];
highscores[i][2] = mem[2];
} else {
highscores[i][0] = "___";
highscores[i][1] = "___";
highscores[i][2] = "0";
}
}
else
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
if (sc.hasNextLine()) { if (sc.hasNextLine()) {
@ -192,6 +224,7 @@ public class YahtzeeGame {
} }
sc.close(); sc.close();
scSp.close();
return highscores; return highscores;
} }
@ -405,16 +438,27 @@ public class YahtzeeGame {
} }
PrintWriter out = new PrintWriter(new FileWriter("src/csv/highscores.csv", false)); PrintWriter out = new PrintWriter(new FileWriter("src/csv/highscores.csv", false));
PrintWriter outSp = new PrintWriter(new FileWriter("src/csv/highscoresSpecial8.csv", false));
if (savedGamemode.equals("Special8"))
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
out.print(highscores[i][0] + ": " + highscores[i][1] + ": " outSp.print(highscores[i][0] + " " + highscores[i][1] + " "
+ highscores[i][2]);
outSp.println();
}
else
for (int i = 0; i < 10; i++) {
out.print(highscores[i][0] + " " + highscores[i][1] + " "
+ highscores[i][2]); + highscores[i][2]);
out.println(); out.println();
} }
out.close(); out.close();
outSp.close();
} catch (Exception e) { } catch (Exception e) {
} }
@ -428,15 +472,16 @@ public class YahtzeeGame {
} }
public String showHighscores() throws FileNotFoundException { public String showHighscores(String gamemode) throws FileNotFoundException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
this.savedGamemode = gamemode;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
sb.append((i + 1) + ": " + refreshHighscoreList()[i][0]); sb.append((i + 1) + ": " + refreshHighscoreList()[i][0]);
sb.append(" " + refreshHighscoreList()[i][1]); sb.append(": " + refreshHighscoreList()[i][1]);
sb.append(" " + refreshHighscoreList()[i][2] + "\n"); sb.append(": " + refreshHighscoreList()[i][2] + "\n");
} }
@ -447,10 +492,15 @@ public class YahtzeeGame {
public void deleteHighscores() throws IOException { public void deleteHighscores() throws IOException {
PrintWriter out = new PrintWriter(new FileWriter("src/csv/highscores.csv", false)); PrintWriter out = new PrintWriter(new FileWriter("src/csv/highscores.csv", false));
PrintWriter outSp = new PrintWriter(new FileWriter("src/csv/highscoresSpecial8.csv", false));
if (savedGamemode.equals("Special8"))
outSp.print("");
else
out.print(""); out.print("");
out.close(); out.close();
outSp.close();
} }

View File

@ -17,14 +17,17 @@ public class TUI {
YahtzeeGame game = new YahtzeeGame() { YahtzeeGame game = new YahtzeeGame() {
}; };
System.out.println("\nMain menu:\n"); System.out.println("\nMain menu:");
System.out.println(">Play"); System.out.println(">Play");
System.out.println(">Highscores"); System.out.println(">Highscores");
choice = sc.nextLine(); choice = sc.nextLine();
if (choice.equals("Highscores")) { if (choice.equals("Highscores")) {
System.out.println(game.showHighscores()); System.out.println("\nChoose your gamemode:");
System.out.println(">Return"); System.out.println(">Normal");
System.out.println(">Special8");
System.out.println("\n" + game.showHighscores(sc.nextLine()));
System.out.println("\n>Return");
System.out.println(">Delete"); System.out.println(">Delete");
choice = sc.nextLine(); choice = sc.nextLine();
if (choice.equals("Return")) { if (choice.equals("Return")) {
@ -72,20 +75,24 @@ public class TUI {
if (game.gameOver(i)) if (game.gameOver(i))
continue; continue;
System.out.println("\nIts your turn " + game.getPlayerName(i)); System.out.println("\n\n\nIts your turn " + game.getPlayerName(i));
System.out.println("\nThis is your Yahtzee Box: "); System.out.println("\nThis is your Yahtzee Box: ");
System.out.println("\n" + game.selectedOptionsPrinted(i) + "\n"); System.out.println("\n" + game.selectedOptionsPrinted(i) + "\n");
while (!game.allDicesLockedIn(i) && !game.noMoreRolls(i)) { while (!game.allDicesLockedIn(i) && !game.noMoreRolls(i)) {
if (game.getLockedInDiceAmount(i) != 4)
System.out.println("Rolling dices... "); System.out.println("Rolling dices... ");
else
System.out.println("Rolling the last dice...");
game.rollDices(i); game.rollDices(i);
System.out.println("Free dices: " + game.getFreeDiceNumbers(i)); System.out.println("Free dices: " + game.getFreeDiceNumbers(i));
System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i)); System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i));
if (game.autoLockInDices(i)) { if (game.autoLockInDices(i)) {
System.out.println("\nNo rolls left auto locking dices....\n"); System.out.println("\nNo rolls left => auto locking dices...\n");
} }
if (!game.noMoreRolls(i)) { if (!game.noMoreRolls(i)) {
System.out.println( System.out.println(
@ -94,9 +101,9 @@ public class TUI {
game.lockInDices(i, choice.split(" ")); game.lockInDices(i, choice.split(" "));
if ((game.getLeftRolls(i)) != 1) if ((game.getLeftRolls(i)) != 1 && !game.allDicesLockedIn(i))
System.out.println("\n" + game.getLeftRolls(i) + " rolls left"); System.out.println("\n" + game.getLeftRolls(i) + " rolls left");
else if ((game.getLeftRolls(i)) == 1) else if ((game.getLeftRolls(i)) == 1 && !game.allDicesLockedIn(i))
System.out.println("\n" + game.getLeftRolls(i) + " roll left"); System.out.println("\n" + game.getLeftRolls(i) + " roll left");
} }
} }
@ -104,22 +111,27 @@ public class TUI {
System.out.println("\n\nLocked in dices: " + game.getLockedInDiceNumbers(i)); System.out.println("\n\nLocked in dices: " + game.getLockedInDiceNumbers(i));
System.out.println("Done locking in... Here are your options: "); System.out.println("Done locking in... Here are your options: ");
game.evaluateAllOptions(i); game.evaluateAllOptions(i);
System.out.println(game.optionsPrinted(i)); System.out.println("\n" + game.optionsPrinted(i));
if (game.onlyOneOption(i)) {
game.selectOption(i, game.getAllOptions(i).get(0).split(":")[0]);
System.out.println("Only one option possible => auto selecting option...");
} else {
System.out.println("Which option you want to select?: "); System.out.println("Which option you want to select?: ");
game.selectOption(i, sc.nextLine()); game.selectOption(i, sc.nextLine());
}
if (game.gameOver(i)) { if (game.gameOver(i)) {
System.out.println( System.out.println(
"Your game is over, here is your total score: " + game.returnTotalPoints(i)); "\n\nYour game is over, here is your total score: " + game.returnTotalPoints(i));
} }
} }
} }
System.out.println("The game is over, " + game.getWinnerMessage()); System.out.println("\n\nThe game is over, " + game.getWinnerMessage());
System.out.println("Saving all highscores to the highscore table..."); System.out.println("Saving all highscores to the highscore table...");
game.saveAllPlayersHighscores(); game.saveAllPlayersHighscores();
System.out.println( System.out.println(
"If you want to stop the programm type: 'stop', otherwise you will return to the main menu:"); "\nIf you want to stop the programm type: 'stop', otherwise you will return to the main menu:");
choice = sc.nextLine(); choice = sc.nextLine();
} }
} }