Nearly everything implemented

main
selim 2024-04-29 16:47:41 +02:00
parent 0dc39592db
commit df415b4042
10 changed files with 90 additions and 82 deletions

View File

@ -0,0 +1 @@
1
1

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/ui/TUI$1.class 100644

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
1
1

View File

@ -42,8 +42,10 @@ public class Hand {
public int getLockedInDiceAmount() { public int getLockedInDiceAmount() {
if (lockedInDices != null)
return lockedInDices.size(); return lockedInDices.size();
else
return 0;
} }
public void rollDices() { public void rollDices() {
@ -89,7 +91,7 @@ public class Hand {
public ArrayList<Integer> getLockedInDiceNumbers() { public ArrayList<Integer> getLockedInDiceNumbers() {
ArrayList<Integer> res = new ArrayList<>(); ArrayList<Integer> 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()); res.add(this.lockedInDices.get(i).getDiceNumber());

View File

@ -1,5 +1,7 @@
package facade; package facade;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -151,10 +153,10 @@ public class YahtzeeGame {
return 0; return 0;
} }
private String[][] refreshHighscoreList() { private String[][] refreshHighscoreList() throws FileNotFoundException {
String highscores[][] = new String[10][3]; 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++) { for (int i = 0; i < 10; i++) {
@ -162,7 +164,12 @@ public class YahtzeeGame {
highscores[i][0] = sc.next(); highscores[i][0] = sc.next();
highscores[i][1] = sc.next(); highscores[i][1] = sc.next();
highscores[i][2] = sc.nextLine(); highscores[i][2] = sc.nextLine();
} else {
highscores[i][0] = "___";
highscores[i][1] = "___";
highscores[i][2] = "0";
} }
} }
sc.close(); sc.close();
@ -402,7 +409,7 @@ public class YahtzeeGame {
} }
public String showHighscores() { public String showHighscores() throws FileNotFoundException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@ -1,9 +1,7 @@
package ui; package ui;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
import facade.YahtzeeGame; import facade.YahtzeeGame;
public class TUI { public class TUI {
@ -12,16 +10,13 @@ public class TUI {
String choice = ""; String choice = "";
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
boolean newGame = false;
System.out.println("Yahtzee Star Wars Special!"); System.out.println("Yahtzee Star Wars Special!");
while (newGame) {
YahtzeeGame game = new YahtzeeGame() {
};
while (!choice.equals("stop")) { while (!choice.equals("stop")) {
YahtzeeGame game = new YahtzeeGame() {
};
System.out.println("Main menu:\n"); System.out.println("Main menu:\n");
System.out.println(">Play"); System.out.println(">Play");
System.out.println(">Highscores"); System.out.println(">Highscores");
@ -32,8 +27,9 @@ public class TUI {
System.out.println(">Return"); System.out.println(">Return");
System.out.println(">Delete"); System.out.println(">Delete");
choice = sc.nextLine(); choice = sc.nextLine();
if (choice.equals("Return")) if (choice.equals("Return")) {
break; }
else if (choice.equals("Delete")) { else if (choice.equals("Delete")) {
System.out.println( System.out.println(
"Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': "); "Are you sure you want to delete the Highscore file?\nAs a confirmation type: 'I AM SURE': ");
@ -107,12 +103,13 @@ public class TUI {
} }
} }
System.out.println("The game is over, saving all highscores to the highscore table..."); System.out.println("The game is over, " + game.getWinnerMessage());
System.out.println("Saving all highscores to the highscore table...");
game.saveAllPlayersHighscores(); 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();
} }
} }
} }
} }
}