Package com.mlarktar.spacewar.commands

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

/*
*  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.Font;
import java.awt.Rectangle;

import com.mlarktar.spacewar.Space;
import com.mlarktar.spacewar.SpaceWar;
import com.mlarktar.spacewar.sprites.CrazyPoly;
import com.mlarktar.spacewar.sprites.DeffensiveRepresentation;
import com.mlarktar.spacewar.sprites.OffensiveRepresentation;
import com.mlarktar.spacewar.sprites.ScrollingText;
import com.mlarktar.spacewar.sprites.Ship;

/**
* @author malar
*
* Shows up at the begining of the application and
* displays the animated game title.
*
* TODO Include ship score in the presentation.
*/
public class WellcomeSpaceWar extends SWCommand {
  private Space space;
  private int basex, basey;
  private int wideAccumulator;
  private SpaceWar app;

  public WellcomeSpaceWar(SpaceWar app) {
    this.app = app;
    space = new Space();
    panel = space;
  }
 
  private int getX(int charidx, int col) {
    return basex + charidx * 4 * CrazyPoly.POLISIZE + wideAccumulator + col * CrazyPoly.POLISIZE;
  }

  private int getY(int row) {
    return basey + row * CrazyPoly.POLISIZE;
  }
 
  /* (non-Javadoc)
   * @see com.mlarktar.spacewar.SWCommand#init()
   */
  public void init() {
    space.fillWithStars();
   
    Rectangle bounds = space.getBounds();
   
    basex = (bounds.width - CrazyPoly.POLISIZE * 8 * 4) / 2;
    basey = (bounds.height - CrazyPoly.POLISIZE * 5) / 2;
   
    // S
    space.addSpaceItem(new CrazyPoly(getX(0, 2), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 1), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 1), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 0), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 0), getY(1), true, true));
    space.addSpaceItem(new CrazyPoly(getX(0, 0), getY(1), false, true));
    space.addSpaceItem(new CrazyPoly(getX(0, 0), getY(2), true, true));
    space.addSpaceItem(new CrazyPoly(getX(0, 1), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 1), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 2), getY(2), false, true));
    space.addSpaceItem(new CrazyPoly(getX(0, 2), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 2), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 2), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 1), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 1), getY(4), false, false));
    space.addSpaceItem(new CrazyPoly(getX(0, 0), getY(4), false, false));
    // P
    space.addSpaceItem(new CrazyPoly(getX(1, 0), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 1), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 1), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 2), getY(0), false, true));
    space.addSpaceItem(new CrazyPoly(getX(1, 2), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 2), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 2), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 0), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 0), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 0), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 0), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 0), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 0), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(1, 0), getY(4), true, false));
    // A
    space.addSpaceItem(new CrazyPoly(getX(2, 0), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 1), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 1), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 2), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 0), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 0), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 0), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 0), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 0), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 0), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 0), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 1), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 1), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 2), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 2), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 2), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 2), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 2), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 2), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(2, 2), getY(4), true, false));
    // C
    space.addSpaceItem(new CrazyPoly(getX(3, 0), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 1), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 1), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 2), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 0), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 0), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 0), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 0), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 0), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 0), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 0), getY(4), true, true));
    space.addSpaceItem(new CrazyPoly(getX(3, 1), getY(4), false, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 1), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(3, 2), getY(4), true, false));
    // E
    space.addSpaceItem(new CrazyPoly(getX(4, 0), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 1), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 1), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 2), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 0), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 0), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 0), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 0), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 0), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 0), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 0), getY(4), true, true));
    space.addSpaceItem(new CrazyPoly(getX(4, 1), getY(4), false, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 1), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 2), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(4, 1), getY(2), true, false));
    // W
    space.addSpaceItem(new CrazyPoly(getX(5, 0), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 0), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 0), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 0), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 0), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 0), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 0), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 0), getY(4), true, true));
    space.addSpaceItem(new CrazyPoly(getX(5, 1), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 1), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 2), getY(3), false, true));
    space.addSpaceItem(new CrazyPoly(getX(5, 2), getY(4), true, true));
    space.addSpaceItem(new CrazyPoly(getX(5, 3), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 3), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 3), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 3), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 3), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 3), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 3), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(5, 3), getY(0), false, false));
    wideAccumulator += CrazyPoly.POLISIZE;
    // A
    space.addSpaceItem(new CrazyPoly(getX(6, 0), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 1), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 1), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 2), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 0), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 0), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 0), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 0), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 0), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 0), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 0), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 1), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 1), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 2), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 2), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 2), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 2), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 2), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 2), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(6, 2), getY(4), true, false));
    // R
    space.addSpaceItem(new CrazyPoly(getX(7, 0), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 1), getY(0), true, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 1), getY(0), false, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 2), getY(0), false, true));
    space.addSpaceItem(new CrazyPoly(getX(7, 2), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 2), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 2), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 0), getY(1), true, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 0), getY(1), false, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 0), getY(2), false, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 0), getY(2), true, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 0), getY(3), false, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 0), getY(3), true, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 0), getY(4), true, false));
    space.addSpaceItem(new CrazyPoly(getX(7, 1), getY(2), false, true));
    space.addSpaceItem(new CrazyPoly(getX(7, 1), getY(3), true, true));
    space.addSpaceItem(new CrazyPoly(getX(7, 2), getY(3), false, true));
    space.addSpaceItem(new CrazyPoly(getX(7, 2), getY(4), true, true));
   
    // add ship and victories by each ship
    Ship ship = new Ship(bounds.width / 4, bounds.height * 2 / 3, space);
    ship.setRepresentation(new DeffensiveRepresentation());
    space.addSpaceItem(ship);
    ship = new Ship(bounds.width * 3 / 4, bounds.height * 2 / 3, space);
    ship.setRepresentation(new OffensiveRepresentation());
    space.addSpaceItem(ship);
   
    // add the equal sign and the number of victories for each ship
    ScrollingText text = new ScrollingText(" = " + app.getShipVictories(0), bounds.width / 4 + Ship.SHIPSIZE, bounds.height * 2 / 3 + Ship.SHIPSIZE);
    text.setAboutFont(new Font("Monospaced", Font.BOLD, 20));
    space.addSpaceItem(text);
    text = new ScrollingText(" = " + app.getShipVictories(1), bounds.width * 3 / 4 + Ship.SHIPSIZE, bounds.height * 2 / 3 + Ship.SHIPSIZE);
    text.setAboutFont(new Font("Monospaced", Font.BOLD, 20));
    space.addSpaceItem(text);
  }

  /* (non-Javadoc)
   * @see com.mlarktar.spacewar.SWCommand#start()
   */
  public void start() {
    space.start();
  }

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

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

}
TOP

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

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.