highscore functions done

main
s.eser 2024-04-28 19:05:07 +02:00
parent 549dc0a399
commit eb361a6f58
7 changed files with 36 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,6 @@
package facade;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.ArrayList;
@ -14,13 +13,14 @@ public class YahtzeeGame {
public int playerCount;
public ArrayList<Player> players = new ArrayList<>();
public String savedGamemode;
public String gameSheet;
public YahtzeeGame(int playerCount, String gamemode, String... names) {
this.playerCount = playerCount;
this.savedGamemode = gamemode;
for (int i = 0; i < this.playerCount; i++) {
this.players.add(new Player(names[i], this.savedGamemode));
@ -93,11 +93,9 @@ public class YahtzeeGame {
return 0;
}
public void setScoreToHighscores(int player) throws FileNotFoundException {
private String[][] refreshHighscoreList(){
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++) {
@ -109,18 +107,19 @@ public class YahtzeeGame {
}
}
for (int i = 0; i < 10; i++) {
sc.close();
return highscores;
}
if (highscores[i][2] == null) {
highscores[i][0] = sc.next();
highscores[i][1] = sc.next();
highscores[i][2] = sc.nextLine();
}
}
public void setScoreToHighscores(int player, String highscores[][]) throws FileNotFoundException {
String highscoreMem1 = "";
String highscoreMem2 = "";
try {
if (returnTotalPoints(player) < Integer.parseInt(highscores[9][2])) {
return;
}
@ -335,5 +334,30 @@ public class YahtzeeGame {
out.close();
} catch (Exception e) {
}
}
public void saveAllPlayersHighscores() throws FileNotFoundException{
for(int i = 0; i<playerCount; i++){
setScoreToHighscores(i,refreshHighscoreList());
}
}
public String showHighscores(){
StringBuilder sb = new StringBuilder();
for(int i = 0; i<10; i++){
sb.append(i+": "+refreshHighscoreList()[i][0]);
sb.append(": " + refreshHighscoreList()[i][1]);
sb.append(": " + refreshHighscoreList()[i][2] + "\n");
}
return sb.toString();
}
}