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