Android Open Source - FourRowSolitaire Win Screen






From Project

Back to project page FourRowSolitaire.

License

The source code is released under:

GNU General Public License

If you think the Android project FourRowSolitaire listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 This file is a part of Four Row Solitaire
/*  ww  w .  j a  va 2s .c om*/
 Copyright (C) 2010-2014 by Matt Stephen, Todor Balabanov, Konstantin Tsanov, Ventsislav Medarov, Vanya Gyaurova, Plamena Popova, Hristiana Kalcheva, Yana Genova

 Four Row Solitaire 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 3 of the License, or
 (at your option) any later version.

 Four Row Solitaire 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.

 You should have received a copy of the GNU General Public License
 along with FourRowSolitaire.  If not, see <http://www.gnu.org/licenses/>.
 */

package eu.veldsoft.four.row.solitaire;

import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseEvent;
import java.io.File;
import java.net.URL;

import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.event.MouseInputAdapter;

/**
 * Class: WinScreen
 * 
 * Description: The WinScreen class manages the win animation and sounds window.
 * 
 * @author Matt Stephen
 */
class WinScreen extends JFrame {

  /**
   * 
   */
  private static final long serialVersionUID = 1L;

  // TODO Use shared preferences. Change int with enum.
  /**
   * Animations. 0 is off, 1 is on.
   */
  static int animation = 0;

  // TODO Use shared preferences. Change int with enum.
  /**
   * Sounds. 0 is off, 1 is on.
   */
  static int sounds = 0;

  /**
   * Sound threat.
   */
  private SoundThread sound = null;

  /**
   * If the sound settings are on, plays the win sounds. If the animation
   * settings are on, fires the fireworks.
   * 
   * @author Todor Balabanov
   */
  public WinScreen() {
    setUndecorated(true);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setFocusable(true);

    /*
     * For JDialog instead of JFrame, but the mouse listener doesn't work
     * with JDialog for some reason.
     * setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
     */
    if (sounds == 1) {
      setSize(200, 200);
      sound = new SoundThread();
      sound.run();
    }

    if (animation == 1) {
      setSize(800, 600);

      FireworksDisplay fw = new FireworksDisplay(100, 200);
      add(fw);
      fw.restartDisplay();
      setLocationRelativeTo(null);
    } else {
      this.setLocation(0, 0);
      add(new JLabel("Click Here to Stop Music"));
    }

    setVisible(true);

    addMouseListener(new MouseInputAdapter() {
      public void mouseClicked(MouseEvent e) {
        if (sound != null && sound.sequencer.isRunning()) {
          sound.sequencer.stop();
        }

        WinScreen.this.dispose();
      }
    });

    addFocusListener(new FocusAdapter() {
      public void focusLost(FocusEvent e) {
        WinScreen.this.requestFocus();
      }
    });
  }

  /**
   * Creates the sound thread. The sound thread is called only when the sounds
   * are turned on. Manages the sounds.
   * 
   * @author Todor Balabanov
   */
  private class SoundThread extends Thread {
    /**
     * Sequencer.
     */
    public Sequencer sequencer;

    /**
     * To play the sound.
     * 
     * @author Todor Balabanov
     */
    public void run() {
      /*
       * To hold choice.
       */
      String song = "";

      try {
        /*
         * Doesn't work as a .jar file.
         */
        File songDir = new File(getClass().getResource("sounds/win/")
            .toURI());
        String[] songs = songDir.list();
        boolean retry = true;

        do {
          song = songs[Common.PRNG.nextInt(songs.length)];

          if (song.toLowerCase().contains(".mid")) {
            retry = false;
          }
        } while (retry);
      } catch (Exception ex) {
        int songInt = Common.PRNG.nextInt(4);

        if (songInt == 0) {
          song = "celebration.mid";
        } else if (songInt == 1) {
          song = "anotheronebitesthedust.mid";
        } else if (songInt == 2) {
          song = "wearethechampions.mid";
        } else if (songInt == 3) {
          song = "bluedabadee.mid";
        }
      }

      URL filelocation = getClass().getResource("sounds/win/" + song);

      try {
        Sequence sequence = MidiSystem.getSequence(filelocation);
        sequencer = MidiSystem.getSequencer();
        sequencer.open();
        sequencer.setSequence(sequence);
        sequencer.setLoopCount(0);
        sequencer.start();
      } catch (Exception ex) {
        System.err.println("Error opening win sound file.");
      }
    }
  }
}




Java Source Code List

eu.veldsoft.four.row.solitaire.AboutGameActivity.java
eu.veldsoft.four.row.solitaire.AcePileLayeredPane.java
eu.veldsoft.four.row.solitaire.AcePile.java
eu.veldsoft.four.row.solitaire.AnimationSettings.java
eu.veldsoft.four.row.solitaire.BestTimesActivity.java
eu.veldsoft.four.row.solitaire.CardColor.java
eu.veldsoft.four.row.solitaire.CardComponent.java
eu.veldsoft.four.row.solitaire.CardRank.java
eu.veldsoft.four.row.solitaire.CardStackLayeredPane.java
eu.veldsoft.four.row.solitaire.CardStack.java
eu.veldsoft.four.row.solitaire.CardSuit.java
eu.veldsoft.four.row.solitaire.Card.java
eu.veldsoft.four.row.solitaire.ChangeAppearance.java
eu.veldsoft.four.row.solitaire.ChangeOptions.java
eu.veldsoft.four.row.solitaire.ColumnLayeredPane.java
eu.veldsoft.four.row.solitaire.Column.java
eu.veldsoft.four.row.solitaire.Common.java
eu.veldsoft.four.row.solitaire.DealDeckLayeredPane.java
eu.veldsoft.four.row.solitaire.DealDeck.java
eu.veldsoft.four.row.solitaire.Deck.java
eu.veldsoft.four.row.solitaire.DiscardPileLayeredPane.java
eu.veldsoft.four.row.solitaire.DiscardPile.java
eu.veldsoft.four.row.solitaire.FireworksDisplay.java
eu.veldsoft.four.row.solitaire.FourRowSolitaire.java
eu.veldsoft.four.row.solitaire.GameActivity.java
eu.veldsoft.four.row.solitaire.GameDifficulty.java
eu.veldsoft.four.row.solitaire.GameState.java
eu.veldsoft.four.row.solitaire.HelpActivity.java
eu.veldsoft.four.row.solitaire.MenuActivity.java
eu.veldsoft.four.row.solitaire.SettingsActivity.java
eu.veldsoft.four.row.solitaire.SingleCellLayeredPane.java
eu.veldsoft.four.row.solitaire.SingleCell.java
eu.veldsoft.four.row.solitaire.SolitaireBoardFrame.java
eu.veldsoft.four.row.solitaire.SolitaireBoard.java
eu.veldsoft.four.row.solitaire.SolitaireLayout.java
eu.veldsoft.four.row.solitaire.SolitairePanel.java
eu.veldsoft.four.row.solitaire.SoundsSettings.java
eu.veldsoft.four.row.solitaire.StatisticsActivity.java
eu.veldsoft.four.row.solitaire.StatisticsTab0Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab1Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab2Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab3Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab4Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab5Activity.java
eu.veldsoft.four.row.solitaire.ThroughLimit.java
eu.veldsoft.four.row.solitaire.TopTimes.java
eu.veldsoft.four.row.solitaire.WinActivity.java
eu.veldsoft.four.row.solitaire.WinScreen.java