Fixed score sorting, added a place column in ScoreDialog

This commit is contained in:
Kai S. K. Engelbart 2019-05-15 20:41:34 +02:00
parent 9574e426c0
commit eac310b879
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13
3 changed files with 20 additions and 9 deletions

1
.gitignore vendored
View File

@ -54,3 +54,4 @@ local.properties
.scala_dependencies
.worksheet
/scores.ser
/scores old.ser

View File

@ -32,15 +32,16 @@ public class ScoreDialog extends JDialog {
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
getContentPane().setLayout(new BorderLayout(0, 0));
String[] columnNames = {"Name", "Game duration", "Board Config", "Date"};
String[][] data = new String[scores.size()][4];
String[] columnNames = { "Place", "Name", "Game duration", "Board Config", "Date" };
String[][] data = new String[scores.size()][5];
Iterator<Score> iter = scores.iterator();
for(int i = 0; i < data.length; i++) {
Score s = iter.next();
data[i][0] = s.getName();
data[i][1] = String.valueOf(s.getDuration());
data[i][2] = boardConfigName;
data[i][3] = new SimpleDateFormat().format(s.getDate());
data[i][0] = String.valueOf(i + 1);
data[i][1] = s.getName();
data[i][2] = String.valueOf(s.getDuration());
data[i][3] = boardConfigName;
data[i][4] = new SimpleDateFormat().format(s.getDate());
}
mtable = new JTable(data, columnNames);

View File

@ -39,18 +39,27 @@ public class ScoreManager {
if (config == EASY && (easy.size() < 10 || easy.get(9).getDuration() > evt.getDuration())) {
String name = JOptionPane.showInputDialog("Please enter your name");
Score score = new Score(name, evt.getDuration(), new Date());
easy.add(score);
sortInsert(score, easy);
} else if (config == MEDIUM && (medium.size() < 10 || medium.get(9).getDuration() > evt.getDuration())) {
String name = JOptionPane.showInputDialog("Please enter your name");
Score score = new Score(name, evt.getDuration(), new Date());
medium.add(score);
sortInsert(score, medium);
} else if (config == HARD && (hard.size() < 10 || hard.get(9).getDuration() > evt.getDuration())) {
String name = JOptionPane.showInputDialog("Please enter your name");
Score score = new Score(name, evt.getDuration(), new Date());
hard.add(score);
sortInsert(score, hard);
}
}
private void sortInsert(Score score, List<Score> list) {
for (int i = 0; i < list.size(); i++)
if (list.get(i).getDuration() > score.getDuration()) {
list.add(i, score);
return;
}
list.add(score);
}
public void displayEasy() {
new ScoreDialog(easy, "Easy").setVisible(true);
}