Exemplo n.º 1
0
  public void processFire(Bullet bullet) throws InterruptedException {

    this.bullet = bullet;

    Direction tankDirection = tank.getDirection();

    while (bullet.getY() > minusLimit
        && bullet.getY() < plusLimit
        && bullet.getX() > minusLimit
        && bullet.getX() < plusLimit) {
      if (tankDirection == Direction.UP) {
        bullet.updateY(-1);
      } else if (tankDirection == Direction.DOWN) {
        bullet.updateY(1);
      } else if (tankDirection == Direction.LEFT) {
        bullet.updateX(-1);
      } else if (tankDirection == Direction.RIGHT) {
        bullet.updateX(1);
      }

      if (processInterception()) {
        bullet.destroy();
      }

      repaint();
      Thread.sleep(bullet.getSpeed());
    }
  }
Exemplo n.º 2
0
  public void processFire(Bullet bullet) throws Exception {
    this.bullet = bullet;

    while ((bullet.getX() > -15 && bullet.getX() < battleField.getBF_WIDTH())
        && (bullet.getY() > -15 && bullet.getY() < battleField.getBF_HEIGHT())) {
      if (bullet.getDirection() == Direction.UP) {
        bullet.updateY(-step);
      } else if (bullet.getDirection() == Direction.DOWN) {
        bullet.updateY(step);
      } else if (bullet.getDirection() == Direction.LEFT) {
        bullet.updateX(-step);
      } else {
        bullet.updateX(step);
      }
      if (processInterception() == true) {
        bullet.destroy();
      }
      repaintFire();
    }
  }
Exemplo n.º 3
0
  public void processFire(Bullet bullet, AbstractTank tank) throws InterruptedException {
    this.bullet = bullet;
    this.currentTank = tank;
    Direction bulletDirection = bullet.getDirection();

    while (true) {
      Quadrant nextQuadrant =
          getQuadrant(bullet.getX() + bulletDirection.stepX, bullet.getY() + bulletDirection.stepY);

      if (!nextQuadrant.isValid(battleField)) {
        bullet.destroy();
        break;
      }

      bullet.updateX(bulletDirection.stepX);
      bullet.updateY(bulletDirection.stepY);
      Thread.sleep(Bullet.SPEED);

      if (processInterception()) {
        bullet.destroy();
        break;
      }
    }
  }