- Updated the Node interface and its implementations to include a strength() function. This is a double value between 0 and 1 representing the percent activation.
- Updated the PlayerModel to fix a bug in the high score tracking. - Created HighScoreDialog.java, which displays the high scores from a PlayerModel. In the future, it will have a "New Game" button so that it can be used to transition between games.
This commit is contained in:
69
src/view/HighScoreDialog.java
Normal file
69
src/view/HighScoreDialog.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package view;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import model.playerModel.PlayerModel;
|
||||
|
||||
public class HighScoreDialog extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame x = new JFrame();
|
||||
x.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
x.setVisible(true);
|
||||
|
||||
PlayerModel pm = new PlayerModel();
|
||||
pm.logGame(100);
|
||||
pm.logGame(90);
|
||||
pm.logGame(80);
|
||||
pm.logGame(70);
|
||||
pm.logGame(60);
|
||||
pm.logGame(50);
|
||||
pm.logGame(40);
|
||||
pm.logGame(30);
|
||||
pm.logGame(20);
|
||||
pm.logGame(10);
|
||||
pm.logGame(98);
|
||||
pm.logGame(105);
|
||||
|
||||
new HighScoreDialog(x, pm);
|
||||
}
|
||||
|
||||
public HighScoreDialog(JFrame owner, PlayerModel pm) {
|
||||
super(owner, "Game over!", true);
|
||||
|
||||
String text = "<html>";
|
||||
text += "<b>Game Over!</b>";
|
||||
text += "<br><br>";
|
||||
text += "<em>High Scores:</em>";
|
||||
text += "<br><ol>";
|
||||
|
||||
int[] highScores = pm.getHighScores();
|
||||
loop: for (int i = 0; i < highScores.length; i++) {
|
||||
if (highScores[i] == -1) {
|
||||
break loop;
|
||||
}
|
||||
|
||||
else {
|
||||
text += "<li>" + highScores[i] + "</li>";
|
||||
}
|
||||
}
|
||||
|
||||
text += "</ol></html>";
|
||||
|
||||
JLabel label = new JLabel(text);
|
||||
label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
|
||||
this.add(label);
|
||||
this.pack();
|
||||
this.setResizable(false);
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user