Last fixes (Error Handling)
parent
24eafc0b0d
commit
7af2b8d295
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/ui/TUI.class
BIN
bin/ui/TUI.class
Binary file not shown.
|
@ -13,19 +13,20 @@ import domain.Player;
|
||||||
|
|
||||||
public class YahtzeeGame {
|
public class YahtzeeGame {
|
||||||
|
|
||||||
public int playerCount;
|
private int playerCount;
|
||||||
public ArrayList<Player> players = new ArrayList<>();
|
private ArrayList<Player> players = new ArrayList<>();
|
||||||
public String savedGamemode;
|
private String savedGamemode;
|
||||||
|
|
||||||
public YahtzeeGame() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlayercount(int playerCount) {
|
public void setPlayercount(int playerCount) {
|
||||||
this.playerCount = playerCount;
|
this.playerCount = playerCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPlayercount(){
|
||||||
|
return this.playerCount;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void setPlayerNames(String... names) {
|
public void setPlayerNames(String... names) {
|
||||||
for (int i = 0; i < this.playerCount; i++) {
|
for (int i = 0; i < this.playerCount; i++) {
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ public class TUI {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
String choice = "";
|
String choice = "";
|
||||||
|
boolean notFound = false;
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
System.out.println("\nYahtzee Star Wars Special!");
|
System.out.println("\nYahtzee Star Wars Special!");
|
||||||
|
@ -19,6 +20,7 @@ public class TUI {
|
||||||
try {
|
try {
|
||||||
YahtzeeGame game = new YahtzeeGame() {
|
YahtzeeGame game = new YahtzeeGame() {
|
||||||
};
|
};
|
||||||
|
notFound = false;
|
||||||
System.out.println("\nMain menu:");
|
System.out.println("\nMain menu:");
|
||||||
System.out.println(">Play");
|
System.out.println(">Play");
|
||||||
System.out.println(">Highscores");
|
System.out.println(">Highscores");
|
||||||
|
@ -30,11 +32,19 @@ public class TUI {
|
||||||
System.out.println("\nChoose your gamemode:");
|
System.out.println("\nChoose your gamemode:");
|
||||||
System.out.println(">Normal");
|
System.out.println(">Normal");
|
||||||
System.out.println(">Special8");
|
System.out.println(">Special8");
|
||||||
System.out.println("\n" + game.showHighscores(sc.nextLine()));
|
choice = sc.nextLine();
|
||||||
|
if(choice.equalsIgnoreCase("Special8"))
|
||||||
|
game.setGamemode("Special8");
|
||||||
|
else
|
||||||
|
game.setGamemode("Normal");
|
||||||
|
System.out.println("\n" + game.showHighscores(choice));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("\nHighscore file not found!\n");
|
System.out.println("\nHighscore file not found!\n");
|
||||||
|
notFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("\n>Return");
|
System.out.println("\n>Return");
|
||||||
|
if(!notFound)
|
||||||
System.out.println(">Delete");
|
System.out.println(">Delete");
|
||||||
choice = sc.nextLine();
|
choice = sc.nextLine();
|
||||||
if (choice.equalsIgnoreCase("Return")) {
|
if (choice.equalsIgnoreCase("Return")) {
|
||||||
|
@ -69,9 +79,9 @@ public class TUI {
|
||||||
System.out.println("\nType in the player names, lock in each name with Enter: ");
|
System.out.println("\nType in the player names, lock in each name with Enter: ");
|
||||||
System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]");
|
System.out.println(">ex. Lucas [Enter] William [Enter] Lena [Enter]");
|
||||||
|
|
||||||
String playerNames[] = new String[game.playerCount];
|
String playerNames[] = new String[game.getPlayercount()];
|
||||||
|
|
||||||
for (int i = 0; i < game.playerCount; i++) {
|
for (int i = 0; i < game.getPlayercount(); i++) {
|
||||||
playerNames[i] = sc.nextLine();
|
playerNames[i] = sc.nextLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +89,7 @@ public class TUI {
|
||||||
|
|
||||||
while (!game.gameOverAll()) {
|
while (!game.gameOverAll()) {
|
||||||
|
|
||||||
for (int i = 0; i < game.playerCount; i++) {
|
for (int i = 0; i < game.getPlayercount(); i++) {
|
||||||
|
|
||||||
if (game.gameOver(i))
|
if (game.gameOver(i))
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue