Beispiel #1
0
  public boolean processInterception() {
    Quadrant bulletQuadrant = bullet.getLocation();
    AbstractTank opponent = getOpponent();
    Quadrant opponentQuadrant = getOpponentLocation();

    if (opponentQuadrant.equals(bulletQuadrant)) {
      bullet.destroy();
      boolean isDestroyed = opponent.destroy();
      if (isDestroyed) {
        System.out.println("TANK DESTROYED: " + opponent);
        gameOver(opponent);
      }
      return true;
    }

    FieldObject object = battleField.scan(bulletQuadrant);
    if (object != null) {
      battleField.update(bulletQuadrant, null);
      System.out.println(
          "QUADRANT CLEANED, vertical: " + bulletQuadrant.v + ", horizontal: " + bulletQuadrant.h);
      if (object.getClass() == Eagle.class) {
        gameOver(object);
      }
      return true;
    }

    return false;
  }
Beispiel #2
0
 private boolean isLegalMove() {
   Quadrant quadrant = currentTank.getLocation();
   Direction direction = currentTank.getDirection();
   Quadrant neighborQuadrant = quadrant.getNeighbor(direction);
   return quadrant.hasEmptyNeighbor(direction, battleField)
       && !getOpponentLocation().equals(neighborQuadrant);
 }
Beispiel #3
0
 private boolean isFinishedMove(Quadrant startQuadrant) {
   Quadrant currentQuadrant = currentTank.getLocation();
   Direction direction = currentTank.getDirection();
   Quadrant nextQuadrant =
       ActionField.getQuadrant(
           currentTank.getX() + direction.stepX, currentTank.getY() + direction.stepY);
   // nextQuadrant is not currentQuadrant.getNeighbor !
   return currentQuadrant.v >= startQuadrant.v + 1
       || currentQuadrant.h >= startQuadrant.h + 1
       || nextQuadrant.v < startQuadrant.v - 1
       || nextQuadrant.h < startQuadrant.h - 1;
 }
Beispiel #4
0
 private AbstractTank getOpponent() {
   if (currentTank.equals(defender)) {
     return aggressor;
   } else {
     return defender;
   }
 }
Beispiel #5
0
  public void processMove(AbstractTank tank) throws InterruptedException {
    currentTank = tank;
    Quadrant startQuadrant = tank.getLocation();
    Direction direction = tank.getDirection();

    if (isLegalMove()) {
      while (!isFinishedMove(startQuadrant)) {
        tank.updateX(direction.stepX);
        tank.updateY(direction.stepY);
        Thread.sleep(tank.getSpeed());
      }
      System.out.println("MOVED " + direction);
    } else {
      System.out.println("NO MOVE, direction: " + direction);
      Thread.sleep(tank.getSpeed());
    }
  }
Beispiel #6
0
 public void runTheGame() throws InterruptedException {
   defender.destroyOpponent();
 }