コード例 #1
0
        private List <DistrictCell> GenerateDistrictCells(VoronoiDiagram voronoi)
        {
            //Create a district cell from the voronoi cells
            var districtCells = new List <DistrictCell>();

            foreach (var cell in voronoi.GetCellsInBounds())
            {
                //ignore cells that are not valid
                if (cell.Edges.Count < 2)
                {
                    continue;
                }

                districtCells.Add(DistrictCell.FromCell(cell, _citySettings.DistrictSettings[0].Type));
            }


            //tag random cells based on the settings for each district
            foreach (var setting in _citySettings.DistrictSettings)
            {
                for (int i = 0; i < setting.Frequency; ++i)
                {
                    //Get a random start cell from the voronoi
                    var startCell = districtCells.GetRandomValue();

                    //size is a ratio of the width and length of the plane
                    var size = setting.Size * ((voronoi.Bounds.Right + voronoi.Bounds.Bottom) / 8);

                    //tag cell
                    districtCells.TagCells(startCell, size, setting.Type);
                }
            }

            return(districtCells);
        }
コード例 #2
0
        private static List <ProjectSkill> GenerateProjectSkills(ProjectInfo projectInfo, int projectCount)
        {
            List <ProjectSkill> projectSkills = new List <ProjectSkill>();
            List <string>       skills        = DataLists.Skills;

            for (int k = 0; k < projectCount; k++)
            {
                if (skills.Count <= 0)
                {
                    break;
                }

                string skillName = skills.GetRandomValue();
                skills.Remove(skillName);

                projectSkills.Add(new ProjectSkill {
                    ProjectId = projectInfo.Id, SkillName = skillName
                });
            }

            return(projectSkills);
        }
コード例 #3
0
ファイル: Shop.cs プロジェクト: VoodooStu/UnicornSequleJam
        /// <summary>
        /// Get a random available skin in _subCategoryDataSkin.
        /// Returns null if there is none.
        /// </summary>
        /// <param name="subCategorySkinData"></param>
        /// <returns></returns>
        public Skin GetSkin(SubCategorySkinData subCategorySkinData)
        {
            Skin skin = null;

            foreach (var category in shopData.categories)
            {
                if (category.subCategories.Contains(subCategorySkinData))
                {
                    List <Skin> subCategorySkins = new List <Skin>(subCategorySkinData.skins);
                    subCategorySkins.RemoveAll(x => x.IsCollected);

                    if (subCategorySkins.Count <= 0)
                    {
                        continue;
                    }

                    skin = subCategorySkins.GetRandomValue();
                }
            }

            return(skin);
        }
コード例 #4
0
ファイル: RoadBuilder.cs プロジェクト: TobieD/City-Generator
        /// <summary>
        /// Keep generating roads until branches are zero
        /// </summary>
        private List<Road> GenerateRoad(List<Road> roads,List<Road> inner , Road startLine ,Road endLine, int branches)
        {
            //find a new start and end point
            var start = startLine.Center();
            var end = endLine.Center();

            //When an intersection occurs break the line
            HandlePossibleRoadIntersections(new Line(start,end),startLine,endLine, roads, inner);

            //reduce branches to end recursion
            branches--;
            if (branches + 1 <= 0)
            {
                roads.AddRange(inner);
                return roads;
            }

            //From the pool of lines choose 2 random ones that aren't the same
            var road1 = roads.GetRandomValue();
            var road2 = roads.GetRandomValue();
            //make sure both are unique
            while (road1 == road2)
            {
                road2 = roads.GetRandomValue();
            }

            //generate a new road by connecting 2 roads
            return GenerateRoad(roads, inner, road1, road2, branches);
        }
コード例 #5
0
 public Vector2 RandomEnemySpawnPosition()
 {
     return(listSpawnPointEnemy.GetRandomValue().position.ToVector2());
 }
コード例 #6
0
        private List<DistrictCell> GenerateDistrictCells(VoronoiDiagram voronoi)
        {
            //Create a district cell from the voronoi cells
            var districtCells = new List<DistrictCell>();
            foreach (var cell in voronoi.GetCellsInBounds())
            {
                //ignore cells that are not valid
                if (cell.Edges.Count < 2)
                {
                    continue;
                }

                districtCells.Add(DistrictCell.FromCell(cell,_citySettings.DistrictSettings[0].Type));
            }

            //tag random cells based on the settings for each district
            foreach (var setting in _citySettings.DistrictSettings)
            {
                for (int i = 0; i < setting.Frequency; ++i)
                {
                    //Get a random start cell from the voronoi
                    var startCell = districtCells.GetRandomValue();

                    //size is a ratio of the width and length of the plane
                    var size = setting.Size * ((voronoi.Bounds.Right + voronoi.Bounds.Bottom)/8);

                    //tag cell
                    districtCells.TagCells(startCell, size, setting.Type);
                }
            }

            return districtCells;
        }