Exemplo n.º 1
0
  public void processFire(Bullet bullet) throws InterruptedException {

    this.bullet = bullet;

    Direction tankDirection = tank.getDirection();

    while (bullet.getY() > minusLimit
        && bullet.getY() < plusLimit
        && bullet.getX() > minusLimit
        && bullet.getX() < plusLimit) {
      if (tankDirection == Direction.UP) {
        bullet.updateY(-1);
      } else if (tankDirection == Direction.DOWN) {
        bullet.updateY(1);
      } else if (tankDirection == Direction.LEFT) {
        bullet.updateX(-1);
      } else if (tankDirection == Direction.RIGHT) {
        bullet.updateX(1);
      }

      if (processInterception()) {
        bullet.destroy();
      }

      repaint();
      Thread.sleep(bullet.getSpeed());
    }
  }
Exemplo n.º 2
0
  /*
  	public void onPaint(Graphics2D g) {
  		Iterator i = _renderables.iterator();
  		while(i.hasNext()){
  			Renderable r = (Renderable) i.next();
  			r.render(g);
  		}
  		_renderables.clear();
  	}
  */
  public Wave processBulletReturnFiringWave(Bullet bullet, long currentTime) {

    int tightMatchDistanceThreshold = 50;
    Wave hitWave =
        DUtils.findClosestWave(
            _waves,
            new Point2D.Double(bullet.getX(), bullet.getY()),
            _robot.getTime(),
            DUtils.ANY_WAVE,
            DUtils.FIRING_WAVE,
            tightMatchDistanceThreshold);

    if (hitWave == null) {
      return NO_WAVE_FOUND;
    }

    for (int x = 0; x < _bulletHitRegisters.size(); x++) {
      BulletHitRegister bhr = (BulletHitRegister) _bulletHitRegisters.get(x);

      bhr.registerBulletHit(bullet, hitWave, currentTime);
    }

    hitWave.processedBulletHit = true;

    return hitWave;
  }
Exemplo n.º 3
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();
    }
  }
Exemplo n.º 4
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 = getQuadrantXY(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, 255, 0));
    g.fillRect(bullet.getX(), bullet.getY(), 14, 14);
  }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
  private boolean processInterception() {
    String currentCoordinate = getQuadrant(bullet.getX(), bullet.getY());

    int y = Integer.parseInt(currentCoordinate.substring(0, 1));
    int x = Integer.parseInt(currentCoordinate.substring(2, 3));

    boolean result = false;

    if (battleField.scanQuadrant(y, x) == " ") {
      result = false;
    }

    if (!battleField.scanQuadrant(y, x).trim().isEmpty()) {
      battleField.updateQuadrant(y, x, " ");
      result = true;
    }

    return result;
  }
Exemplo n.º 7
0
  public void processFire(Bullet bullet, AbstractTank tank) throws InterruptedException {
    this.bullet = bullet;
    this.currentTank = tank;
    Direction bulletDirection = bullet.getDirection();

    while (true) {
      Quadrant nextQuadrant =
          getQuadrant(bullet.getX() + bulletDirection.stepX, bullet.getY() + bulletDirection.stepY);

      if (!nextQuadrant.isValid(battleField)) {
        bullet.destroy();
        break;
      }

      bullet.updateX(bulletDirection.stepX);
      bullet.updateY(bulletDirection.stepY);
      Thread.sleep(Bullet.SPEED);

      if (processInterception()) {
        bullet.destroy();
        break;
      }
    }
  }
