Exemplo n.º 1
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);
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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());
    }
  }