BreakOut 5.4
This commit is contained in:
parent
59c2f83f49
commit
05a4463ba8
@ -136,7 +136,7 @@ public class Controller implements ActionListener, KeyListener {
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
// exit current level
|
||||
game.getLevel().setFinished(true);
|
||||
toStartScreen();
|
||||
toStartScreen(game.getLevel().getScore());
|
||||
break;
|
||||
}
|
||||
|
||||
@ -161,10 +161,14 @@ public class Controller implements ActionListener, KeyListener {
|
||||
|
||||
/**
|
||||
* This method switches the view to the StartScreen view.
|
||||
* @param score The player score
|
||||
*/
|
||||
public void toStartScreen() {
|
||||
public void toStartScreen(int score) {
|
||||
view.showScreen(StartScreen.class.getName());
|
||||
view.getStartScreen().requestFocusInWindow();
|
||||
|
||||
view.getStartScreen().addScore(score);
|
||||
view.getStartScreen().repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,7 +114,7 @@ public class Game {
|
||||
controller.toPlayground();
|
||||
} else {
|
||||
// tells the controller to switch to the startScreen of the game
|
||||
controller.toStartScreen();
|
||||
controller.toStartScreen(level.getScore());
|
||||
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ public class Level extends Thread implements ILevel {
|
||||
// level failed
|
||||
} else {
|
||||
setFinished(true);
|
||||
game.getController().toStartScreen();
|
||||
game.getController().toStartScreen(getScore());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,11 @@ public class StartScreen extends JPanel {
|
||||
*/
|
||||
private JLabel error;
|
||||
|
||||
/**
|
||||
* The scoreMenu
|
||||
*/
|
||||
private SectionPanel scoreMenu;
|
||||
|
||||
|
||||
/**
|
||||
* The constructor needs a view
|
||||
@ -125,16 +130,16 @@ public class StartScreen extends JPanel {
|
||||
*/
|
||||
private void initializeScoreMenu() {
|
||||
// The layout
|
||||
SectionPanel scoreMenu = new SectionPanel(Color.WHITE);
|
||||
scoreMenu = new SectionPanel(Color.WHITE);
|
||||
scoreMenu.shady = false;
|
||||
scoreMenu.setLayout(new MigLayout("", "10[center, grow, fill]10",
|
||||
"5[center]5"));
|
||||
|
||||
// adding the compoenents to the layout
|
||||
// adding the components to the layout
|
||||
JLabel headline = new JLabel("Scores");
|
||||
headline.setFont(new Font("Sans-serif", Font.PLAIN, 16));
|
||||
headline.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
scoreMenu.add(headline, "cell 0 0, gaptop 5");
|
||||
scoreMenu.add(headline, "cell 0 0, gaptop 5, wrap");
|
||||
|
||||
add(scoreMenu, "cell 1 0, gapleft 5");
|
||||
}
|
||||
@ -200,4 +205,28 @@ public class StartScreen extends JPanel {
|
||||
error.setText("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a score to the scoreboard
|
||||
* @param score
|
||||
*/
|
||||
public void addScore(int score) {
|
||||
// adding the components to the layout
|
||||
|
||||
// name
|
||||
JLabel lName = new JLabel(getPlayersName());
|
||||
lName.setFont(new Font("Sans-serif", Font.PLAIN, 16));
|
||||
lName.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
scoreMenu.add(lName, "gaptop 5");
|
||||
|
||||
// spacing
|
||||
JLabel space = new JLabel();
|
||||
scoreMenu.add(space);
|
||||
|
||||
// score
|
||||
JLabel lScore = new JLabel(String.valueOf(score));
|
||||
lScore.setFont(new Font("Sans-serif", Font.PLAIN, 16));
|
||||
lScore.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
scoreMenu.add(lScore, "gaptop 5, wrap");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user