Package oop13.space.controller

Examples of oop13.space.controller.GameController


*/
public class Main {
 
  public static void main(String[] args) {
    Model model = new Model();
    MainMenuController c = new MainMenuController(model);
    MainFrame mainFrame = new MainFrame();
    c.setView(mainFrame);
    mainFrame.setVisible(true);
  }
View Full Code Here


  @Override
  public void submitScore() throws EmptyPlayerNameException {
    Integer score = this.model.getStatistics().getScore();
    String name = this.subScore.getTextField().getText();
    if (name.trim().isEmpty()) {
      throw new EmptyPlayerNameException();
    }
    if (name.length() >= MAX_NAME_LENGTH) {
      name = name.substring(0, MAX_NAME_LENGTH);
    }
    HighScore.getHighScore().addScore(name, score);
View Full Code Here

   * @param gamePanel - The {@link oop13.space.views.GamePanelInterface} to observe
   */
  public void setView(GamePanelInterface gamePanel) {
    this.gamePanel = gamePanel;
    this.gamePanel.attachObserver(this);
    Game newGame = new Game(model, this);
    newGame.start();
  }
View Full Code Here

  /**
   * Chooses randomly an alien that can shoot
   * and adds a new alien shot.
   */
  private void alienShot() {
    Alien a = model.getAliens().getShooter();
    if (a != null) {
      AlienShot shot = a.fire();
      model.addAlienShot(shot);
            shot.moveIndividual(a.getPositionX() + SHOT_STEP, a.getPositionY());
    }
  }
View Full Code Here

    in a list*/
  public void initIndividuals() {
    this.listIndividuals = new CopyOnWriteArrayList<Individual>();
    int startPositionX = INITIAL_POSITION_X;
    this.spaceShip = new Ship();
    this.alien1 = new Alien(new AlienType(1), startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.alien2 = new Alien(new AlienType(2), startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.alien3 = new Alien(new AlienType(3), startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.alien4 = new AlienMotherShip();
    this.alien4.moveTo(startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.alienShot = new AlienShot(startPositionX, POSITION_Y);
View Full Code Here

    Assert.assertTrue(shipShot.isDead());
    Assert.assertTrue(alienShot.isDead());
   
    //Testing score when aliens die
    model.resetStatistics();
    Alien alien1 = new Alien(new AlienType(1), 50, 30);
    Alien alien2 = new Alien(new AlienType(2), 80, 30);
    Alien alien3 = new Alien(new AlienType(3), 100, 30);
    model.getList().add(alien1);
    model.getList().add(alien2);
    model.getList().add(alien3);
    model.removeIndividual(alien1);
    Assert.assertTrue(model.getStatistics().getScore() == 10);
View Full Code Here

  public void run() {

    int counterTimer = 0;
    int lives = model.getShip().getLives();
      double motherSpawnMoment = Math.random() * MOTHERSHIP_SPAWN_FREQ;
    AlienBlock alienBlock = model.getAliens();
    Ship spaceShip = model.getShip();
    List<Individual> individuals = model.getList();

    alienBlock.startMove();
    AudioPlayer.getAudioPlayer().playLoop(AudioPlayer.BACKGROUND_SOUND);

    while (!this.isOver) {
      counterTimer++;
      if (counterTimer % SHOT_RATIO == 0) {
        alienShot();
      }

      //Adds a mother ship to the game
      if (counterTimer >= motherSpawnMoment) {
          AlienMotherShip motherShip = model.addMotherShip();
        motherShip.startMove();
        motherSpawnMoment = MOTHERSHIP_BASE_FREQ + Math.random() * MOTHERSHIP_SPAWN_FREQ;
        counterTimer = 0;
      }

      /* Moves all the individuals
       * (except the aliens 'cause they already move).
       * Checks all the possible collisions of all individuals
       * Checks if some aliens are dead
       * Sets lives and score in the game panel */
      for (Individual ind : individuals) {
        if (!(ind instanceof Alien)) {
                    ind.moveIndividual(ind.getPositionX(), ind.getPositionY());
        }
        ind.collideWith(individuals);
        if (spaceShip.getLives() != lives) {
          this.obs.setShipLivesInPanel();
          lives--;
        }
        if (ind.isDead()) {
          this.model.removeIndividual(ind);
                    if (ind instanceof Alien && !(ind instanceof AlienMotherShip)) {
                      AudioPlayer.getAudioPlayer().playOnce(AudioPlayer.ALIEN_KILLED_SOUND);
            this.aliensKilled++;
          }
          if (ind instanceof AlienMotherShip) {
                        if (!((AlienMotherShip) ind).isOutOfLimit()) {
                this.motherShipsKilled++;
            }
          }
                    this.obs.setScoreInPanel(this.model.getStatistics().getScore());
        }
      }

      //Speed up the last alien survivor
      if (this.aliensKilled >= KILLED_ALIENS_BEFORE_SPEEDUP) {
        alienBlock.setSleepTime(ALIENS_SLEEP_TIME);
      }

      //Check game won
      if (alienBlock.checkGameWon()) {
        this.levelsCompleted++;
        this.obs.gameWon();
        this.isOver = true;
      }

      //Check game over
      if (alienBlock.checkGameOver() || spaceShip.isDead()) {
        //Stops the alien block's thread
        if (!alienBlock.checkGameOver()) {
          alienBlock.setGameOver();
        }
        spaceShip.setLives(0);
        this.obs.gameOver();
        this.isOver = true;
      }
View Full Code Here

        alienShot();
      }

      //Adds a mother ship to the game
      if (counterTimer >= motherSpawnMoment) {
          AlienMotherShip motherShip = model.addMotherShip();
        motherShip.startMove();
        motherSpawnMoment = MOTHERSHIP_BASE_FREQ + Math.random() * MOTHERSHIP_SPAWN_FREQ;
        counterTimer = 0;
      }

      /* Moves all the individuals
View Full Code Here

    startPositionX += DELTA_X;
    this.alien2 = new Alien(new AlienType(2), startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.alien3 = new Alien(new AlienType(3), startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.alien4 = new AlienMotherShip();
    this.alien4.moveTo(startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.alienShot = new AlienShot(startPositionX, POSITION_Y);
    startPositionX += DELTA_X;
    this.wall = new Wall(startPositionX);
View Full Code Here

    for (int i = 0; i < 10; i++) {
      ShipShot shot = model.addShot();
      Assert.assertTrue(model.getList().contains(shot));
    }
    Assert.assertEquals(model.getList().size(), 75);
    AlienMotherShip motherShip = model.addMotherShip();
    Assert.assertEquals(model.getList().size(), 76);
    for (int i = 0; i < 5; i++) {
      AlienShot alienShot = model.addAlienShot(new AlienShot(10, i));
      Assert.assertTrue(model.getList().contains(alienShot));
    }
View Full Code Here

TOP

Related Classes of oop13.space.controller.GameController

Copyright © 2018 www.massapicom. 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.