当前位置: 首页>>代码示例>>C#>>正文


C# Random.Item方法代码示例

本文整理汇总了C#中System.Random.Item方法的典型用法代码示例。如果您正苦于以下问题:C# Random.Item方法的具体用法?C# Random.Item怎么用?C# Random.Item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Random的用法示例。


在下文中一共展示了Random.Item方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateVoxelMap

        private MyMwcObjectBuilder_VoxelMap GenerateVoxelMap(int sizeInVoxels, Vector3 positionInSector, Random rnd, List<MyMwcVoxelFilesEnum> voxelAsteroids, MyWeightDictionary<MyMwcVoxelMaterialsEnum> primaryMaterials, MyWeightDictionary<MyMwcVoxelMaterialsEnum> secondaryMaterials)
        {
            int sizeInMeters = sizeInVoxels;// (int)(sizeInVoxels * MyVoxelConstants.VOXEL_SIZE_IN_METRES);
            voxelAsteroids.Clear();
            MyVoxelMap.GetAsteroidsBySizeInMeters(sizeInMeters, voxelAsteroids, false);
            int rndIndex = rnd.Next(0, voxelAsteroids.Count);

            MyMwcVoxelMaterialsEnum mainMat = MyMwcVoxelMaterialsEnum.Stone_01;
            if (primaryMaterials.Count > 0)
            {
                primaryMaterials.GetRandomItem(rnd);
            }

            MyMwcObjectBuilder_VoxelMap builder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.VoxelMap, null) as MyMwcObjectBuilder_VoxelMap;
            builder.VoxelFile = rnd.Item(voxelAsteroids);
            builder.VoxelMaterial = mainMat;
            builder.PositionAndOrientation = new MyMwcPositionAndOrientation(positionInSector, Vector3.Forward, Vector3.Up);

            AddMergeContent(rnd, voxelAsteroids, sizeInMeters, builder);
            AddVeins(secondaryMaterials, rnd, positionInSector, 2, sizeInMeters, builder, VeinAngleDeviation, MaxLevel, BaseSecondaryMaterialThickness);

            return builder;
        }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:23,代码来源:MySectorGenerator.cs

示例2: GenerateStations

        private void GenerateStations(MyMwcVector3Int sector, MySolarSystemMapData solarData, MySolarSystemMapSectorData sectorData, List<MyMwcObjectBuilder_Base> addToList, Random rnd, MyDynamicAABBTree prunningStructure)
        {
            Dictionary<MyMwcVector3Int, MyMwcObjectBuilder_SectorObjectGroups> groupCache = new Dictionary<MyMwcVector3Int, MyMwcObjectBuilder_SectorObjectGroups>();

            //List<MyImportantSolarObject>
            var objects = solarData.ImportantObjects.Where(o => o.NavigationMark.Sector.Equals(sector));

            foreach(var obj in objects)
            {
                var size = MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER / 1000;
                Vector3? pos = FindEntityPosition(prunningStructure, rnd, size);
                if (pos.HasValue)
                {
                    var templateSector = MyTemplateGroups.GetGroupSector(obj.TemplateGroup);
                    MyMwcObjectBuilder_SectorObjectGroups groups;
                    if (!groupCache.TryGetValue(templateSector, out groups))
                    {
                        groups = LoadObjectGroups(templateSector);
                        if (groups == null)
                        {
                            return;
                        }
                        groupCache.Add(templateSector, groups);
                    }

                    sectorData.Entities.Add(new MySolarSystemMapEntity(sector, pos.Value, size, "", MySolarSystemEntityEnum.OutpostIcon));

                    var group = rnd.Item(groups.Groups);
                    IEnumerable<MyMwcObjectBuilder_PrefabBase> prefabs = group.GetPrefabBuilders(groups.Entities);
                    IEnumerable<MyMwcObjectBuilder_Base> rootObjects = group.GetRootBuilders(groups.Entities);
                    var objects3d = rootObjects.OfType<MyMwcObjectBuilder_Object3dBase>();

                    var faction = MyFactions.GetFactionBySector(sector);

                    var objectPos = pos.Value;
                    if (objects3d.Any())
                    {
                        var firstPos = objects3d.First().PositionAndOrientation.Position;
                        var offset = objectPos - firstPos;

                        foreach (var o in objects3d)
                        {
                            // Clone
                            var clone = o.Clone() as MyMwcObjectBuilder_Object3dBase;
                            clone.PositionAndOrientation.Position += offset;
                            clone.ClearEntityId();
                            if (clone is MyMwcObjectBuilder_PrefabContainer)
                            {
                                ((MyMwcObjectBuilder_PrefabContainer)clone).Faction = faction;
                            }
                            if (clone is MyMwcObjectBuilder_SpawnPoint)
                            {
                                ((MyMwcObjectBuilder_SpawnPoint)clone).Faction = faction;
                            }
                            addToList.Add(clone);
                        }
                    }
                    else if(prefabs.Any())
                    {
                        MyMwcObjectBuilder_PrefabContainer container = new MyMwcObjectBuilder_PrefabContainer(null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE,
                            prefabs.ToList(), 0, faction, null);

                        var clone = container.Clone() as MyMwcObjectBuilder_PrefabContainer; // To clone children easily
                        clone.ClearEntityId(); // Clear childs ids
                        clone.PositionAndOrientation = new MyMwcPositionAndOrientation(objectPos, Vector3.Forward, Vector3.Up);
                        addToList.Add(clone);
                    }
                } //end of station generation

                if (pos.HasValue && rnd.Float(0, 1) < 0.5f)
                { //Create mysterious cube at 1% of stations
                    var sizeMyst = size * 1.5f;
                    Vector3? posMyst = FindEntityPosition(prunningStructure, rnd, sizeMyst, 1.0f, 1.0f, pos.Value);
                    if (posMyst.HasValue)
                    {
                        CreateMysteriousCubes(posMyst.Value, addToList, rnd);
                    }

                    //Create some more
                    int count = rnd.Next(5);
                    for (int i = 0; i < count; i++)
                    {
                        var size2 = MyMwcSectorConstants.SECTOR_SIZE / 2;
                        Vector3? pos2 = FindEntityPosition(prunningStructure, rnd, size2);
                        if (pos2.HasValue)
                        {
                            CreateMysteriousCubes(pos2.Value, addToList, rnd);
                        }
                    }
                }
            }
        }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:92,代码来源:MySectorGenerator.cs

