/** * 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); }
/** * 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; }
/** * Creates random circles on a map. Currently the only map generation algorithm. * * @param f Used field * @param n Number of circles * @param maxr Maximal radius of circles */ public static void randomCircles(Field f, int n, double maxr) { for (int i = 0; i < n; i++) { f.createCircle( new Vector2D(rand.nextDouble() * f.getTilesX(), rand.nextDouble() * f.getTilesY()), rand.nextDouble() * maxr); } }