Example #1
0
  @Test
  public void picksHealth() {
    // jogador apanha um bonus de vida (ganha vida)
    Player p = new Player(true);

    int life = p.getLifepoints();

    // cria objeto que da a vida ao player
    Health h = new Health(p.getX(), p.getY(), true);

    Obstacle ob = new Obstacle((int) p.getX(), (int) p.getY(), 20, true);

    // verifica se apanha
    assertTrue(h.colide(p));
    h.caught(p, true);

    // verifica se nao ganha vida, pois tem a vida cheia
    assertEquals(life, p.getLifepoints());

    // perde vida
    ob.damage(p);
    int life1 = p.getLifepoints();
    assertTrue(life > life1);

    // ganha vida
    h.caught(p, true);
    assertTrue(life1 < p.getLifepoints());
  }
Example #2
0
  @Test
  public void colidesWithObstacle() {
    // jogador colide com um obstaculo (perde vida)
    Player p = new Player(true);

    int life = p.getLifepoints();

    Obstacle ob = new Obstacle((int) p.getX(), (int) p.getY(), life, true);

    // verifica se colide
    assertTrue(ob.colide(p));

    ob.damage(p);

    // verifica se perde vida
    assertTrue(life > p.getLifepoints());
  }
Example #3
0
  // GAMEPLAY
  @Test
  public void gameOver() {
    // jogador fica sem vida
    Player p = new Player(true);

    int life = p.getLifepoints();

    // cria obstaculo que tira a vida toda ao player
    Obstacle ob = new Obstacle((int) p.getX(), (int) p.getY(), life, true);

    // verifica se colide
    assertTrue(ob.colide(p));

    ob.damage(p);

    // verifica se perde vida toda
    assertTrue(life > p.getLifepoints());
    assertEquals(p.getLifepoints(), 0);
  }
Example #4
0
  @Test
  public void picksInvulnerableBonus() {
    // jogador fica invulnerável durante x tempo
    Player p = new Player(true);

    int life = p.getLifepoints();

    Invulnerability ob = new Invulnerability();

    Obstacle obj = new Obstacle((int) p.getX(), (int) p.getY(), life, true);

    // verifica se apanha
    assertTrue(ob.colide(p));
    ob.caught(p, true);

    // colide com objeto que danifica
    obj.damage(p);

    // verifica se nao perde vida
    assertEquals(life, p.getLifepoints());
  }
Example #5
0
  /** optimizes obstacle list vertically */
  public void optimizeObstaclesVertically() {
    boolean changed = false;
    if (!tileObstacles.isEmpty()) {
      Obstacle comparedObstacle1, comparedObstacle2;
      for (int i = 0; i < tileObstacles.size(); i++) {
        comparedObstacle1 = tileObstacles.get(i);
        for (int j = i + 1; j < tileObstacles.size(); j++) {
          comparedObstacle2 = tileObstacles.get(j);

          if (comparedObstacle1.getX() == comparedObstacle2.getX()) {
            if (comparedObstacle1.getWidth() == comparedObstacle2.getWidth()) {
              if (comparedObstacle1.getY() + comparedObstacle1.getHeight()
                  == comparedObstacle2.getY()) {
                // obstacle1 above obstacle2
                tileObstacles.add(
                    new Obstacle(
                        comparedObstacle1.getX(),
                        comparedObstacle1.getY(),
                        comparedObstacle1.getWidth(),
                        comparedObstacle1.getHeight() + comparedObstacle2.getHeight()));
                tileObstacles.remove(comparedObstacle1);
                tileObstacles.remove(comparedObstacle2);
                changed = true;
              }
              if (comparedObstacle1.getY() - comparedObstacle2.getHeight()
                  == comparedObstacle2.getY()) {
                // obstacle2 above obstacle1
                tileObstacles.add(
                    new Obstacle(
                        comparedObstacle1.getX(),
                        comparedObstacle2.getY(),
                        comparedObstacle1.getWidth(),
                        comparedObstacle1.getHeight() + comparedObstacle2.getHeight()));
                tileObstacles.remove(comparedObstacle1);
                tileObstacles.remove(comparedObstacle2);
                changed = true;
              }
            }
          }
        }
      }
    }
    // System.out.println(tileObstacles.size());
    if (changed) optimizeObstaclesVertically();
  }