diff --git a/bin/domain/Box.class b/bin/domain/Box.class index b233fb2..bb0735c 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 4a4ca3c..c6665ca 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 de6e16e..8767774 100644 Binary files a/bin/domain/Hand.class and b/bin/domain/Hand.class differ diff --git a/bin/ui/TUI.class b/bin/ui/TUI.class index 5fa08a1..fe70f11 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 2712887..24d1743 100644 --- a/src/domain/Box.java +++ b/src/domain/Box.java @@ -265,7 +265,7 @@ public class Box { else if (option.equals("categoryBigStreet")) setCategoryBigStreet = categoryBigStreet; else if (option.equals("categoryYahtzee")) { - if (setCategoryYahtzee > 0) { + if (setCategoryYahtzee != null) { setCategoryYahtzee += 50; if (counter[0] == 5) setCategoryOne = 5; diff --git a/src/domain/Dice.java b/src/domain/Dice.java index dbce06c..31e2724 100644 --- a/src/domain/Dice.java +++ b/src/domain/Dice.java @@ -1,5 +1,7 @@ package domain; +import java.lang.Math; + public class Dice { private int diceNumber; @@ -8,9 +10,9 @@ public class Dice { public Dice(String gamemode) { this.savedGamemode = gamemode; if (gamemode.equals("Normal") || gamemode.equals("StarWarsDay")) - this.diceNumber = (int) Math.random() * 6 + 1; + this.diceNumber = ((int) (Math.random() * 6)) + 1; else if (gamemode.equals("Special8")) - this.diceNumber = (int) Math.random() * 8 + 1; + this.diceNumber = ((int) (Math.random() * 8)) + 1; } public Dice(String gamemode, int diceNumber) { @@ -21,9 +23,9 @@ public class Dice { public void rerollDice() { if (this.savedGamemode.equals("Normal") || this.savedGamemode.equals("StarWarsDay")) - this.diceNumber = (int) Math.random() * 6 + 1; + this.diceNumber = ((int) (Math.random() * 6)) + 1; else if (this.savedGamemode.equals("Special8")) - this.diceNumber = (int) Math.random() * 8 + 1; + this.diceNumber = ((int) (Math.random() * 8)) + 1; } diff --git a/src/domain/Hand.java b/src/domain/Hand.java index 3669566..310a672 100644 --- a/src/domain/Hand.java +++ b/src/domain/Hand.java @@ -5,15 +5,15 @@ import java.util.ArrayList; public class Hand { private ArrayList dices = new ArrayList<>(5); - private ArrayList lockedInDices; - private int leftRolls = 2; + private ArrayList lockedInDices = new ArrayList<>(); + private int leftRolls = 3; private String savedGamemode; public Hand(String gamemode) { this.savedGamemode = gamemode; - for (int i = 0; i < dices.size(); i++) { + for (int i = 0; i < 5; i++) { dices.add(i, new Dice(gamemode)); @@ -56,6 +56,12 @@ public class Hand { } leftRolls--; + + if (this.leftRolls == 1) + for (int i = 0; i < this.dices.size(); i++) { + lockInDice(this.dices.get(i).getDiceNumber()); + } + } public ArrayList getAllDiceNumbers() { diff --git a/src/ui/TUI.java b/src/ui/TUI.java index 863d494..d773683 100644 --- a/src/ui/TUI.java +++ b/src/ui/TUI.java @@ -17,7 +17,7 @@ public class TUI { YahtzeeGame game = new YahtzeeGame() { }; - System.out.println("Main menu:\n"); + System.out.println("\nMain menu:\n"); System.out.println(">Play"); System.out.println(">Highscores"); choice = sc.nextLine(); @@ -32,11 +32,11 @@ public class TUI { 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': "); + "\nAre 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..."); + System.out.println("\nHighscore file got deleted...\nReturning to the main menu..."); } else { System.out.println("Highscore file not deleted...\nReturning to the main menu..."); } @@ -47,18 +47,19 @@ public class TUI { else if (choice.equals("Play")) { - System.out.println("Choose your gamemode: "); + System.out.println("\nChoose 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("\nAmount 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: "); + game.setPlayercount(Integer.parseInt(sc.nextLine())); + System.out.println("\nType 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(); } @@ -72,26 +73,31 @@ public class TUI { 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"); + System.out.println("\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)) { + while (!game.allDicesLockedIn(i) && !game.noMoreRolls(i)) { + + System.out.println("Rolling dices... "); + game.rollDices(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... "); + + if ((game.getLeftRolls(i)) != 1) + System.out.println("\n" + game.getLeftRolls(i) + " rolls left"); + else + System.out.println("\n" + game.getLeftRolls(i) + " roll left"); } System.out.println("Done locking in... Here are your options: "); + System.out.println("Locked in dices: " + game.getLockedInDiceNumbers(i)); System.out.println(game.optionsPrinted(i)); System.out.println("Which option you want to select?: "); game.selectOption(i, sc.nextLine());