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