Exemplo n.º 1
0
  @Override
  public void restart() {

    if (context
        .getLeaderboard()
        .isHighScore(new Player("", context.getHUDManager().getScore()), 10)) {
      textBox.setEnabled(true);
      textBox.setText("Enter your name");
    } else textBox.setEnabled(false);

    entryAdded = false;
    context.getSoundManager().playBackgroundSound(backgroundMusic);
  }
Exemplo n.º 2
0
  public GameOverScreen(Component comp, Graphics2D g2d) {
    this.component = comp;
    this.g2d = g2d;
    background = new ImageEntity(comp);
    background.load("/resources/gameOverScreen.png");

    highScoreNotification = new ImageEntity(comp, g2d);
    highScoreNotification.load("/resources/newHighscore.png");
    highScoreNotification.setPosition(new Point2D(519, 559));

    backButton = new Button(comp);
    backButton.setGraphics(g2d);
    backButton.load("/resources/backButton.png");

    textBox = new TextField(comp, g2d, Color.BLACK, new Font("arial", Font.PLAIN, 30));
    textBox.load("/resources/textbox.png");
    textBox.setMaxSize(20);
    textBox.setPosition(new Point2D(451, 600));
    textBox.setAction("player_text");
    textBox.addObserver(this);

    entryAddedNotification = new ImageEntity(comp, g2d);
    entryAddedNotification.load("/resources/leaderboardSuccessNotification.png");
    entryAddedNotification.setPosition(new Point2D(textBox.getX(), textBox.getY()));

    backButton.setPosition(new Point2D(384, 591));
    backButton.setAction("back");
    backButton.addObserver(this);
    entryAdded = false;
    backgroundMusic = new SoundSample("/resources/gameOverSong.wav");
  }
Exemplo n.º 3
0
  @Override
  public void update(Observable o, GameEvent e) {
    if (!(e instanceof ActionEvent)) return;

    ActionEvent ev = (ActionEvent) e;

    switch (ev.getMessage()) {
      case "back":
        if (textBox.isEnabled() && !entryAdded) return;
        else context.goNext(Screens.START, GameManager.RESUME);
        break;
      case "player_text":
        String text = textBox.getText();
        context.getLeaderboard().insert(new Player(text, context.getHUDManager().getScore()));
        context.getLeaderboard().save(GameSettings.LEADERBOARD_PATH);
        textBox.setEnabled(false);
        entryAdded = true;
        break;
      default:
        break;
    }
  }
Exemplo n.º 4
0
  @Override
  public void draw() {
    g2d.drawImage(background.getImage(), 0, 0, 1280 - 1, 720 - 1, component);
    backButton.draw();

    Font prevFont = g2d.getFont();
    g2d.setColor(Color.GREEN);
    g2d.setFont(new Font("arial", Font.PLAIN, 20));
    g2d.drawString(
        "Score: " + context.getHUDManager().getScore(),
        (int) highScoreNotification.getX() + 5,
        (int) highScoreNotification.getY() - 10);
    g2d.setFont(prevFont);

    if (context
        .getLeaderboard()
        .isHighScore(new Player("", context.getHUDManager().getScore()), 10)) {
      highScoreNotification.draw();
      textBox.draw();
    }

    if (entryAdded) entryAddedNotification.draw();
  }
Exemplo n.º 5
0
 @Override
 public void mouseClicked(MouseEvent e) {
   backButton.mouseClicked(e);
   textBox.mouseClicked(e);
 }
Exemplo n.º 6
0
 @Override
 public void keyTyped(KeyEvent e) {
   textBox.keyTyped(e);
 }
Exemplo n.º 7
0
 @Override
 public void keyPressed(KeyEvent e) {
   textBox.keyPressed(e);
 }