Package oop13.space.testing.TestCollisionsInFrame

Examples of oop13.space.testing.TestCollisionsInFrame.Control


  /*Initialize all the individuals that will collide with the ship shot and add them
    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);
View Full Code Here


  @Test
  public void testAddIndividuals() {
    IModel model = new Model();
    model.initIndividuals();
    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);
View Full Code Here

  @Test
  public void testRemoveIndividuals() {
    IModel model = new Model();
    model.initIndividuals();
    Ship spaceShip = model.getShip();
    ShipShot shot = model.addShot();
    model.removeIndividual(shot);
    model.removeIndividual(spaceShip);
    Assert.assertTrue(model.getList().size() == 64);
    for (Individual ind : model.getList()) {
      model.removeIndividual(ind);
View Full Code Here

    Assert.assertTrue(spaceShip.getLives() == 2);
    spaceShip.decreaseLives();
   
    //Testing collisions AlienShot -> Ship and Shot -> Alien
    model.getList().add(new AlienShot(spaceShip.getPositionX(), spaceShip.getPositionY()));
    ShipShot shot = new ShipShot(10, 50);
    model.getList().add(shot);
    shot.collideWith(model.getList());
    spaceShip.collideWith(model.getList());
    Assert.assertTrue(spaceShip.isDead());
    Assert.assertTrue(shot.isDead());
    int individualsKilled = 0;
    for (Individual ind : model.getList()) {
      if (ind.isDead()) {
        individualsKilled++;
      }
    }
    Assert.assertTrue(individualsKilled == 4); //Individuals dead: alienShot, shot, ship and an alien
    for (Individual ind : model.getList()) {
      if (ind.getPositionX() == 10 && ind.getPositionY() == 50) {
        Assert.assertTrue(ind.isDead());
      }
    }
   
    //Testing collisions Shot -> Wall and Alien shot -> Wall
    ShipShot shipShot = new ShipShot(40, 450);
    Wall wallKicked = null;
    model.getList().add(shipShot);
    for (Wall wall : model.getWalls().getList()) {
      wall.collideWith(model.getList());
    }
    for (Wall wall : model.getWalls().getList()) {
      if (wall.getPositionX() == 40 && wall.getPositionY() == 450) {
        wallKicked = wall;
      }
    }
    Assert.assertTrue(wallKicked.getLives() == 1);
    model.getList().remove(shipShot);
    AlienShot alienShot = new AlienShot(35, 450);
    model.getList().add(alienShot);
    wallKicked.collideWith(model.getList());
    Assert.assertTrue(wallKicked.getLives() == 0);
    Assert.assertTrue(wallKicked.isDead());
   
    //Testing collisions Shot -> Alien Shot
    model.getList().add(shipShot);
    alienShot.collideWith(model.getList());
    Assert.assertTrue(shipShot.isDead());
    Assert.assertTrue(alienShot.isDead());
   
    //Testing score when aliens die
    model.resetStatistics();
    Alien alien1 = new Alien(new AlienType(1), 50, 30);
View Full Code Here

        }
        if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
          this.getShip().moveIndividual(this.getShip().getPositionX() + DELTA_MOVEMENT, this.getShip().getPositionY());
        }
        if (e.getKeyCode() == KeyEvent.VK_SPACE) {
          ShipShot shot = new ShipShot(this.getShip().getPositionX() + DELTA_MOVEMENT, this.getShip().getPositionY() - (DELTA_MOVEMENT * 2));
          this.list.add(shot);
        }
      }
     
    }
 
View Full Code Here

  public void testChangesInModel() {
    IModel model = new Model();
    model.initIndividuals();
    model.initAchievements();
    Ship spaceShip = model.getShip();
    Statistics statistics = model.getStatistics();
   
    //Testing adding and resetting statistics
    statistics.setLevelsCompleted(3);
    statistics.setMotherShipsKilled(5);
    statistics.setScore(300);
    statistics.setAliensKilled(100);
    Assert.assertTrue(statistics.getLevelsCompleted() == 3);
    Assert.assertTrue(statistics.getMotherShipsKilled() == 5);
    Assert.assertTrue(statistics.getScore() == 300);
    Assert.assertTrue(statistics.getAliensKilled() == 100);
    statistics.resetStatistics();
    for (Field f : statistics.getClass().getDeclaredFields()) {
      f.setAccessible(true);
      try {
        Assert.assertTrue(f.getInt(statistics) == 0);
      } catch (IllegalArgumentException e) {
        System.err.println(GameStrings.ILLEGAL_ARG_ERROR);
View Full Code Here

      }
    }
   
    //Testing collisions Shot -> Wall and Alien shot -> Wall
    ShipShot shipShot = new ShipShot(40, 450);
    Wall wallKicked = null;
    model.getList().add(shipShot);
    for (Wall wall : model.getWalls().getList()) {
      wall.collideWith(model.getList());
    }
    for (Wall wall : model.getWalls().getList()) {
      if (wall.getPositionX() == 40 && wall.getPositionY() == 450) {
        wallKicked = wall;
      }
    }
    Assert.assertTrue(wallKicked.getLives() == 1);
    model.getList().remove(shipShot);
    AlienShot alienShot = new AlienShot(35, 450);
    model.getList().add(alienShot);
    wallKicked.collideWith(model.getList());
    Assert.assertTrue(wallKicked.getLives() == 0);
    Assert.assertTrue(wallKicked.isDead());
   
    //Testing collisions Shot -> Alien Shot
    model.getList().add(shipShot);
    alienShot.collideWith(model.getList());
    Assert.assertTrue(shipShot.isDead());
View Full Code Here

    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);
    this.wall.moveTo(startPositionX, POSITION_Y);

    this.listIndividuals.add(spaceShip);
    this.listIndividuals.add(alien1);
    this.listIndividuals.add(alien2);
View Full Code Here

  public TestCollisionsToShip() {
    this.listIndividuals = new CopyOnWriteArrayList<>();
    this.spaceShip = new ShipTest();
    this.listIndividuals.add(this.spaceShip);
    this.testPanel = new GamePanel(this.listIndividuals);
    this.testPanel.addKeyListener(new Control(this.listIndividuals));
    this.testPanel.setFocusable(true);
  }
View Full Code Here

  public void resetAchievements() {
    File achFile = this.model.getAchievementsFile();
    ListIOManager<Achievement> achManager = new ListIOManager<>(achFile);
    List<Achievement> achList = this.model.getAchievementsList();
    achManager.reset();
    AchievementsGUI achGUI = new AchievementsGUI(achList);
    this.setView(achGUI);
    this.mainFrame.replacePanel(achGUI);
  }
View Full Code Here

TOP

Related Classes of oop13.space.testing.TestCollisionsInFrame.Control

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.