diff --git a/bin/domain/Box.class b/bin/domain/Box.class index a173d93..29b6b8b 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 abcd61a..4a4ca3c 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 3e90cd4..0ec25ba 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 48bd58a..a5c34a8 100644 Binary files a/bin/facade/YahtzeeGame.class and b/bin/facade/YahtzeeGame.class differ diff --git a/bin/ui/TUI.class b/bin/ui/TUI.class index 0f845fa..0e5cba4 100644 Binary files a/bin/ui/TUI.class and b/bin/ui/TUI.class differ diff --git a/src/domain/Box.java b/src/domain/Box.java index 3e7afda..2712887 100644 --- a/src/domain/Box.java +++ b/src/domain/Box.java @@ -348,4 +348,53 @@ public class Box { } + public String selectedOptionsPrinted(int player) { + + StringBuilder sb = new StringBuilder(); + + if (savedGamemode.equals("Special8")) { + sb.append("categoryOne: " + nullCheck(setCategoryOne) + "\n"); + sb.append("categoryTwo: " + nullCheck(setCategoryTwo) + "\n"); + sb.append("categoryThree: " + nullCheck(setCategoryThree) + "\n"); + sb.append("categoryFour: " + nullCheck(setCategoryFour) + "\n"); + sb.append("categoryFive: " + nullCheck(setCategoryFive) + "\n"); + sb.append("categorySix: " + nullCheck(setCategorySix) + "\n"); + sb.append("categorySeven: " + nullCheck(setCategorySeven) + "\n"); + sb.append("categoryEight: " + nullCheck(setCategoryEight) + "\n"); + sb.append("\n--------------------------\n\n"); + sb.append("categoryTripleMatch: " + nullCheck(setCategoryTripleMatch) + "\n"); + sb.append("categoryFourOfAKind: " + nullCheck(setCategoryFourOfAKind) + "\n"); + sb.append("categoryFullHouse: " + nullCheck(setCategoryFullHouse) + "\n"); + sb.append("categorySmallStreet: " + nullCheck(setCategorySmallStreet) + "\n"); + sb.append("categoryBigStreet: " + nullCheck(setCategoryBigStreet) + "\n"); + sb.append("categoryYahtzee: " + nullCheck(setCategoryYahtzee) + "\n"); + sb.append("categoryChance: " + nullCheck(setCategoryChance) + "\n"); + sb.append("categoryR2D2: " + nullCheck(setCategoryR2D2) + "\n"); + } else { + sb.append("categoryOne: " + nullCheck(setCategoryOne) + "\n"); + sb.append("categoryTwo: " + nullCheck(setCategoryTwo) + "\n"); + sb.append("categoryThree: " + nullCheck(setCategoryThree) + "\n"); + sb.append("categoryFour: " + nullCheck(setCategoryFour) + "\n"); + sb.append("categoryFive: " + nullCheck(setCategoryFive) + "\n"); + sb.append("categorySix: " + nullCheck(setCategorySix) + "\n"); + sb.append("\n--------------------------\n\n"); + sb.append("categoryTripleMatch: " + nullCheck(setCategoryTripleMatch) + "\n"); + sb.append("categoryFourOfAKind: " + nullCheck(setCategoryFourOfAKind) + "\n"); + sb.append("categoryFullHouse: " + nullCheck(setCategoryFullHouse) + "\n"); + sb.append("categorySmallStreet: " + nullCheck(setCategorySmallStreet) + "\n"); + sb.append("categoryBigStreet: " + nullCheck(setCategoryBigStreet) + "\n"); + sb.append("categoryYahtzee: " + nullCheck(setCategoryYahtzee) + "\n"); + sb.append("categoryChance: " + nullCheck(setCategoryChance) + "\n"); + } + return sb.toString(); + + } + + public String nullCheck(Integer i) { + + if (i == null) + return "___"; + else + return "" + i; + } } diff --git a/src/domain/Hand.java b/src/domain/Hand.java index 89fa2d4..f0526ab 100644 --- a/src/domain/Hand.java +++ b/src/domain/Hand.java @@ -33,13 +33,19 @@ public class Hand { } - public void lockInDices(int... dices) { + public void lockInDices(String... dices) { for (int i = 0; i < dices.length; i++) { - lockInDice(dices[i]); + lockInDice(Integer.parseInt(dices[i])); } } + public int getLockedInDiceAmount() { + + return lockedInDices.size(); + + } + public void rollDices() { if (this.leftRolls > 0) @@ -96,4 +102,5 @@ public class Hand { return this.leftRolls; } + } diff --git a/src/facade/YahtzeeGame.java b/src/facade/YahtzeeGame.java index 369c3b1..af2dde1 100644 --- a/src/facade/YahtzeeGame.java +++ b/src/facade/YahtzeeGame.java @@ -9,42 +9,39 @@ import java.util.Scanner; import domain.Player; - - public class YahtzeeGame { public int playerCount; public ArrayList players = new ArrayList<>(); public String savedGamemode; - public YahtzeeGame() { } - public void setPlayercount(int playerCount){ + public void setPlayercount(int playerCount) { this.playerCount = playerCount; - + } - public void setPlayerNames(String... names){ + public void setPlayerNames(String... names) { for (int i = 0; i < this.playerCount; i++) { this.players.add(new Player(names[i], this.savedGamemode)); } - + } - - public String getPlayerName(int player){ + + public String getPlayerName(int player) { return players.get(player).name; } - - public void setGamemode(String gamemode){ + + public void setGamemode(String gamemode) { this.savedGamemode = gamemode; - + } - + public void rollDices(int player) { players.get(player).hand.rollDices(); @@ -69,21 +66,35 @@ public class YahtzeeGame { } - public void lockInDices(int player, int... dices) { + public void lockInDices(int player, String... dices) { + if (dices[0].equals("none")) + return; players.get(player).hand.lockInDices(dices); } + public boolean allDicesLockedIn(int player) { + + return players.get(player).hand.getLockedInDiceAmount() == 5; + + } + public int getLeftRolls(int player) { return players.get(player).hand.getLeftRolls(); } + public boolean noMoreRolls(int player) { + + return 0 == getLeftRolls(player); + + } + public ArrayList getAllOptionsEvaluated(int player) { - players.get(player).box.evaluateBoxOptions(players.get(player - 1).hand.getAllDiceNumbers()); + players.get(player).box.evaluateBoxOptions(players.get(player).hand.getAllDiceNumbers()); return players.get(player).box.getAllOptions(); } @@ -96,23 +107,42 @@ public class YahtzeeGame { } + public String optionsPrinted(int player) { + + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < getAllOptionsEvaluated(player).size(); i++) { + + sb.append(getAllOptionsEvaluated(player).get(i) + "\n"); + + } + + return sb.toString(); + + } + + public String selectedOptionsPrinted(int player) { + + return players.get(player).box.selectedOptionsPrinted(player); + } + public boolean gameOver(int player) { return players.get(player).box.gameOver(); } - public boolean gameOverAll(){ + public boolean gameOverAll() { int counter = 0; - - for(int i = 0; iPlay"); - System.out.println(">Highscores"); + + System.out.println("Main menu:\n"); + 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(">Delete"); choice = sc.nextLine(); - - if(choice.equals("Highscores")){ - System.out.println(game.showHighscores()); - System.out.println(">Return"); - System.out.println(">Delete"); + if (choice.equals("Return")) + break; + else if (choice.equals("Delete")) { + System.out.println( + "Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': "); choice = sc.nextLine(); - if(choice.equals("Return")) - break; - else if(choice.equals("Delete")){ - System.out.println("Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': "); - choice = sc.nextLine(); - if(choice.equals("I AM SURE")){ - game.deleteHighscores(); - System.out.println("Highscore file got deleted...\nReturning to the main menu..."); - } - else{ - System.out.println("Highscore file not deleted...\nReturning to the main menu..."); - } - + if (choice.equals("I AM SURE")) { + game.deleteHighscores(); + System.out.println("Highscore file got deleted...\nReturning to the main menu..."); + } else { + System.out.println("Highscore file not deleted...\nReturning to the main menu..."); } } - - else if(choice.equals("Play")){ - - System.out.println("Choose your gamemode: "); - System.out.println(">Normal"); - System.out.println(">StarWarsDay"); - System.out.println(">Special8"); - game.setGamemode(sc.nextLine()); - System.out.println("Amount of players: "); - System.out.println(">1-6"); - game.setPlayercount(sc.nextInt()); - System.out.println("Type in the player names, lock in each name with Enter: "); - System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]"); - - String playerNames[] = new String[game.playerCount]; - for(int i = 0; i < game.playerCount; i++){ - playerNames[i] = sc.nextLine(); - } - - game.setPlayerNames(playerNames); - - while (!game.gameOverAll()) { - - for(int i = 0; iNormal"); + System.out.println(">StarWarsDay"); + System.out.println(">Special8"); + game.setGamemode(sc.nextLine()); + System.out.println("Amount of players: "); + System.out.println(">1-6"); + game.setPlayercount(sc.nextInt()); + System.out.println("Type in the player names, lock in each name with Enter: "); + System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]"); + + String playerNames[] = new String[game.playerCount]; + for (int i = 0; i < game.playerCount; i++) { + playerNames[i] = sc.nextLine(); + } + + game.setPlayerNames(playerNames); + + while (!game.gameOverAll()) { + + for (int i = 0; i < game.playerCount; i++) { + + if (game.gameOver(i)) + continue; + + System.out.println("Its your turn " + game.getPlayerName(i)); + System.out.println("This is your Yahtzee Box: "); + System.out.println(game.selectedOptionsPrinted(i) + "\n"); + + while (!game.allDicesLockedIn(i) || !game.noMoreRolls(i)) { + + System.out.println("Your dices: "); + System.out.println("Free dices: " + game.getFreeDiceNumbers(i)); + System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i)); + System.out.println( + "Type in which free dices you want to keep \n(seperated by space, type 'none' if you dont want to keep any): "); + choice = sc.nextLine(); + game.lockInDices(i, choice.split(" ")); + game.rollDices(i); + System.out.println(game.getLeftRolls(i) + " rolls left"); + System.out.println("Rerolling dices... "); + + } + + System.out.println("Done locking in... Here are your options: "); + System.out.println(game.optionsPrinted(i)); + 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)); + } + } + } + + System.out.println("The game is over, saving all highscores to the highscore table..."); + game.saveAllPlayersHighscores(); + + } + } } }