Exemple #1
0
 /**
  * Finds valid start position for the Unit
  *
  * @param f Used field
  * @return Valid position
  */
 public static Vector2D findStartPos(Field f) {
   Point start = new Point(rand.nextInt(f.getTilesX()), rand.nextInt(f.getTilesY()));
   Tile[][] tiles = f.getTiles();
   while (tiles[start.x][start.y].getValue() == 1)
     start = new Point(rand.nextInt(f.getTilesX()), rand.nextInt(f.getTilesY()));
   return f.getWorldPos(start);
 }
Exemple #2
0
  /**
   * Generates randomly spread towers on a map
   *
   * @param f Used field
   * @param n Number of towers
   * @param g Used game
   * @return List of towers
   */
  public static ArrayList<Entity> randomTowers(Field f, int n, Core g, ArrayList<Team> teams) {
    ArrayList<Entity> list = new ArrayList<Entity>();
    Tile[][] tiles = f.getTiles();
    for (int i = 0; i < n; i++) {
      Point tower = new Point(rand.nextInt(f.getTilesX()), rand.nextInt(f.getTilesY()));
      while (tiles[tower.x][tower.y].getValue() == 1)
        tower = new Point(rand.nextInt(f.getTilesX()), rand.nextInt(f.getTilesY()));

      int team = rand.nextInt(teams.size());
      list.add(new Tower(f.getWorldPos(tower), teams.get(team)));
    }
    return list;
  }