1
0
Fork 0

BreakOut 5.4

This commit is contained in:
rxbn_ 2020-02-03 23:35:01 +01:00
parent 59c2f83f49
commit 05a4463ba8
4 changed files with 40 additions and 7 deletions

View File

@ -136,7 +136,7 @@ public class Controller implements ActionListener, KeyListener {
case KeyEvent.VK_ESCAPE: case KeyEvent.VK_ESCAPE:
// exit current level // exit current level
game.getLevel().setFinished(true); game.getLevel().setFinished(true);
toStartScreen(); toStartScreen(game.getLevel().getScore());
break; break;
} }
@ -161,10 +161,14 @@ public class Controller implements ActionListener, KeyListener {
/** /**
* This method switches the view to the StartScreen view. * 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.showScreen(StartScreen.class.getName());
view.getStartScreen().requestFocusInWindow(); view.getStartScreen().requestFocusInWindow();
view.getStartScreen().addScore(score);
view.getStartScreen().repaint();
} }
/** /**

View File

@ -114,7 +114,7 @@ public class Game {
controller.toPlayground(); controller.toPlayground();
} else { } else {
// tells the controller to switch to the startScreen of the game // tells the controller to switch to the startScreen of the game
controller.toStartScreen(); controller.toStartScreen(level.getScore());
} }

View File

@ -301,7 +301,7 @@ public class Level extends Thread implements ILevel {
// level failed // level failed
} else { } else {
setFinished(true); setFinished(true);
game.getController().toStartScreen(); game.getController().toStartScreen(getScore());
} }
} }

View File

@ -51,6 +51,11 @@ public class StartScreen extends JPanel {
*/ */
private JLabel error; private JLabel error;
/**
* The scoreMenu
*/
private SectionPanel scoreMenu;
/** /**
* The constructor needs a view * The constructor needs a view
@ -125,16 +130,16 @@ public class StartScreen extends JPanel {
*/ */
private void initializeScoreMenu() { private void initializeScoreMenu() {
// The layout // The layout
SectionPanel scoreMenu = new SectionPanel(Color.WHITE); scoreMenu = new SectionPanel(Color.WHITE);
scoreMenu.shady = false; scoreMenu.shady = false;
scoreMenu.setLayout(new MigLayout("", "10[center, grow, fill]10", scoreMenu.setLayout(new MigLayout("", "10[center, grow, fill]10",
"5[center]5")); "5[center]5"));
// adding the compoenents to the layout // adding the components to the layout
JLabel headline = new JLabel("Scores"); JLabel headline = new JLabel("Scores");
headline.setFont(new Font("Sans-serif", Font.PLAIN, 16)); headline.setFont(new Font("Sans-serif", Font.PLAIN, 16));
headline.setHorizontalAlignment(SwingConstants.CENTER); 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"); add(scoreMenu, "cell 1 0, gapleft 5");
} }
@ -200,4 +205,28 @@ public class StartScreen extends JPanel {
error.setText(""); 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");
}
} }