highscore functions done
parent
549dc0a399
commit
eb361a6f58
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.
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScoreToHighscores(int player, String highscores[][]) throws FileNotFoundException {
|
||||||
|
|
||||||
if (highscores[i][2] == null) {
|
String highscoreMem1 = "";
|
||||||
highscores[i][0] = sc.next();
|
String highscoreMem2 = "";
|
||||||
highscores[i][1] = sc.next();
|
|
||||||
highscores[i][2] = sc.nextLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue