diff --git a/bin/csv/highscores.csv b/bin/csv/highscores.csv index e69de29..8b13789 100644 --- a/bin/csv/highscores.csv +++ b/bin/csv/highscores.csv @@ -0,0 +1 @@ + diff --git a/bin/domain/Box.class b/bin/domain/Box.class index 29b6b8b..b233fb2 100644 Binary files a/bin/domain/Box.class and b/bin/domain/Box.class differ diff --git a/bin/domain/Hand.class b/bin/domain/Hand.class index 0ec25ba..de6e16e 100644 Binary files a/bin/domain/Hand.class and b/bin/domain/Hand.class differ diff --git a/bin/facade/YahtzeeGame.class b/bin/facade/YahtzeeGame.class index a5c34a8..530daef 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 new file mode 100644 index 0000000..7ce44c2 Binary files /dev/null and b/bin/ui/TUI$1.class differ diff --git a/bin/ui/TUI.class b/bin/ui/TUI.class index 0e5cba4..5fa08a1 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 e69de29..8b13789 100644 --- a/src/csv/highscores.csv +++ b/src/csv/highscores.csv @@ -0,0 +1 @@ + diff --git a/src/domain/Hand.java b/src/domain/Hand.java index f0526ab..3669566 100644 --- a/src/domain/Hand.java +++ b/src/domain/Hand.java @@ -42,8 +42,10 @@ public class Hand { public int getLockedInDiceAmount() { - return lockedInDices.size(); - + if (lockedInDices != null) + return lockedInDices.size(); + else + return 0; } public void rollDices() { @@ -89,7 +91,7 @@ public class Hand { public ArrayList getLockedInDiceNumbers() { ArrayList res = new ArrayList<>(); - for (int i = 0; i < this.lockedInDices.size(); i++) { + for (int i = 0; i < getLockedInDiceAmount(); i++) { res.add(this.lockedInDices.get(i).getDiceNumber()); diff --git a/src/facade/YahtzeeGame.java b/src/facade/YahtzeeGame.java index af2dde1..3278e7f 100644 --- a/src/facade/YahtzeeGame.java +++ b/src/facade/YahtzeeGame.java @@ -1,5 +1,7 @@ package facade; +import java.io.File; +import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; @@ -151,10 +153,10 @@ public class YahtzeeGame { return 0; } - private String[][] refreshHighscoreList() { + private String[][] refreshHighscoreList() throws FileNotFoundException { String highscores[][] = new String[10][3]; - Scanner sc = new Scanner("src/csv/highscores.csv"); + Scanner sc = new Scanner(new File("src/csv/highscores.csv")); for (int i = 0; i < 10; i++) { @@ -162,7 +164,12 @@ public class YahtzeeGame { highscores[i][0] = sc.next(); highscores[i][1] = sc.next(); highscores[i][2] = sc.nextLine(); + } else { + highscores[i][0] = "___"; + highscores[i][1] = "___"; + highscores[i][2] = "0"; } + } sc.close(); @@ -402,7 +409,7 @@ public class YahtzeeGame { } - public String showHighscores() { + public String showHighscores() throws FileNotFoundException { StringBuilder sb = new StringBuilder(); diff --git a/src/ui/TUI.java b/src/ui/TUI.java index f8f7a69..863d494 100644 --- a/src/ui/TUI.java +++ b/src/ui/TUI.java @@ -1,9 +1,7 @@ package ui; import java.io.IOException; -import java.util.ArrayList; import java.util.Scanner; - import facade.YahtzeeGame; public class TUI { @@ -12,107 +10,106 @@ public class TUI { String choice = ""; Scanner sc = new Scanner(System.in); - boolean newGame = false; System.out.println("Yahtzee Star Wars Special!"); - while (newGame) { + while (!choice.equals("stop")) { + YahtzeeGame game = new YahtzeeGame() { }; + System.out.println("Main menu:\n"); + System.out.println(">Play"); + System.out.println(">Highscores"); + choice = sc.nextLine(); - while (!choice.equals("stop")) { - - System.out.println("Main menu:\n"); - System.out.println(">Play"); - System.out.println(">Highscores"); + if (choice.equals("Highscores")) { + System.out.println(game.showHighscores()); + System.out.println(">Return"); + System.out.println(">Delete"); choice = sc.nextLine(); + if (choice.equals("Return")) { + } - if (choice.equals("Highscores")) { - System.out.println(game.showHighscores()); - System.out.println(">Return"); - System.out.println(">Delete"); + 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]"); + 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()) { - String playerNames[] = new String[game.playerCount]; for (int i = 0; i < game.playerCount; i++) { - playerNames[i] = sc.nextLine(); - } - game.setPlayerNames(playerNames); + if (game.gameOver(i)) + continue; - while (!game.gameOverAll()) { + System.out.println("Its your turn " + game.getPlayerName(i)); + System.out.println("This is your Yahtzee Box: "); + System.out.println(game.selectedOptionsPrinted(i) + "\n"); - for (int i = 0; i < game.playerCount; i++) { + while (!game.allDicesLockedIn(i) || !game.noMoreRolls(i)) { - if (game.gameOver(i)) - continue; + 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("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("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()); - 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)); - } + 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(); - } + + System.out.println("The 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:"); + choice = sc.nextLine(); } } } - }