diff --git a/bin/csv/highscores.csv b/bin/csv/highscores.csv index b7c8196..e76b1a3 100644 --- a/bin/csv/highscores.csv +++ b/bin/csv/highscores.csv @@ -7,4 +7,4 @@ ___ ___ 0 ___ ___ 0 ___ ___ 0 -___ ___ 0 +___ ___ 0 \ No newline at end of file diff --git a/bin/domain/Box.class b/bin/domain/Box.class index 6cdd89b..e00b440 100644 Binary files a/bin/domain/Box.class and b/bin/domain/Box.class differ diff --git a/bin/domain/Player.class b/bin/domain/Player.class index dc8b686..66f3cb1 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 85e7b0e..cb14354 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 cf65bfd..a7f4bef 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 b7c8196..e76b1a3 100644 --- a/src/csv/highscores.csv +++ b/src/csv/highscores.csv @@ -7,4 +7,4 @@ ___ ___ 0 ___ ___ 0 ___ ___ 0 -___ ___ 0 +___ ___ 0 \ No newline at end of file diff --git a/src/domain/Box.java b/src/domain/Box.java index 6eaf018..c33d82f 100644 --- a/src/domain/Box.java +++ b/src/domain/Box.java @@ -406,7 +406,7 @@ public class Box { } - public String selectedOptionsPrinted(int player) { + public String selectedOptionsPrinted() { StringBuilder sb = new StringBuilder(); diff --git a/src/domain/Player.java b/src/domain/Player.java index ad39041..dc63d22 100644 --- a/src/domain/Player.java +++ b/src/domain/Player.java @@ -1,11 +1,13 @@ package domain; +import java.util.ArrayList; + public class Player { - public String name; - public Hand hand; - public Box box; - public String savedGamemode; + private String name; + private Hand hand; + private Box box; + private String savedGamemode; public Player(String name, String gamemode) { @@ -22,5 +24,103 @@ public class Player { } + public String getPlayername(){ + return this.name; + } + public void rollDices(){ + this.hand.rollDices(); + + } + + public int getLeftRolls(){ + + return hand.getLeftRolls(); + } + + public ArrayList getAllDiceNumbers(){ + + return hand.getAllDiceNumbers(); + } + + public ArrayList getFreeDiceNumbers(){ + + return hand.getFreeDiceNumbers(); + } + + public ArrayList getLockedInDiceNumbers(){ + + return hand.getLockedInDiceNumbers(); + } + + public int getLockedInDiceAmount(){ + return hand.getLockedInDiceAmount(); + + } + + public void lockInDices(String... dices){ + + hand.lockInDices(dices); + } + + public boolean autoLockInDices(){ + + return hand.autoLockInDices(); + } + + public boolean allDicesLockedIn(){ + return allDicesLockedIn(); + + } + + public void evaluateAllOptions(){ + + box.evaluateBoxOptions(hand.getLockedInDiceNumbers()); + } + public ArrayList getAllOptions(){ + return box.getAllOptions(); + } + public void selectOption(String selectedOption){ + + box.selectOption(selectedOption); + } + + public void resetOptions(){ + box.resetOptions(); + + } + + public void updateBonus(){ + box.updateBonus(); + } + + public void updateUpperBoxScore(){ + box.updateUpperBoxScore(); + } + + public void updateLowerBoxScore(){ + box.updateLowerBoxScore(); + } + + public void updateTotalScore(){ + box.updateTotalScore(); + } + + public boolean onlyOneOption(){ + + return box.onlyOneOption(); + } + + public String selectedOptionsPrinted(){ + + return box.selectedOptionsPrinted(); + } + public boolean gameOver(){ + + return box.gameOver(); + } + + public int returnTotalPoints(){ + return box.returnTotalPoints(); + } } diff --git a/src/facade/YahtzeeGame.java b/src/facade/YahtzeeGame.java index 9bc4714..fd24b22 100644 --- a/src/facade/YahtzeeGame.java +++ b/src/facade/YahtzeeGame.java @@ -37,7 +37,7 @@ public class YahtzeeGame { } public String getPlayerName(int player) { - return players.get(player).name; + return players.get(player).getPlayername(); } public void setGamemode(String gamemode) { @@ -47,56 +47,56 @@ public class YahtzeeGame { public void rollDices(int player) { - players.get(player).hand.rollDices(); + players.get(player).rollDices(); } public ArrayList getAllDiceNumbers(int player) { - return players.get(player).hand.getAllDiceNumbers(); + return players.get(player).getAllDiceNumbers(); } public ArrayList getFreeDiceNumbers(int player) { - return players.get(player).hand.getFreeDiceNumbers(); + return players.get(player).getFreeDiceNumbers(); } public ArrayList getLockedInDiceNumbers(int player) { - return players.get(player).hand.getLockedInDiceNumbers(); + return players.get(player).getLockedInDiceNumbers(); } public int getLockedInDiceAmount(int player) { - return players.get(player).hand.getLockedInDiceAmount(); + return players.get(player).getLockedInDiceAmount(); } public void lockInDices(int player, String... dices) { if (dices[0].equalsIgnoreCase("none")) return; - players.get(player).hand.lockInDices(dices); + players.get(player).lockInDices(dices); } public boolean autoLockInDices(int player) { - return players.get(player).hand.autoLockInDices(); + return players.get(player).autoLockInDices(); } public boolean allDicesLockedIn(int player) { - return players.get(player).hand.getLockedInDiceAmount() == 5; + return players.get(player).getLockedInDiceAmount() == 5; } public int getLeftRolls(int player) { - return players.get(player).hand.getLeftRolls(); + return players.get(player).getLeftRolls(); } @@ -108,25 +108,25 @@ public class YahtzeeGame { public void evaluateAllOptions(int player) { - players.get(player).box.evaluateBoxOptions(players.get(player).hand.getLockedInDiceNumbers()); + players.get(player).evaluateAllOptions(); } public ArrayList getAllOptions(int player) { - return players.get(player).box.getAllOptions(); + return players.get(player).getAllOptions(); } public void selectOption(int player, String selectedOption) { - players.get(player).box.selectOption(selectedOption); - players.get(player).box.resetOptions(); + players.get(player).selectOption(selectedOption); + players.get(player).resetOptions(); players.get(player).getNewHand(); - players.get(player).box.updateBonus(); - players.get(player).box.updateUpperBoxScore(); - players.get(player).box.updateLowerBoxScore(); - players.get(player).box.updateTotalScore(); + players.get(player).updateBonus(); + players.get(player).updateUpperBoxScore(); + players.get(player).updateLowerBoxScore(); + players.get(player).updateTotalScore(); } @@ -146,18 +146,18 @@ public class YahtzeeGame { public boolean onlyOneOption(int player) { - return players.get(player).box.onlyOneOption(); + return players.get(player).onlyOneOption(); } public String selectedOptionsPrinted(int player) { - return players.get(player).box.selectedOptionsPrinted(player); + return players.get(player).selectedOptionsPrinted(); } public boolean gameOver(int player) { - return players.get(player).box.gameOver(); + return players.get(player).gameOver(); } @@ -165,7 +165,7 @@ public class YahtzeeGame { int counter = 0; for (int i = 0; i < playerCount; i++) { - if (players.get(i).box.gameOver()) + if (players.get(i).gameOver()) counter++; } @@ -174,8 +174,8 @@ public class YahtzeeGame { public int returnTotalPoints(int player) { - if (players.get(player).box.gameOver()) - return players.get(player).box.returnTotalPoints(); + if (players.get(player).gameOver()) + return players.get(player).returnTotalPoints(); else return 0; } @@ -183,49 +183,35 @@ public class YahtzeeGame { private String[][] refreshHighscoreList() throws FileNotFoundException { 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]; - - if (savedGamemode.equalsIgnoreCase("Special8")) - - for (int i = 0; i < 10; i++) { - - 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"; - } - - } + String source; + + if(savedGamemode.equalsIgnoreCase("Special8")) + source = "src/csv/highscoresSpecial8.csv"; else + source = "src/csv/highscores.csv"; + + Scanner sc = new Scanner(new File(source)); - for (int i = 0; i < 10; i++) { - 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 (sc.hasNextLine()) { - } else { - highscores[i][0] = "___"; - highscores[i][1] = "___"; - highscores[i][2] = "0"; - } + 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"; } + } + sc.close(); - scSp.close(); return highscores; } @@ -252,7 +238,7 @@ public class YahtzeeGame { if (i == 2) highscores[0][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[0][i] = "" + players.get(player).name; + highscores[0][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[0][i] = "" + LocalDate.now(); highscoreMem2 = highscores[1][i]; @@ -281,7 +267,7 @@ public class YahtzeeGame { if (i == 2) highscores[1][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[1][i] = "" + players.get(player).name; + highscores[1][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[1][i] = "" + LocalDate.now(); highscoreMem1 = highscores[2][i]; @@ -307,7 +293,7 @@ public class YahtzeeGame { if (i == 2) highscores[2][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[2][i] = "" + players.get(player).name; + highscores[2][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[2][i] = "" + LocalDate.now(); highscoreMem2 = highscores[3][i]; @@ -331,7 +317,7 @@ public class YahtzeeGame { if (i == 2) highscores[3][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[3][i] = "" + players.get(player).name; + highscores[3][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[3][i] = "" + LocalDate.now(); highscoreMem1 = highscores[4][i]; @@ -353,7 +339,7 @@ public class YahtzeeGame { if (i == 2) highscores[4][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[4][i] = "" + players.get(player).name; + highscores[4][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[4][i] = "" + LocalDate.now(); highscoreMem2 = highscores[5][i]; @@ -373,7 +359,7 @@ public class YahtzeeGame { if (i == 2) highscores[5][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[5][i] = "" + players.get(player).name; + highscores[5][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[5][i] = "" + LocalDate.now(); highscoreMem1 = highscores[6][i]; @@ -391,7 +377,7 @@ public class YahtzeeGame { if (i == 2) highscores[6][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[6][i] = "" + players.get(player).name; + highscores[6][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[6][i] = "" + LocalDate.now(); highscoreMem2 = highscores[7][i]; @@ -407,7 +393,7 @@ public class YahtzeeGame { if (i == 2) highscores[7][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[7][i] = "" + players.get(player).name; + highscores[7][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[7][i] = "" + LocalDate.now(); highscoreMem1 = highscores[8][i]; @@ -421,7 +407,7 @@ public class YahtzeeGame { if (i == 2) highscores[8][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[8][i] = "" + players.get(player).name; + highscores[8][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[8][i] = "" + LocalDate.now(); highscores[9][i] = highscoreMem1; @@ -432,34 +418,31 @@ public class YahtzeeGame { if (i == 2) highscores[9][i] = "" + returnTotalPoints(player); else if (i == 1) - highscores[9][i] = "" + players.get(player).name; + highscores[9][i] = "" + players.get(player).getPlayername(); else if (i == 0) highscores[9][i] = "" + LocalDate.now(); } } - PrintWriter out = new PrintWriter(new FileWriter("src/csv/highscores.csv", false)); - PrintWriter outSp = new PrintWriter(new FileWriter("src/csv/highscoresSpecial8.csv", false)); - - if (savedGamemode.equalsIgnoreCase("Special8")) - for (int i = 0; i < 10; i++) { - - outSp.print(highscores[i][0] + " " + highscores[i][1] + " " - + highscores[i][2]); - - outSp.println(); - } + String source; + + if(savedGamemode.equalsIgnoreCase("Special8")) + source = "src/csv/highscoresSpecial8.csv"; else - for (int i = 0; i < 10; i++) { + source = "src/csv/highscores.csv"; + + PrintWriter out = new PrintWriter(new FileWriter(source)); - out.print(highscores[i][0] + " " + highscores[i][1] + " " - + highscores[i][2]); + + for (int i = 0; i < 10; i++) { - out.println(); - } + out.print(highscores[i][0] + " " + highscores[i][1] + " " + + highscores[i][2]); + + out.println(); + } out.close(); - outSp.close(); } catch (Exception e) { } @@ -492,16 +475,18 @@ 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)); - - if (savedGamemode.equalsIgnoreCase("Special8")) - outSp.print(""); + String source; + + if(savedGamemode.equalsIgnoreCase("Special8")) + source = "src/csv/highscoresSpecial8.csv"; else - out.print(""); + source = "src/csv/highscores.csv"; + + PrintWriter out = new PrintWriter(new FileWriter(source)); + + out.print(""); out.close(); - outSp.close(); } diff --git a/src/ui/TUI.java b/src/ui/TUI.java index 797ebfa..a05fd1d 100644 --- a/src/ui/TUI.java +++ b/src/ui/TUI.java @@ -32,12 +32,7 @@ public class TUI { System.out.println("\nChoose your gamemode:"); System.out.println(">Normal"); System.out.println(">Special8"); - choice = sc.nextLine(); - if(choice.equalsIgnoreCase("Special8")) - game.setGamemode("Special8"); - else - game.setGamemode("Normal"); - System.out.println("\n" + game.showHighscores(choice)); + System.out.println("\n" + game.showHighscores(sc.nextLine())); } catch (FileNotFoundException e) { System.out.println("\nHighscore file not found!\n"); notFound = true;