示例3: CreateMysteriousCube

        private void CreateMysteriousCube(Vector3 posMyst, List<MyMwcObjectBuilder_Base> addToList, Random rnd)
        {
            MyMwcObjectBuilder_MysteriousCube mysteriousCube = new MyMwcObjectBuilder_MysteriousCube(
            new MyMwcPositionAndOrientation(posMyst, Vector3.Forward, Vector3.Up)
            );

            MyMwcObjectBuilder_MysteriousCube_TypesEnum cubeType = (MyMwcObjectBuilder_MysteriousCube_TypesEnum)rnd.Item(Enum.GetValues(typeof(MyMwcObjectBuilder_MysteriousCube_TypesEnum)));
            mysteriousCube.MysteriousCubeType = cubeType;
            addToList.Add(mysteriousCube);
        }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:10,代码来源:MySectorGenerator.cs

示例4: GenerateSectorObjectBuildersFromSolarEntities

        public void GenerateSectorObjectBuildersFromSolarEntities(List<MySolarSystemMapEntity> entities, List<MyMwcObjectBuilder_Base> addToList, Random rnd, MyWeightDictionary<MyMwcVoxelMaterialsEnum> primaryMaterials, MyWeightDictionary<MyMwcVoxelMaterialsEnum> secondaryMaterials, MyStaticAsteroidTypeSetEnum staticAsteroidTypesets, MyMwcVoxelMaterialsEnum? fieldMaterial = null, MySolarSystemArea.AreaEnum? areaType = null)
        {
            List<MyMwcObjectBuilder_StaticAsteroid_TypesEnum> asteroids = new List<MyMwcObjectBuilder_StaticAsteroid_TypesEnum>(5);
            List<MyMwcVoxelFilesEnum> voxelAsteroids = new List<MyMwcVoxelFilesEnum>(10);

            int count = addToList.Count;

            foreach (var e in entities)
            {
                if (e.EntityType == MySolarSystemEntityEnum.VoxelAsteroid)
                {
                    int voxelAsteroidSize = FindAsteroidSize(e.Radius, MyVoxelMap.AsteroidSizes);

                    int rndIndex = rnd.Next(0, voxelAsteroids.Count);

                    MyVoxelMap.GetAsteroidsBySizeInMeters(voxelAsteroidSize, voxelAsteroids, false);

                    MyMwcObjectBuilder_VoxelMap builder = GenerateVoxelMap(voxelAsteroidSize, e.PositionInSector, rnd, voxelAsteroids, primaryMaterials, secondaryMaterials);

                    addToList.Add(builder);
                }
                else if (e.EntityType == MySolarSystemEntityEnum.StaticAsteroid)
                {
                    float radius = 100;
                    if (e.Radius == 10000)
                        radius = rnd.Next(2000, 11000);
                    if (e.Radius == 1000)
                        radius = rnd.Next(100, 1100);
                    if (e.Radius == 100)
                        radius = rnd.Next(10, 100);


                    MyMwcVoxelMaterialsEnum asteroidMaterial = MyMwcVoxelMaterialsEnum.Stone_01;
                    if (primaryMaterials.Count > 0)
                        primaryMaterials.GetRandomItem(rnd);

                    MyStaticAsteroidTypeSetEnum asteroidType = MyStaticAsteroidTypeSetEnum.A;

                    //for (int i = 0; i < 40000000; i++)
                    {
                        asteroidType = (MyStaticAsteroidTypeSetEnum)rnd.Item(Enum.GetValues(typeof(MyStaticAsteroidTypeSetEnum)));
                    }

                    if ((staticAsteroidTypesets & MyStaticAsteroidTypeSetEnum.A) == MyStaticAsteroidTypeSetEnum.A)
                        asteroidType = MyStaticAsteroidTypeSetEnum.A;
                    if ((staticAsteroidTypesets & MyStaticAsteroidTypeSetEnum.B) == MyStaticAsteroidTypeSetEnum.B)
                        asteroidType = MyStaticAsteroidTypeSetEnum.B;
                    if ((staticAsteroidTypesets & MyStaticAsteroidTypeSetEnum.All) == MyStaticAsteroidTypeSetEnum.All)
                        asteroidType = rnd.Float(0, 1) > 0.5f ? MyStaticAsteroidTypeSetEnum.A : MyStaticAsteroidTypeSetEnum.B;

                    var builder = GenerateStaticAsteroid(radius, asteroidType, asteroidMaterial, e.PositionInSector, rnd, asteroids);

  
                    builder.AsteroidMaterial1 = fieldMaterial;
                    if (areaType == MySolarSystemArea.AreaEnum.Sun)
                    {
                        builder.FieldDir = MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized();
                    }

                    builder.Generated = true;
                    addToList.Add(builder);

                 
                    //MyEntity ent = MyEntities.CreateFromObjectBuilderAndAdd(null, new MyMwcObjectBuilder_StaticAsteroid(asteroids[rndIndex], mat),
                    //    Matrix.CreateWorld(e.PositionInSector, rnd.Vector(1), rnd.Vector(1)));
                }
                else if (e.EntityType == MySolarSystemEntityEnum.LargeShip)
                {
                    var shipType = rnd.Enum<MyMwcObjectBuilder_PrefabLargeShip_TypesEnum>();
                    MyMwcObjectBuilder_Prefab_AppearanceEnum appearance = rnd.Enum<MyMwcObjectBuilder_Prefab_AppearanceEnum>();

                    var ship = new MyMwcObjectBuilder_PrefabLargeShip(shipType, appearance, new MyMwcVector3Short(0, 0, 0), rnd.Vector(1), null, rnd.FloatNormal(), "Abandoned large ship", 0, false, 0);                    
                    var gamePlayProperties = MyGameplayConstants.GetGameplayProperties(MyMwcObjectBuilderTypeEnum.PrefabLargeShip, (int)shipType, MyMwcObjectBuilder_FactionEnum.Euroamerican);
                    ship.PrefabHealthRatio = MyGameplayConstants.HEALTH_RATIO_MAX;
                    ship.PrefabMaxHealth = gamePlayProperties.MaxHealth;
                    var prefabs = new List<MyMwcObjectBuilder_PrefabBase>();
                    prefabs.Add(ship);
                    var container = new MyMwcObjectBuilder_PrefabContainer(0, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, prefabs, 0, rnd.Enum<MyMwcObjectBuilder_FactionEnum>(), null);
                    container.PositionAndOrientation = new MyMwcPositionAndOrientation(e.PositionInSector, Vector3.Forward, Vector3.Up);
                    addToList.Add(container);
                }
                else if (e.EntityType == MySolarSystemEntityEnum.DebrisField)
                {
                    MyMwcObjectBuilder_LargeDebrisField objectBuilder = new MyMwcObjectBuilder_LargeDebrisField(MyMwcObjectBuilder_LargeDebrisField_TypesEnum.Debris84);
                    objectBuilder.PositionAndOrientation = new MyMwcPositionAndOrientation(e.PositionInSector, rnd.Vector(1), rnd.Vector(1));
                    addToList.Add(objectBuilder);
                }
            }
        }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:89,代码来源:MySectorGenerator.cs


注:本文中的System.Random.Item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。