Exemplo n.º 8
0
  //	private void initLevel(int level){//initializes levels according to the level parameter
  //
  //	}
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2d = (Graphics2D) g;

    // Windmill drawing
    g2d.rotate(wind.getDirection() * Math.PI / 180, 636, 64);
    g2d.drawImage(wind.getImage(), 572, 0, this);
    g2d.rotate(-wind.getDirection() * Math.PI / 180, 636, 64);

    // Boat drawing
    if (boat.isVisible()) {
      g2d.rotate(
          TIGHT_TURN_FACTOR * boat.getDirection() * Math.PI / 180,
          boat.getX() + 16,
          boat.getY() + 16);
      // g2d.drawImage(boat.getImage(), boat.getX(), boat.getY(), this);
      g2d.drawImage(boat.getImage(), boat.getX(), boat.getY(), this);
      // TEST-sınırları görmek için
      //			Rectangle r1 = boat.getBounds();
      //			g2d.drawRect(r1.x, r1.y, r1.width, r1.height);
      g2d.rotate(
          -TIGHT_TURN_FACTOR * boat.getDirection() * Math.PI / 180,
          boat.getX() + 16,
          boat.getY() + 16);
      if ((buoys.size() == 0)
          && (currentLevel
              <= LAST_LEVEL)) { // level atlama ve başarılı bir şekilde oyunu bitirme burada olacak
        System.out.println("All buoys finished, well done!");
        int tp = computeTotalScore();
        System.out.println("Total Score: " + tp);
        nextLevelFlag = true; // Actionlistenera tek seferlik girebilmek için bir flag
        // System.exit(0);
      }
    } else { // If boat is dead then check for remaining lives
      if (boat.getNumOfLives() > 0) {
        boat.decrementNumOfLives();
        boat.setPosition(0, 20);
        boat.setDirection(0);
        boat.setVisible(true);
      } else { // No remaining lives case
        // g2d.drawString("Game Over!", 80, 15);
        System.out.println("Game Over");
        int tp = computeTotalScore();
        System.out.println("Total Score: " + tp);
        currentLevel = 1;
        CardLayout c2 = (CardLayout) (mgf.getCanvas().getLayout());
        c2.show(mgf.getCanvas(), "GUI");
        // System.exit(0);
      }
    }

    // Island drawing
    for (int i = 0; i < islands.size(); i++) {
      Island is = (Island) islands.get(i);
      g2d.drawImage(is.getImage(), is.getX(), is.getY(), this);
    }

    // Bullet drawing
    ArrayList<Bullet> bs = boat.getBulletsList();
    for (int i = 0; i < bs.size(); i++) {
      Bullet b = (Bullet) bs.get(i);
      g2d.drawImage(b.getImage(), b.getX(), b.getY(), this);
    }

    // Buoy drawing
    for (int i = 0; i < buoys.size(); i++) {
      Buoy b = (Buoy) buoys.get(i);
      if (b.isVisible()) {
        g2d.drawImage(b.getImage(), b.getX(), b.getY(), this);
      }
    }

    // Bonus drawing
    for (int i = 0; i < bonuses.size(); i++) {
      Bonus b = (Bonus) bonuses.get(i);
      if (b.isVisible()) {
        g2d.drawImage(b.getImage(), b.getX(), b.getY(), this);
      } else {
        if (b.getBonusType().equalsIgnoreCase("lifebonus")) {
          boat.incrementNumOfLives();
        }
        if (b.getBonusType().equalsIgnoreCase("speedbonus")) {
          boat.setFlashForward(true);
        }
        if (b.getBonusType().equalsIgnoreCase("bulletbonus")) {
          boat.addBonusBullets();
        }
      }
    }

    // Information
    g2d.drawString("Buoys left: " + buoys.size(), 5, 15);

    if (boat.getNumOfLives() == 0) g2d.drawString("Last Chance!", 80, 15);
    else g2d.drawString("Lives: " + boat.getNumOfLives(), 90, 15);
    // g2d.drawString("-" + (int)System.currentTimeMillis()/1000, 5, 25);

    g2d.drawString("Score: " + gamePoint, 160, 15);
    g2d.drawString("Bullets: " + boat.getRemainingNumOfBullets(), 235, 15);
    g2d.drawString("Level: " + currentLevel, 320, 15);

    // Generates new random wind
    wind.generateWindDirection();

    // Default system methods
    Toolkit.getDefaultToolkit().sync(); // ?
    g.dispose(); // ?
  }
