Пример #1
0
 public void processMove(Tank tank) throws Exception {
   this.tank = tank;
   if (tank.getDirection() == Direction.LEFT && tank.getX() <= minimumFieldSize
       || tank.getDirection() == Direction.RIGHT && tank.getX() >= maximumFieldSize
       || tank.getDirection() == Direction.UP && tank.getY() <= minimumFieldSize
       || tank.getDirection() == Direction.DOWN && tank.getY() >= maximumFieldSize) {
     illegaleMove(tank.getDirection());
   } else {
     tank.turn(tank.getDirection());
     for (int i = 0; i < cellSize; i++) {
       moveLeft(tank.getDirection());
       moveRight(tank.getDirection());
       moveUp(tank.getDirection());
       moveDown(tank.getDirection());
       repaintMove();
     }
   }
 }
Пример #2
0
 private void illegaleMove(Direction direction) {
   System.out.println(
       "[illegal move] "
           + "derection:"
           + direction
           + "||"
           + "tankX:"
           + tank.getX()
           + "||"
           + "tankY:"
           + tank.getY());
   return;
 }
Пример #3
0
 public int fireLeft() throws Exception {
   String str = getQuadrantXY(tank.getX(), tank.getY());
   int tankV = Integer.valueOf(str.substring(0, 1));
   int tankH = Integer.valueOf(str.substring(2, str.length()));
   tank.turn(Direction.LEFT);
   for (int idx = tankV; idx < tankV + 1; idx++) {
     for (int j = tankH; j >= 0; j--) {
       if (battleField.scanQuadrant(idx, j) == "B") {
         tank.fire();
       }
     }
   }
   return tankH;
 }
Пример #4
0
 public int fireDown() throws Exception {
   String str = getQuadrantXY(tank.getX(), tank.getY());
   int tankV = Integer.valueOf(str.substring(0, 1));
   int tankH = Integer.valueOf(str.substring(2, str.length()));
   tank.turn(Direction.DOWN);
   for (int idx = tankV; idx < battleField.getBattleField().length; idx++) {
     for (int j = tankH; j < tankH + 1; j++) {
       if (battleField.scanQuadrant(idx, j) == "B") {
         tank.fire();
       }
     }
   }
   return tankV;
 }
Пример #5
0
 private void moveDown(Direction direction) {
   if (direction == Direction.DOWN) {
     tank.updateY(step);
     System.out.println(
         "[move down] "
             + "derection:"
             + direction
             + "||"
             + "tankX:"
             + tank.getX()
             + "||"
             + "tankY:"
             + tank.getY());
   }
 }
Пример #6
0
 private void moveUp(Direction direction) {
   if (direction == Direction.UP) {
     tank.updateY(-step);
     System.out.println(
         "[move up] "
             + "derection:"
             + direction
             + "||"
             + "tankX:"
             + tank.getX()
             + "||"
             + "tankY:"
             + tank.getY());
   }
 }
Пример #7
0
 private void moveRight(Direction direction) {
   if (direction == Direction.RIGHT) {
     tank.updateX(step);
     System.out.println(
         "[move right] "
             + "derection:"
             + direction
             + "||"
             + "tankX:"
             + tank.getX()
             + "||"
             + "tankY:"
             + tank.getY());
   }
 }
Пример #8
0
 private void moveLeft(Direction direction) {
   if (direction == Direction.LEFT) {
     tank.updateX(-step);
     System.out.println(
         "[move left] "
             + "derection:"
             + direction
             + "||"
             + "tankX:"
             + tank.getX()
             + "||"
             + "tankY:"
             + tank.getY());
   }
 }
Пример #9
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    int i = 0;
    Color cc;
    for (int v = 0; v < 9; v++) {
      for (int h = 0; h < 9; h++) {
        if (COLORDED_MODE) {
          if (i % 2 == 0) {
            cc = new Color(252, 241, 177);
          } else {
            cc = new Color(233, 243, 255);
          }
        } else {
          cc = new Color(180, 180, 180);
        }
        i++;
        g.setColor(cc);
        g.fillRect(h * 64, v * 64, 64, 64);
      }
    }

    for (int j = 0; j < battleField.getDimentionY(); j++) {
      for (int k = 0; k < battleField.getDimentionX(); k++) {
        if (battleField.scanQuadrant(j, k).equals("B")) {
          String coordinates = getQuadrant(j + 1, k + 1);
          int separator = coordinates.indexOf("_");
          int y = Integer.parseInt(coordinates.substring(0, separator));
          int x = Integer.parseInt(coordinates.substring(separator + 1));
          g.setColor(new Color(0, 0, 255));
          g.fillRect(x, y, 64, 64);
        }
      }
    }

    g.setColor(new Color(255, 0, 0));
    g.fillRect(tank.getX(), tank.getY(), 64, 64);

    g.setColor(new Color(0, 255, 0));
    if (tank.getDirection() == Direction.UP) {
      g.fillRect(tank.getX() + 20, tank.getY(), 24, 34);
    } else if (tank.getDirection() == Direction.DOWN) {
      g.fillRect(tank.getX() + 20, tank.getY() + 30, 24, 34);
    } else if (tank.getDirection() == Direction.LEFT) {
      g.fillRect(tank.getX(), tank.getY() + 20, 34, 24);
    } else {
      g.fillRect(tank.getX() + 30, tank.getY() + 20, 34, 24);
    }

    g.setColor(new Color(255, 0, 255));
    g.fillRect(agressor.getX(), agressor.getY(), 64, 64);

    g.setColor(new Color(255, 255, 0));
    if (agressor.getDirection() == Direction.UP) {
      g.fillRect(agressor.getX() + 20, agressor.getY(), 24, 34);
    } else if (agressor.getDirection() == Direction.DOWN) {
      g.fillRect(agressor.getX() + 20, agressor.getY() + 30, 24, 34);
    } else if (agressor.getDirection() == Direction.LEFT) {
      g.fillRect(agressor.getX(), agressor.getY() + 20, 34, 24);
    } else {
      g.fillRect(agressor.getX() + 30, agressor.getY() + 20, 34, 24);
    }

    g.setColor(new Color(255, 255, 0));
    g.fillRect(bullet.getX(), bullet.getY(), 14, 14);
  }