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
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
2024-04-30 Selim 254
2024-04-30 Enes 127
2024-04-30 David 82
___ ___ 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
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
___: ___: 0
2024-04-30 Selim 254
2024-04-30 Enes 127
2024-04-30 David 82
___ ___ 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

@ -128,7 +128,7 @@ public class Box {
sumOfAllNumbers += diceNumbers.get(i);
}
categoryStarWarsDay = (counter[3]*4) + (counter[4]*5);
categoryStarWarsDay = (counter[3] * 4) + (counter[4] * 5);
categoryChance = sumOfAllNumbers;
for (int i = 0; i < counter.length; i++) {
@ -153,10 +153,10 @@ public class Box {
}
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;
}
@ -247,10 +247,17 @@ public class Box {
if (setCategoryR2D2 == null && savedGamemode.equals("Special8"))
res.add("R2D2: " + categoryR2D2);
}
return res;
}
public boolean onlyOneOption() {
return getAllOptions().size() == 1;
}
public void selectOption(String option) {
if (option.equals("One"))
@ -359,20 +366,23 @@ public class Box {
}
public void updateBonus(){
public void updateBonus() {
if(savedGamemode.equals("Special8")){
if (savedGamemode.equals("Special8")) {
if(nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(setCategorySeven) + nullCheckInt(setCategoryEight) >= 108){
if (nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree)
+ nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(setCategorySeven)
+ nullCheckInt(setCategoryEight) >= 108) {
this.bonus = 35;
}
} else
if(nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) >= 63){
this.bonus = 35;
if (nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree)
+ nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) >= 63) {
this.bonus = 35;
}
}
@ -381,7 +391,8 @@ public class Box {
if (savedGamemode.equals("Special8"))
return setCategoryOne + setCategoryTwo + setCategoryThree + setCategoryFour + setCategoryFive
+ setCategorySix + setCategorySeven + setCategoryEight + nullCheckInt(bonus) + setCategoryTripleMatch
+ setCategorySix + setCategorySeven + setCategoryEight + nullCheckInt(bonus)
+ setCategoryTripleMatch
+ setCategoryFourOfAKind
+ setCategoryFullHouse + setCategorySmallStreet + setCategoryBigStreet + setCategoryYahtzee
+ setCategoryChance + setCategoryStarWarsDay
@ -451,45 +462,47 @@ public class Box {
}
public void updateUpperBoxScore(){
public void updateUpperBoxScore() {
if(savedGamemode.equals("Special8"))
if (savedGamemode.equals("Special8"))
this.upperBoxScore = nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(setCategorySeven) + nullCheckInt(setCategoryEight) + nullCheckInt(bonus);
this.upperBoxScore = nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo)
+ nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(setCategorySeven)
+ nullCheckInt(setCategoryEight) + nullCheckInt(bonus);
else
this.upperBoxScore = nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo) + nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour)
+ nullCheckInt(setCategoryFive) + nullCheckInt(setCategorySix) + nullCheckInt(bonus);
this.upperBoxScore = nullCheckInt(setCategoryOne) + nullCheckInt(setCategoryTwo)
+ nullCheckInt(setCategoryThree) + nullCheckInt(setCategoryFour)
+ 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)
+ nullCheckInt(setCategoryBigStreet) + nullCheckInt(setCategoryYahtzee) + nullCheckInt(setCategoryChance) + nullCheckInt(setCategoryStarWarsDay) + nullCheckInt(setCategoryR2D2);
this.lowerBoxScore = nullCheckInt(setCategoryTripleMatch) + nullCheckInt(setCategoryFourOfAKind)
+ nullCheckInt(setCategoryFullHouse) + nullCheckInt(setCategorySmallStreet)
+ nullCheckInt(setCategoryBigStreet) + nullCheckInt(setCategoryYahtzee)
+ nullCheckInt(setCategoryChance) + nullCheckInt(setCategoryStarWarsDay)
+ nullCheckInt(setCategoryR2D2);
else
this.lowerBoxScore = nullCheckInt(setCategoryTripleMatch) + nullCheckInt(setCategoryFourOfAKind) + nullCheckInt(setCategoryFullHouse) + nullCheckInt(setCategorySmallStreet)
+ nullCheckInt(setCategoryBigStreet) + nullCheckInt(setCategoryYahtzee) + nullCheckInt(setCategoryChance) + nullCheckInt(setCategoryStarWarsDay);
this.lowerBoxScore = nullCheckInt(setCategoryTripleMatch) + nullCheckInt(setCategoryFourOfAKind)
+ nullCheckInt(setCategoryFullHouse) + nullCheckInt(setCategorySmallStreet)
+ nullCheckInt(setCategoryBigStreet) + nullCheckInt(setCategoryYahtzee)
+ nullCheckInt(setCategoryChance) + nullCheckInt(setCategoryStarWarsDay);
}
public void updateTotalScore(){
public void updateTotalScore() {
this.totalScore = nullCheckInt(upperBoxScore) + nullCheckInt(lowerBoxScore);
}
public String nullCheck(Integer i) {
if (i == null)
@ -500,7 +513,7 @@ public class Box {
public int nullCheckInt(Integer i) {
if(i == null)
if (i == null)
return 0;
else
return i;

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) {
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) {
return players.get(player).box.selectedOptionsPrinted(player);
@ -172,26 +183,48 @@ public class YahtzeeGame {
String highscores[][] = new String[10][3];
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];
for (int i = 0; i < 10; i++) {
if (savedGamemode.equals("Special8"))
if (sc.hasNextLine()) {
for (int i = 0; i < 10; i++) {
mem = sc.nextLine().split(" ");
highscores[i][0] = mem[0];
highscores[i][1] = mem[1];
highscores[i][2] = mem[2];
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++) {
if (sc.hasNextLine()) {
mem = sc.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 {
highscores[i][0] = "___";
highscores[i][1] = "___";
highscores[i][2] = "0";
}
}
sc.close();
scSp.close();
return highscores;
}
@ -405,16 +438,27 @@ public class YahtzeeGame {
}
PrintWriter out = new PrintWriter(new FileWriter("src/csv/highscores.csv", false));
PrintWriter outSp = new PrintWriter(new FileWriter("src/csv/highscoresSpecial8.csv", false));
for (int i = 0; i < 10; i++) {
if (savedGamemode.equals("Special8"))
for (int i = 0; i < 10; i++) {
out.print(highscores[i][0] + ": " + highscores[i][1] + ": "
+ highscores[i][2]);
outSp.print(highscores[i][0] + " " + highscores[i][1] + " "
+ highscores[i][2]);
out.println();
}
outSp.println();
}
else
for (int i = 0; i < 10; i++) {
out.print(highscores[i][0] + " " + highscores[i][1] + " "
+ highscores[i][2]);
out.println();
}
out.close();
outSp.close();
} 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();
this.savedGamemode = gamemode;
for (int i = 0; i < 10; i++) {
sb.append((i + 1) + ": " + refreshHighscoreList()[i][0]);
sb.append(" " + refreshHighscoreList()[i][1]);
sb.append(" " + refreshHighscoreList()[i][2] + "\n");
sb.append(": " + refreshHighscoreList()[i][1]);
sb.append(": " + refreshHighscoreList()[i][2] + "\n");
}
@ -447,10 +492,15 @@ public class YahtzeeGame {
public void deleteHighscores() throws IOException {
PrintWriter out = new PrintWriter(new FileWriter("src/csv/highscores.csv", false));
PrintWriter outSp = new PrintWriter(new FileWriter("src/csv/highscoresSpecial8.csv", false));
out.print("");
if (savedGamemode.equals("Special8"))
outSp.print("");
else
out.print("");
out.close();
outSp.close();
}

View File

@ -17,14 +17,17 @@ public class TUI {
YahtzeeGame game = new YahtzeeGame() {
};
System.out.println("\nMain menu:\n");
System.out.println("\nMain menu:");
System.out.println(">Play");
System.out.println(">Highscores");
choice = sc.nextLine();
if (choice.equals("Highscores")) {
System.out.println(game.showHighscores());
System.out.println(">Return");
System.out.println("\nChoose your gamemode:");
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");
choice = sc.nextLine();
if (choice.equals("Return")) {
@ -72,20 +75,24 @@ public class TUI {
if (game.gameOver(i))
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("\n" + game.selectedOptionsPrinted(i) + "\n");
while (!game.allDicesLockedIn(i) && !game.noMoreRolls(i)) {
System.out.println("Rolling dices... ");
if (game.getLockedInDiceAmount(i) != 4)
System.out.println("Rolling dices... ");
else
System.out.println("Rolling the last dice...");
game.rollDices(i);
System.out.println("Free dices: " + game.getFreeDiceNumbers(i));
System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i));
if(game.autoLockInDices(i)){
System.out.println("\nNo rolls left auto locking dices....\n");
if (game.autoLockInDices(i)) {
System.out.println("\nNo rolls left => auto locking dices...\n");
}
if (!game.noMoreRolls(i)) {
System.out.println(
@ -94,9 +101,9 @@ public class TUI {
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");
else if ((game.getLeftRolls(i)) == 1)
else if ((game.getLeftRolls(i)) == 1 && !game.allDicesLockedIn(i))
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("Done locking in... Here are your options: ");
game.evaluateAllOptions(i);
System.out.println(game.optionsPrinted(i));
System.out.println("Which option you want to select?: ");
game.selectOption(i, sc.nextLine());
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?: ");
game.selectOption(i, sc.nextLine());
}
if (game.gameOver(i)) {
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...");
game.saveAllPlayersHighscores();
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();
}
}