diff --git a/bin/csv/highscores.csv b/bin/csv/highscores.csv index e361fb1..d458538 100644 --- a/bin/csv/highscores.csv +++ b/bin/csv/highscores.csv @@ -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 diff --git a/bin/csv/highscoresSpecial8.csv b/bin/csv/highscoresSpecial8.csv new file mode 100644 index 0000000..e69de29 diff --git a/bin/domain/Box.class b/bin/domain/Box.class index f5e47de..3a59645 100644 Binary files a/bin/domain/Box.class and b/bin/domain/Box.class differ diff --git a/bin/domain/Dice.class b/bin/domain/Dice.class index e5e2cff..84b2350 100644 Binary files a/bin/domain/Dice.class and b/bin/domain/Dice.class differ diff --git a/bin/domain/Hand.class b/bin/domain/Hand.class index e8f03e9..986e04a 100644 Binary files a/bin/domain/Hand.class and b/bin/domain/Hand.class differ diff --git a/bin/domain/Player.class b/bin/domain/Player.class index dc8b686..e97c803 100644 Binary files a/bin/domain/Player.class and b/bin/domain/Player.class differ diff --git a/bin/facade/YahtzeeGame.class b/bin/facade/YahtzeeGame.class index ced5c5a..3ce2371 100644 Binary files a/bin/facade/YahtzeeGame.class and b/bin/facade/YahtzeeGame.class differ diff --git a/bin/ui/TUI$1.class b/bin/ui/TUI$1.class index 9f5a14e..7ce44c2 100644 Binary files a/bin/ui/TUI$1.class and b/bin/ui/TUI$1.class differ diff --git a/bin/ui/TUI.class b/bin/ui/TUI.class index 8d9a00b..10aa1c2 100644 Binary files a/bin/ui/TUI.class and b/bin/ui/TUI.class differ diff --git a/src/csv/highscores.csv b/src/csv/highscores.csv index e361fb1..d458538 100644 --- a/src/csv/highscores.csv +++ b/src/csv/highscores.csv @@ -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 diff --git a/src/csv/highscoresSpecial8.csv b/src/csv/highscoresSpecial8.csv new file mode 100644 index 0000000..e69de29 diff --git a/src/domain/Box.java b/src/domain/Box.java index fe78e2a..c53ab7f 100644 --- a/src/domain/Box.java +++ b/src/domain/Box.java @@ -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; diff --git a/src/facade/YahtzeeGame.java b/src/facade/YahtzeeGame.java index 786e8c1..92194b8 100644 --- a/src/facade/YahtzeeGame.java +++ b/src/facade/YahtzeeGame.java @@ -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(); } diff --git a/src/ui/TUI.java b/src/ui/TUI.java index b0ba1c0..5ba0c66 100644 --- a/src/ui/TUI.java +++ b/src/ui/TUI.java @@ -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(); } }