Ejemplo n.º 1
0
  public static boolean findTowers(int x, int y, Player activePlayer) {
    // The input variables is the position of the new mark.
    // Find towers by iterating from that square on the board
    // Returning a bool; true if one or more towers has been found
    boolean[][] field = new boolean[Gameboard.COLUMNS_AND_ROWS][Gameboard.COLUMNS_AND_ROWS];
    for (int i = 0; i < Gameboard.COLUMNS_AND_ROWS; i++) { // initializing the array...
      for (int j = 0; j < Gameboard.COLUMNS_AND_ROWS; j++) {
        field[i][j] = false;
      }
    }

    // 1. find cluster around x,y
    field = FindClusterRecurse(new FieldIndex(x, y), field, activePlayer.getActiveMark());

    // printing the cluster for debug:
    //		Gdx.app.log("Tower", "Found cluster:");
    //		for(int i=0; i<Gameboard.NUMBER_OF_ROWS; i++){
    //			String s = "";
    //			for(int j=0; j<Gameboard.NUMBER_OF_COLUMNS; j++){
    //				if(field[j][Gameboard.NUMBER_OF_ROWS-i-1])
    //					s += "*";
    //				else
    //					s += " ";
    //			}
    //			Gdx.app.log("", s);
    //		}

    // 2. find towers in this cluster
    ArrayList<SkillType> skillList = FindTowersInCluster(field, activePlayer);

    // 3. adding skills to the player
    String debugString = "";
    if (!activePlayer.isSilenced()) {

      for (SkillType s : skillList) {
        if (s == SkillType.SHOOT) {
          activePlayer.addShootCount();
          debugString += "shoot, ";
        } else if (s == SkillType.BUILD) {
          activePlayer.addBuildCount();
          debugString += "build, ";
        } else if (s == SkillType.SILENCE) {
          activePlayer.addSilenceCount();
          debugString += "silence, ";
        } else if (s == SkillType.SKILLCAP) {
          activePlayer.addSkillCap();
          debugString += "skillCap, ";
        }
      }
    }
    Gdx.app.log("Tower", "Found skills: " + debugString);
    return !skillList.isEmpty();
  }
Ejemplo 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;
  }