Exemplo n.º 1
0
  private static ArrayList<Towers> FindSilenceTower(
      int direction, FieldIndex startPoint, boolean[][] cluster) {
    // checks for the two last pieces of a silence tower in the given direction
    // startPoint should be the second index
    // returns number of found towers

    ArrayList<Towers> towerList = new ArrayList<Towers>();
    FieldIndex right = startPoint.Right(direction);
    FieldIndex left = startPoint.Left(direction);
    boolean leftPart = left.Valid() && cluster[left.x()][left.y()];
    boolean rightPart = right.Valid() && cluster[right.x()][right.y()];

    if (leftPart) {
      FieldIndex up = left.Up(direction);
      if (up.Valid() && cluster[up.x()][up.y()]) {
        Towers leftTower = new Towers(startPoint, direction); // initing the tower
        leftTower.add(left);
        leftTower.add(up);
        leftTower.towerType = SkillType.SILENCE;
        towerList.add(leftTower);
      }
    }
    if (rightPart) {
      FieldIndex up = right.Up(direction);
      if (up.Valid() && cluster[up.x()][up.y()]) {
        Towers rightTower = new Towers(startPoint, direction); // initing the tower
        rightTower.add(right);
        rightTower.add(up);
        rightTower.towerType = SkillType.SILENCE;
        towerList.add(rightTower);
      }
    }
    return towerList;
  }
Exemplo n.º 2
0
  private static ArrayList<SkillType> FindTowersInCluster(boolean[][] cluster, Player player) {
    // checks if there is a piece in front of the given piece,
    // if there is, there might be a tower; calling specific find-tower functions
    // does this for all 8 directions.

    ArrayList<Towers> towerList = new ArrayList<Towers>();
    for (int nx = 0;
        nx < Gameboard.COLUMNS_AND_ROWS;
        nx++) { // checking for all elements in the cluster...
      for (int ny = 0; ny < Gameboard.COLUMNS_AND_ROWS; ny++) {
        if (cluster[nx][ny]) {

          for (int i = 0; i < 8; i++) { // ...in all directions
            FieldIndex f = new FieldIndex(nx, ny);
            FieldIndex start = f.Up(i);
            if (start.Valid() && cluster[start.x()][start.y()]) {
              towerList.addAll(FindShootTower(i, start, cluster));
              towerList.addAll(FindBuildTower(i, start, cluster));
              if (i < 4) {
                towerList.addAll(FindSilenceTower(i, start, cluster));
                towerList.addAll(FindFiveTower(i, start, cluster));
              }
              if (i < 2) {
                towerList.addAll(FindMultipleSkillsTower(i, start, cluster));
              }
            }
          }
        }
      }
    }
    ArrayList<SkillType> skillList = new ArrayList<SkillType>();
    // marking the positions of the towers as built:

    // Gdx.app.log("Tower", "found "+Integer.toString(towerList.size())+" towers:");
    for (Towers t : towerList) {
      // Gdx.app.log("", t.toString());
      if (!player.isSilenced()) {
        for (FieldIndex f : t.tower) {
          if (!f.Valid()) {
            Gdx.app.error("Tower", "Invalid Tower: " + t.toString());
          }
          Game.getInstance().getGameboard().setMarkToBuilt(f.x(), f.y(), player);
        }
      }
      skillList.add(t.towerType);
    }
    return skillList;
  }
Exemplo n.º 3
0
  private static ArrayList<Towers> FindMultipleSkillsTower(
      int direction, FieldIndex startPoint, boolean[][] cluster) {
    // checks for the two last pieces of a multiple-skills tower in the given direction
    // startPoint should be the second index
    // returns number of found towers

    ArrayList<Towers> towerList = new ArrayList<Towers>();
    FieldIndex right = startPoint.Right(direction);
    if (right.Valid() && cluster[right.x()][right.y()]) {
      FieldIndex down = right.Down(direction);
      if (down.Valid() && cluster[down.x()][down.y()]) {
        Towers tower = new Towers(startPoint, direction); // initing the tower
        tower.add(right);
        tower.add(down);
        tower.towerType = SkillType.SKILLCAP;
        towerList.add(tower);
      }
    }
    return towerList;
  }
Exemplo n.º 4
0
  private static ArrayList<Towers> FindShootTower(
      int direction, FieldIndex startPoint, boolean[][] cluster) {
    // checks for the two last pieces of a shoot tower in the given direction
    // startpoint should be the second index
    // returns number of found towers

    FieldIndex right = startPoint.Right(direction);
    FieldIndex left = startPoint.Left(direction);
    boolean leftPart = left.Valid() && cluster[left.x()][left.y()];
    boolean rightPart = right.Valid() && cluster[right.x()][right.y()];

    ArrayList<Towers> towerList = new ArrayList<Towers>();

    if (leftPart && rightPart) {
      Towers tow = new Towers(startPoint, direction);
      tow.add(left);
      tow.add(right);
      tow.towerType = SkillType.SHOOT;
      towerList.add(tow);
    }
    return towerList;
  }
Exemplo n.º 5
0
 private static ArrayList<Towers> FindFiveTower(
     int direction, FieldIndex startPoint, boolean[][] cluster) {
   // checks for the three last pieces of a five-in-a-row tower in the given direction
   // startPoint should be the second index
   // returns a list of found towers
   ArrayList<Towers> towerList = new ArrayList<Towers>();
   Towers tower = new Towers(startPoint, direction);
   FieldIndex up = startPoint.Up(direction);
   if (up.Valid() && cluster[up.x()][up.y()]) {
     tower.add(up);
     up = up.Up(direction);
     if (up.Valid() && cluster[up.x()][up.y()]) {
       tower.add(up);
       up = up.Up(direction);
       if (up.Valid() && cluster[up.x()][up.y()]) {
         tower.add(up);
         towerList.add(tower);
         Game.getInstance().setShowVictoryScreen(true);
         return towerList;
       }
     }
   }
   return towerList; // returning the empty tower list
 }