highscore set Exception handling
parent
0081a61c11
commit
549dc0a399
|
Binary file not shown.
|
|
@ -1,6 +1,11 @@
|
||||||
package facade;
|
package facade;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
import domain.Player;
|
import domain.Player;
|
||||||
|
|
||||||
|
@ -25,66 +30,310 @@ public class YahtzeeGame {
|
||||||
|
|
||||||
public void rollDices(int player) {
|
public void rollDices(int player) {
|
||||||
|
|
||||||
players.get(player - 1).hand.rollDices();
|
players.get(player).hand.rollDices();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Integer> getAllDiceNumbers(int player) {
|
public ArrayList<Integer> getAllDiceNumbers(int player) {
|
||||||
|
|
||||||
return players.get(player - 1).hand.getAllDiceNumbers();
|
return players.get(player).hand.getAllDiceNumbers();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Integer> getFreeDiceNumbers(int player) {
|
public ArrayList<Integer> getFreeDiceNumbers(int player) {
|
||||||
|
|
||||||
return players.get(player - 1).hand.getFreeDiceNumbers();
|
return players.get(player).hand.getFreeDiceNumbers();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Integer> getLockedInDiceNumbers(int player) {
|
public ArrayList<Integer> getLockedInDiceNumbers(int player) {
|
||||||
|
|
||||||
return players.get(player - 1).hand.getLockedInDiceNumbers();
|
return players.get(player).hand.getLockedInDiceNumbers();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lockInDices(int player, int... dices) {
|
public void lockInDices(int player, int... dices) {
|
||||||
|
|
||||||
players.get(player - 1).hand.lockInDices(dices);
|
players.get(player).hand.lockInDices(dices);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeftRolls(int player) {
|
public int getLeftRolls(int player) {
|
||||||
|
|
||||||
return players.get(player - 1).hand.getLeftRolls();
|
return players.get(player).hand.getLeftRolls();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getAllOptionsEvaluated(int player) {
|
public ArrayList<String> getAllOptionsEvaluated(int player) {
|
||||||
|
|
||||||
players.get(player - 1).box.evaluateBoxOptions(players.get(player - 1).hand.getAllDiceNumbers());
|
players.get(player).box.evaluateBoxOptions(players.get(player - 1).hand.getAllDiceNumbers());
|
||||||
return players.get(player - 1).box.getAllOptions();
|
return players.get(player).box.getAllOptions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectOption(int player, String selectedOption) {
|
public void selectOption(int player, String selectedOption) {
|
||||||
|
|
||||||
players.get(player - 1).box.selectOption(selectedOption);
|
players.get(player).box.selectOption(selectedOption);
|
||||||
players.get(player - 1).box.resetOptions();
|
players.get(player).box.resetOptions();
|
||||||
players.get(player - 1).getNewHand();
|
players.get(player).getNewHand();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean gameOver(int player) {
|
public boolean gameOver(int player) {
|
||||||
|
|
||||||
return players.get(player - 1).box.gameOver();
|
return players.get(player).box.gameOver();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int returnTotalPoints(int player) {
|
public int returnTotalPoints(int player) {
|
||||||
|
|
||||||
if (players.get(player - 1).box.gameOver())
|
if (players.get(player).box.gameOver())
|
||||||
return players.get(player - 1).box.returnTotalPoints();
|
return players.get(player).box.returnTotalPoints();
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setScoreToHighscores(int player) throws FileNotFoundException {
|
||||||
|
|
||||||
|
String highscores[][] = new String[10][3];
|
||||||
|
String highscoreMem1 = "";
|
||||||
|
String highscoreMem2 = "";
|
||||||
|
Scanner sc = new Scanner("src/csv/highscores.csv");
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
|
||||||
|
if (sc.hasNextLine()) {
|
||||||
|
highscores[i][0] = sc.next();
|
||||||
|
highscores[i][1] = sc.next();
|
||||||
|
highscores[i][2] = sc.nextLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
|
||||||
|
if (highscores[i][2] == null) {
|
||||||
|
highscores[i][0] = sc.next();
|
||||||
|
highscores[i][1] = sc.next();
|
||||||
|
highscores[i][2] = sc.nextLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (returnTotalPoints(player) < Integer.parseInt(highscores[9][2])) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (returnTotalPoints(player) > Integer.parseInt(highscores[0][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
highscoreMem1 = highscores[0][i];
|
||||||
|
if (i == 2)
|
||||||
|
highscores[0][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[0][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[0][i] = "" + LocalDate.now();
|
||||||
|
highscoreMem2 = highscores[1][i];
|
||||||
|
highscores[1][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[2][i];
|
||||||
|
highscores[2][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[3][i];
|
||||||
|
highscores[3][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[4][i];
|
||||||
|
highscores[4][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[5][i];
|
||||||
|
highscores[5][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[6][i];
|
||||||
|
highscores[6][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[7][i];
|
||||||
|
highscores[7][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[8][i];
|
||||||
|
highscores[8][i] = highscoreMem2;
|
||||||
|
highscores[9][i] = highscoreMem1;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (returnTotalPoints(player) > Integer.parseInt(highscores[1][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
highscoreMem2 = highscores[1][i];
|
||||||
|
if (i == 2)
|
||||||
|
highscores[1][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[1][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[1][i] = "" + LocalDate.now();
|
||||||
|
highscoreMem1 = highscores[2][i];
|
||||||
|
highscores[2][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[3][i];
|
||||||
|
highscores[3][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[4][i];
|
||||||
|
highscores[4][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[5][i];
|
||||||
|
highscores[5][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[6][i];
|
||||||
|
highscores[6][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[7][i];
|
||||||
|
highscores[7][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[8][i];
|
||||||
|
highscores[8][i] = highscoreMem2;
|
||||||
|
highscores[9][i] = highscoreMem1;
|
||||||
|
}
|
||||||
|
} else if (returnTotalPoints(player) > Integer.parseInt(highscores[2][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
highscoreMem1 = highscores[2][i];
|
||||||
|
if (i == 2)
|
||||||
|
highscores[2][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[2][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[2][i] = "" + LocalDate.now();
|
||||||
|
highscoreMem2 = highscores[3][i];
|
||||||
|
highscores[3][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[4][i];
|
||||||
|
highscores[4][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[5][i];
|
||||||
|
highscores[5][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[6][i];
|
||||||
|
highscores[6][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[7][i];
|
||||||
|
highscores[7][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[8][i];
|
||||||
|
highscores[8][i] = highscoreMem2;
|
||||||
|
highscores[9][i] = highscoreMem1;
|
||||||
|
}
|
||||||
|
} else if (returnTotalPoints(player) > Integer.parseInt(highscores[3][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
highscoreMem2 = highscores[3][i];
|
||||||
|
if (i == 2)
|
||||||
|
highscores[3][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[3][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[3][i] = "" + LocalDate.now();
|
||||||
|
highscoreMem1 = highscores[4][i];
|
||||||
|
highscores[4][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[5][i];
|
||||||
|
highscores[5][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[6][i];
|
||||||
|
highscores[6][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[7][i];
|
||||||
|
highscores[7][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[8][i];
|
||||||
|
highscores[8][i] = highscoreMem2;
|
||||||
|
highscores[9][i] = highscoreMem1;
|
||||||
|
}
|
||||||
|
} else if (returnTotalPoints(player) > Integer.parseInt(highscores[4][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
highscoreMem1 = highscores[4][i];
|
||||||
|
if (i == 2)
|
||||||
|
highscores[4][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[4][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[4][i] = "" + LocalDate.now();
|
||||||
|
highscoreMem2 = highscores[5][i];
|
||||||
|
highscores[5][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[6][i];
|
||||||
|
highscores[6][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[7][i];
|
||||||
|
highscores[7][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[8][i];
|
||||||
|
highscores[8][i] = highscoreMem2;
|
||||||
|
highscores[9][i] = highscoreMem1;
|
||||||
|
}
|
||||||
|
} else if (returnTotalPoints(player) > Integer.parseInt(highscores[5][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
highscoreMem2 = highscores[5][i];
|
||||||
|
if (i == 2)
|
||||||
|
highscores[5][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[5][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[5][i] = "" + LocalDate.now();
|
||||||
|
highscoreMem1 = highscores[6][i];
|
||||||
|
highscores[6][i] = highscoreMem2;
|
||||||
|
highscoreMem2 = highscores[7][i];
|
||||||
|
highscores[7][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[8][i];
|
||||||
|
highscores[8][i] = highscoreMem2;
|
||||||
|
highscores[9][i] = highscoreMem1;
|
||||||
|
}
|
||||||
|
} else if (returnTotalPoints(player) > Integer.parseInt(highscores[6][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
highscoreMem1 = highscores[6][i];
|
||||||
|
if (i == 2)
|
||||||
|
highscores[6][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[6][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[6][i] = "" + LocalDate.now();
|
||||||
|
highscoreMem2 = highscores[7][i];
|
||||||
|
highscores[7][i] = highscoreMem1;
|
||||||
|
highscoreMem1 = highscores[8][i];
|
||||||
|
highscores[8][i] = highscoreMem2;
|
||||||
|
highscores[9][i] = highscoreMem1;
|
||||||
|
}
|
||||||
|
} else if (returnTotalPoints(player) > Integer.parseInt(highscores[7][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
highscoreMem2 = highscores[7][i];
|
||||||
|
if (i == 2)
|
||||||
|
highscores[7][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[7][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[7][i] = "" + LocalDate.now();
|
||||||
|
highscoreMem1 = highscores[8][i];
|
||||||
|
highscores[8][i] = highscoreMem2;
|
||||||
|
highscores[9][i] = highscoreMem1;
|
||||||
|
}
|
||||||
|
} else if (returnTotalPoints(player) > Integer.parseInt(highscores[8][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
highscoreMem1 = highscores[8][i];
|
||||||
|
if (i == 2)
|
||||||
|
highscores[8][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[8][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[8][i] = "" + LocalDate.now();
|
||||||
|
highscores[9][i] = highscoreMem1;
|
||||||
|
}
|
||||||
|
} else if (returnTotalPoints(player) > Integer.parseInt(highscores[9][2])) {
|
||||||
|
|
||||||
|
for (int i = 2; i >= 0; i--) {
|
||||||
|
if (i == 2)
|
||||||
|
highscores[9][i] = "" + returnTotalPoints(player);
|
||||||
|
else if (i == 1)
|
||||||
|
highscores[9][i] = "" + players.get(player).name;
|
||||||
|
else if (i == 0)
|
||||||
|
highscores[9][i] = "" + LocalDate.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintWriter out = new PrintWriter("src/csv/highscores.csv");
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
for (int s = 0; s < 3; s++) {
|
||||||
|
out.print(i + ": " + LocalDate.now() + ": " + players.get(player).name + ": "
|
||||||
|
+ returnTotalPoints(player));
|
||||||
|
}
|
||||||
|
out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue