Package devint.cero.ui.graphical

Source Code of devint.cero.ui.graphical.EndDialog

/*
*  Cero Project - Copyright   2006 The Cero Developement Team
*  (Michael Laguerre, Camille Roux, Matthieu Segret, Mathieu Sivade)
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the Free
*  Software Foundation; either version 2 of the License, or (at your option)
*  any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
*  for more details.
*/

package devint.cero.ui.graphical;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.List;

import javax.swing.*;
import javax.swing.border.*;

import cero.games.Zone;
import cero.games.ZonesGroup;
import cero.games.uno.UnoGame;
import cero.games.uno.UnoPlayer;
import cero.ui.sound.SoundManager;
import cero.ui.sound.TTSSound;
import cero.ui.sound.WaveSound;

/**
* End Dialog Box. It is shown when a round is over.
*
* @author LAGUERRE Michael
*/
public class EndDialog extends DialogBox {

  private static final long serialVersionUID = -5210841290222780112L;

  private JPanel buttonPanel;

  private JButton noButton;

  private Font font = new Font("Courier New", Font.BOLD, 25);

  /**
   * Constructor for objects of class AboutDialog.
   *
   * @param parent
   *            the parent window
   * @param title
   *            the title of the AboutDialog box
   */
  public EndDialog(JFrame parent, String title) {
    super(parent, title);
    setSize(440, 370);
    super.configureFrame();
    makeLabelPanel();
    printInfos();
    addKeyListener(this);
  }

  /**
   * Create the graphical components and place them into the box.
   */
  private void makeLabelPanel() {
    labelPanel = new JPanel();
    labelPanel.setBorder(new EmptyBorder(10, 30, 10, 30));
    labelPanel.setLayout(new BorderLayout());
    labelPanel.setBackground(SystemColor.control);

    buttonPanel = new JPanel();
    buttonPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.setBackground(SystemColor.control);

    okButton = new JButton("  Oui  ");
    okButton.setFont(font);
    okButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        hideDialog();
      }
    });
    okButton.setBackground(Color.lightGray);
    buttonPanel.add(okButton);

    noButton = new JButton("  Non  ");
    noButton.setFont(font);
    noButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        quit();
      }
    });
    noButton.setBackground(Color.lightGray);
    buttonPanel.add(noButton);
    labelPanel.add(buttonPanel, BorderLayout.SOUTH);

    add(labelPanel);

  }

  /**
   * Retrieves all the needed information and print them into the box.
   */
  private void printInfos() {
    UnoGame game = ((Frame) parent).getGame();
    UnoPlayer player = ((Frame) parent).getPlayer();
    List<cero.games.Player> listPlayers = game.getPlayers().getSortedList();
    title = new JLabel("", JLabel.CENTER);

    for (cero.games.Player players : listPlayers) {
      if (players.equals(player)) {
        ZonesGroup zones = players.getZones();
        int totalNumberOfCards = 0;
        for (Zone zone : zones)
          totalNumberOfCards += zone.getCardCount();

        if (totalNumberOfCards == 0) {
          title.setText("Tu as gagné");
          SoundManager.playSound(new WaveSound("wav/gui/win.wav",
              false));
        } else {
          title.setText("Tu as perdu");
          SoundManager.playSound(new WaveSound("wav/gui/loose.wav",
              false));
        }
      }
    }
    title.setFont(font);
    title.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    labelPanel.add(title, BorderLayout.NORTH);

    SoundManager.playSound(new TTSSound("",false));
   
    String string = "\n";
    for (cero.games.Player players : game.getPlayers()){
      String substring = players.getPlayerName() + " : " + ((UnoPlayer) players).getPoints() + " points\n";
      string += substring;
      SoundManager.playSound(new TTSSound(substring + ".",false));
    }
   
    string+="\nVeux tu recommencer ?\n";

    text = new JTextArea();
    text.setText(string);
    text.setAlignmentX(JTextArea.CENTER_ALIGNMENT);
    text.setFont(font);
    text.setBackground(null);
    labelPanel.add(text, BorderLayout.CENTER);

    SoundManager.playSound(new WaveSound("wav/gui/end.wav", false));
    SoundManager.playSound(new WaveSound("wav/gui/buttons.wav", false));
  }

  /**
   * Action done when a key (enter, space, escape) is pressed.
   *
   * @param e
   *            the KeyEvent to listen to
   */
  public void keyPressed(KeyEvent e) {
    switch (e.getKeyCode()) {
    case KeyEvent.VK_ENTER:
    case KeyEvent.VK_SPACE:
      hideDialog();
      break;
    case KeyEvent.VK_ESCAPE:
      quit();
      break;
    }
  }

  /**
   * Action done when we want to quit.
   */
  public void quit() {
    SoundManager.playSound(new WaveSound("wav/gui/au_revoir.wav", true));
    try {
      Thread.sleep(1000);
    } catch (InterruptedException event) {
      event.printStackTrace();
    }
    System.exit(0);
  }
}
TOP

Related Classes of devint.cero.ui.graphical.EndDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.