Esempio n. 1
0
 public int battleFieldScanner() {
   for (int fieldX = 0; fieldX < bf.getDimentionX(); fieldX++) {
     for (int fieldY = 0; fieldY < bf.getDimentionY(); fieldY++)
       if ((af.getQuadrantString(fieldX, fieldY).equals(enemyTankPosition()))
           || (bf.scanQuadrant2(fieldY, fieldX) instanceof Rock)) {
         return fieldX + 1;
       }
   }
   return 0;
 }
Esempio n. 2
0
  public void reappear() {
    try {
      Thread.sleep(1000);
    } catch (Exception e) {
      System.out.println("Exception");
    }
    x = new Random().nextInt(bf.getDimentionX()) * 64;
    y = new Random().nextInt(bf.getDimentionY()) * 64;

    af.repaint();
  }
 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;
 }
Esempio n. 4
0
 boolean checkRight(int checkX, int checkY) {
   for (; checkX < 9; checkX++) {
     if (bf.scanQuadrant2(checkY, checkX) instanceof Rock
         || af.getQuadrantString(checkX, checkY).equals(enemyTankPosition())) {
       return true;
     }
   }
   return false;
 }
 private boolean processInterception() {
   String str = getQuadrantXY(bullet.getX(), bullet.getY());
   int i = Integer.valueOf(str.substring(0, 1));
   int q = Integer.valueOf(str.substring(2, str.length()));
   if (i >= battleField.getBattleField().length - battleField.getBattleField().length
       && i < battleField.getBattleField().length
       && q >= battleField.getBattleField().length - battleField.getBattleField().length
       && q < battleField.getBattleField().length
       && battleField.scanQuadrant(i, q) == "B") {
     battleField.updateQuadrant(i, q, " ");
     return true;
   } else return false;
 }
  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();
    }
  }
  public ActionField() throws Exception {
    battleField = new BattleField();
    tank = new Tank(this, battleField);

    agressor =
        new Agressor(
            Integer.parseInt(position.substring(0, position.indexOf("_"))),
            Integer.parseInt(position.substring(position.lastIndexOf("_") + 1, position.length())),
            Direction.LEFT,
            this,
            battleField);
    bullet = new Bullet(-100, -100, Direction.STOP);
    JFrame frame = new JFrame("BATTLE FIELD, DAY 2");
    frame.setLocation(750, 150);
    frame.setMinimumSize(
        new Dimension(battleField.getBF_WIDTH() + 16, battleField.getBF_HEIGHT() + 39));
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(this);
    frame.pack();
    frame.setVisible(true);
  }
 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;
 }
  @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);
  }