コード例 #1
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;
 }
コード例 #2
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;
 }
コード例 #3
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();
     }
   }
 }