Package com.mlarktar.spacewar.commands

Source Code of com.mlarktar.spacewar.commands.AboutSpaceWar

/*
*  This file is part of jSpaceWar.
*
*  jSpaceWar 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.
*
*  jSpaceWar 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 jSpaceWar.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.mlarktar.spacewar.commands;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;

import javax.swing.Timer;

import com.mlarktar.spacewar.AboutText;
import com.mlarktar.spacewar.SoundEvents;
import com.mlarktar.spacewar.SoundServer;
import com.mlarktar.spacewar.Space;
import com.mlarktar.spacewar.sprites.ScrollingText;

/**
* @author malar
*
* This class displays the about information of SpaceWar.
* Author and stuff.
*/
public class AboutSpaceWar extends SWCommand implements ActionListener {
  private Space space;
  private Timer timer;
  private Iterator lines;
  private ScrollingText lastLine;

  public AboutSpaceWar() {
    space = new Space();
    panel = space;
    timer = new Timer(2000, this);
    timer.setCoalesce(true);
  }
 
  /* (non-Javadoc)
   * @see com.mlarktar.spacewar.SWCommand#init()
   */
  public void init() {
    space.fillWithStars();
  }

  /* (non-Javadoc)
   * @see com.mlarktar.spacewar.SWCommand#start()
   */
  public void start() {
    timer.start();
    space.start();
   
    if (!SoundServer.getSoundEvents().isLooping()) {
      SoundServer.getSoundEvents().loopEvent(SoundEvents.AMB_ABT);
    }
  }

  /* (non-Javadoc)
   * @see com.mlarktar.spacewar.SWCommand#stop()
   */
  public void stop() {
    timer.stop();
    space.dispose();
   
    SoundServer.getSoundEvents().stopLooping();
  }

  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    if (lines == null) {
      lines = new AboutText().getIterator();
    }
    if (lines.hasNext()) {
      lastLine = (ScrollingText) lines.next();
      space.addSpaceItem(lastLine);
    } else {
      if (lastLine.getDuration() == 0) {
        // Restart the animation
        lines = null;
      }
    }   
  }

  /* (non-Javadoc)
   * @see com.mlarktar.spacewar.commands.SWCommand#pause()
   */
  public void pause() {
    timer.stop();
    space.stop();
  }
}
TOP

Related Classes of com.mlarktar.spacewar.commands.AboutSpaceWar

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.