Exemplo n.º 9
0
  // Build the board with predetermined values for each object in the game
  private void buildBoardValue(Gameboard gameboard, Player player, Opponent opponent) {

    // resets the tilevalue, inReachTurrent and inReachBullet values
    for (int i = 0; i < gameboard.getWidth(); i++) {
      for (int j = 0; j < gameboard.getHeight(); j++) {
        tileValue[i][j] = 0;
        for (int k = 0; k < 4; k++) {
          inReachTurret[i][j][k] = null;
          inReachBullet[i][j][k] = null;
        }
      }
    }

    ArrayList<PowerUp> allPowerUps = gameboard.getPowerUps();

    // set the value for each powertype
    for (int i = 0; i < allPowerUps.size(); i++) {
      switch (allPowerUps.get(i).getPowerUpType()) {
        case SHIELD:
          tileValue[allPowerUps.get(i).getX()][allPowerUps.get(i).getY()] = 50;
          break;
        case LASER:
          tileValue[allPowerUps.get(i).getX()][allPowerUps.get(i).getY()] = 45;
          break;
        case TELEPORT:
          tileValue[allPowerUps.get(i).getX()][allPowerUps.get(i).getY()] = 40;
          break;
      }
    }

    ArrayList<Turret> allTurrets = gameboard.getTurrets();

    // sets the value according to condition of the bot
    for (int i = 0; i < allTurrets.size(); i++) {
      Turret t = allTurrets.get(i);
      tileValue[t.getX()][t.getY()] = -1000;
      if (!t.isDead()) {
        Boolean[] goDir = {true, true, true, true};

        int shieldVal = 0;
        if (player.isShieldActive()) {
          shieldVal = 100;
        } else if (player.getLaserCount() > 0) {
          shieldVal = 60;
        } else if (player.getShieldCount() > 0) {
          shieldVal = 43;
        } else {
          shieldVal = -10;
        }

        for (int j = 1; j <= 5; j++) {
          try {
            int nx, ny;
            nx = (t.getX() + j) % gameboard.getWidth();
            ny = t.getY();
            if (gameboard.isWallAtTile(nx, ny)) goDir[0] = false;
            else if (goDir[0]) {
              tileValue[nx][ny] = shieldVal;
              inReachTurret[nx][ny][returnNextIndex(inReachTurret[nx][ny])] = t;
            }
            nx = (t.getX() - j + gameboard.getWidth()) % gameboard.getWidth();
            ny = t.getY();
            if (gameboard.isWallAtTile(nx, ny)) goDir[1] = false;
            else if (goDir[1]) {
              tileValue[nx][ny] = shieldVal;
              inReachTurret[nx][ny][returnNextIndex(inReachTurret[nx][ny])] = t;
            }
            nx = t.getX();
            ny = (t.getY() + j) % gameboard.getHeight();
            if (gameboard.isWallAtTile(nx, ny)) goDir[2] = false;
            else if (goDir[2]) {
              tileValue[nx][ny] = shieldVal;
              inReachTurret[nx][ny][returnNextIndex(inReachTurret[nx][ny])] = t;
            }
            nx = t.getX();
            ny = (t.getY() - j + gameboard.getHeight()) % gameboard.getHeight();
            if (gameboard.isWallAtTile(nx, ny)) goDir[3] = false;
            else if (goDir[3]) {
              tileValue[nx][ny] = shieldVal;
              inReachTurret[nx][ny][returnNextIndex(inReachTurret[nx][ny])] = t;
            }
          } catch (Exception e) {
          }
        }
      }
    }

    // Adjust the tile values to incorporate whether the opponent has laser or not
    Boolean[] goDir = {true, true, true, true};
    if (opponent.getLaserCount() >= 1) {
      try {
        for (int j = 1; j <= 5; j++) {
          int nx, ny;
          nx = (opponent.getX() + j) % gameboard.getWidth();
          ny = opponent.getY();
          if (gameboard.isWallAtTile(nx, ny)) goDir[0] = false;
          else if (goDir[0]) {
            if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
            else tileValue[nx][ny] = -1;
          }
          nx = (opponent.getX() - j + gameboard.getWidth()) % gameboard.getWidth();
          ny = opponent.getY();
          if (gameboard.isWallAtTile(nx, ny)) goDir[1] = false;
          else if (goDir[1]) {
            if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
            else tileValue[nx][ny] = -1;
          }
          nx = opponent.getX();
          ny = (opponent.getY() + j) % gameboard.getHeight();
          if (gameboard.isWallAtTile(nx, ny)) goDir[2] = false;
          else if (goDir[2]) {
            if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
            else tileValue[nx][ny] = -1;
          }
          nx = opponent.getX();
          ny = (opponent.getY() - j + gameboard.getHeight()) % gameboard.getHeight();
          if (gameboard.isWallAtTile(nx, ny)) goDir[3] = false;
          else if (goDir[3]) {
            if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
            else tileValue[nx][ny] = -1;
          }
        }
      } catch (Exception e) {
      }
    }

    // modifies the gameboard tile vales to incorporate bullets
    for (int i = 0; i < gameboard.getBullets().size(); i++) {
      Bullet b = gameboard.getBullets().get(i);
      int h = gameboard.getHeight();
      int w = gameboard.getWidth();
      int nx, ny;
      switch (b.getDirection()) {
        case UP:
          nx = b.getX();
          ny = (b.getY() + h - 1) % h;
          if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
          else tileValue[nx][ny] = -2;
          inReachBullet[nx][ny][returnNextIndex(inReachBullet[nx][ny])] = b;
          break;
        case RIGHT:
          nx = (b.getX() + 1) % w;
          ny = b.getY();
          if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
          else tileValue[nx][ny] = -2;
          inReachBullet[nx][ny][returnNextIndex(inReachBullet[nx][ny])] = b;
          break;
        case DOWN:
          nx = b.getX();
          ny = (b.getY() + 1) % h;
          if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
          else tileValue[nx][ny] = -2;
          inReachBullet[nx][ny][returnNextIndex(inReachBullet[nx][ny])] = b;
          break;
        case LEFT:
          nx = (b.getX() + w - 1) % w;
          ny = b.getY();
          if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
          else tileValue[nx][ny] = -2;
          inReachBullet[nx][ny][returnNextIndex(inReachBullet[nx][ny])] = b;
          break;
      }
    }

    ArrayList<Wall> allWalls = gameboard.getWalls();

    for (int i = 0; i < allWalls.size(); i++) {
      tileValue[allWalls.get(i).getX()][allWalls.get(i).getY()] = -1000;
    }
  }