added new state of highscore implementation. problems are some NULLP. Exceptions of the MapEngine while getting the Scores

This commit is contained in:
shebang
2015-01-14 08:00:53 +01:00
parent a528aea320
commit fc845ea8f4
3 changed files with 46 additions and 11 deletions
-1
View File
@@ -17,7 +17,6 @@ public class Main extends JFrame {
this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
this.add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER); this.add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
this.setVisible(true); this.setVisible(true);
} }
@@ -12,6 +12,7 @@ import de.heatup.highscore.ScoreEntry;
import de.heatup.logging.Logger; import de.heatup.logging.Logger;
import de.heatup.mapengine.MapEngine; import de.heatup.mapengine.MapEngine;
import de.heatup.ui.FontLoader; import de.heatup.ui.FontLoader;
import de.heatup.ui.PanelBuilder;
public class HighscorePanel { public class HighscorePanel {
@@ -31,6 +32,7 @@ public class HighscorePanel {
// MapEngine used to get and set the Highscore // MapEngine used to get and set the Highscore
private static MapEngine me; private static MapEngine me;
private static int scoreEntries = 0;
public HighscorePanel() { public HighscorePanel() {
@@ -39,15 +41,18 @@ public class HighscorePanel {
} }
private static void getHighscores() { private static void getHighscores() {
// default map
me = new MapEngine(1);
// set some default values // TODO : Init the MapEngine before a new game is started for getting highscores
me.getHighscoreHandler().setHighscore(me.getMapHash(), "Daniel", 3134); me = PanelBuilder.getMapEngine();
me.getHighscoreHandler().setHighscore(me.getMapHash(), "Tim", 2010);
me.getHighscoreHandler().saveHighscores();
// only for testing purposes
// me.getHighscoreHandler().setHighscore(me.getMapHash(), "Daniel", 3134);
// me.getHighscoreHandler().setHighscore(me.getMapHash(), "Tim", 2010);
// me.getHighscoreHandler().saveHighscores();
// count Score entries for building the GridLayout
for(ScoreEntry score : me.getHighscoreHandler().getHighscores(me.getMapHash())) { for(ScoreEntry score : me.getHighscoreHandler().getHighscores(me.getMapHash())) {
scoreEntries++;
Logger.write(score.getName()+" "+score.getScore()); Logger.write(score.getName()+" "+score.getScore());
} }
} }
@@ -77,6 +82,7 @@ public class HighscorePanel {
ttfbase = FontLoader.getFont(); ttfbase = FontLoader.getFont();
emulogicHeading = ttfbase.deriveFont(Font.PLAIN, 20); emulogicHeading = ttfbase.deriveFont(Font.PLAIN, 20);
emulogicDivider = ttfbase.deriveFont(Font.PLAIN, 10); emulogicDivider = ttfbase.deriveFont(Font.PLAIN, 10);
emulogicSmall = ttfbase.deriveFont(Font.PLAIN, 12);
headingLabel = new JLabel(); headingLabel = new JLabel();
headingLabel.setText("HeatUP! - Highscores"); headingLabel.setText("HeatUP! - Highscores");
@@ -98,9 +104,30 @@ public class HighscorePanel {
contentPanel.setSize(new Dimension(800, 550)); contentPanel.setSize(new Dimension(800, 550));
contentPanel.setBackground(Color.BLACK); contentPanel.setBackground(Color.BLACK);
contentPanel.setFocusable(false); contentPanel.setFocusable(false);
contentPanel.setVisible(true); contentPanel.setVisible(true);
// GridLayout for Scores // GridLayout for Scores
JPanel scores = new JPanel();
scores.setBackground(Color.BLACK);
scores.setFocusable(false);
scores.setVisible(true);
getHighscores();
scores.setLayout(new GridLayout(0, scoreEntries));
for(ScoreEntry score : me.getHighscoreHandler().getHighscores(me.getMapHash())) {
JLabel l = new JLabel();
l.setBackground(Color.BLACK);
l.setForeground(Color.YELLOW);
l.setFont(emulogicSmall);
l.setVisible(true);
l.setText(score.getName() + " ---> " + score.getScore());
scores.add(l);
}
contentPanel.add(scores);
} }
+10 -1
View File
@@ -165,8 +165,17 @@ public class MenuPanel {
showHighscore.addMouseListener(new MouseAdapter() { showHighscore.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
// @TODO: implement show highscore
if(gameExists == 1) {
menuPanel.setVisible(false);
HighscorePanel p = new HighscorePanel();
PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
Logger.write("show highscore"); Logger.write("show highscore");
} else if (gameExists == 2) {
Logger.write("cant show scores while game is running");
}
} }
}); });