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


C# Random.NextTexture方法代码示例

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


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

示例1: Generate

 protected override void Generate(District district, TileBuilder[,] tiles,
     int borderLeft, int borderTop,
     int borderRight, int borderBottom, Random rand)
 {
     GenHelper.BuildFloor(tiles, borderLeft, borderTop,
         district.Width - borderLeft - borderRight,
         district.Height - borderTop - borderBottom,
         0, (x, y) => rand.NextTexture("floor/concrete", 4));
 }
开发者ID:alexturpin,项目名称:Zombles,代码行数:9,代码来源:Empty.cs

示例2: Generate

        public override void Generate(District district, TileBuilder[,] tiles, Random rand)
        {
            Face entryFaces = Face.None;

            for (int i = 0; i < 4; ++i)
                entryFaces |= rand.NextFace();

            int fenceHeight = rand.NextDouble() < 0.8 ? 2 : 1;

            Func <int, int, Face, bool, ResourceLocator> wallFunc = (horzPos, level, face, isInterior) => {
                if ((entryFaces & face) != Face.None) {
                    if (face == Face.North || face == Face.South) {
                        if (Math.Abs(horzPos * 2 - SizeX + 1) < 3)
                            return "";
                    } else {
                        if (Math.Abs(horzPos * 2 - SizeY + 1) < 3)
                            return "";
                    }
                }

                if (level < fenceHeight - 1)
                    return "wall/brick0/0";
                return "wall/fence/0";
            };
            Func <int, int, ResourceLocator> floorFunc = (horzPos, vertPos) => {
                return rand.NextTexture("floor/grass", 4);
            };
            GenHelper.BuildFloor(tiles, X, Y, SizeX, SizeY, 0, floorFunc);

            if (Fence) {
                GenHelper.BuildWall(tiles, X, Y, Face.North, SizeX, fenceHeight, wallFunc);
                GenHelper.BuildWall(tiles, X + SizeX - 1, Y, Face.East, SizeY, fenceHeight, wallFunc);
                GenHelper.BuildWall(tiles, X, Y + SizeY - 1, Face.South, SizeX, fenceHeight, wallFunc);
                GenHelper.BuildWall(tiles, X, Y, Face.West, SizeY, fenceHeight, wallFunc);
            }
        }
开发者ID:alexturpin,项目名称:Zombles,代码行数:36,代码来源:Park.cs

示例3: Generate

        public override void Generate(District district, TileBuilder[,] tiles, Random rand)
        {
            if (EntranceFaces != Face.None) {
                int rheight = rand.Next(3) + 4;

                ResourceLocator wallGroup = "wall/brick" + rand.Next(2);

                GenHelper.BuildRoof(tiles, X, Y, SizeX, SizeY, rheight, "floor/roof/0");

                Func<int,int,Face,bool,ResourceLocator> texFunc = (horzpos, level, face, isInterior) => {
                    if (level < rheight)
                        return rand.NextTexture(wallGroup, 4);

                    return wallGroup["7"];
                };

                GenHelper.BuildWall(tiles, X, Y, Face.North, SizeX, rheight + 1, texFunc);
                GenHelper.BuildWall(tiles, X, Y, Face.West, SizeY, rheight + 1, texFunc);
                GenHelper.BuildWall(tiles, X, Y + SizeY - 1, Face.South, SizeX, rheight + 1, texFunc);
                GenHelper.BuildWall(tiles, X + SizeX - 1, Y, Face.East, SizeY, rheight + 1, texFunc);
                
                var entrFace = rand.NextFace(EntranceFaces);
                var doorway = new GarageDoor {
                    Direction = entrFace,
                    LeftBorderTile = wallGroup["8"],
                    RightBorderTile = wallGroup["9"],
                    BothBorderTile = wallGroup["a"],
                    Width = rand.Next(2, 4),
                    Height = 3,
                    DoorTile = "wall/garage/0"
                };

                switch (entrFace) {
                    case Face.North:
                        doorway.X = X + 1;
                        doorway.Y = Y;
                        break;
                    case Face.South:
                        doorway.X = X + 1;
                        doorway.Y = Y + SizeY - 1;
                        break;
                    case Face.East:
                        doorway.X = X + SizeX - 1;
                        doorway.Y = Y + 1;
                        break;
                    case Face.West:
                        doorway.X = X;
                        doorway.Y = Y + 1;
                        break;
                }

                var dx = 1 - Math.Abs(entrFace.GetNormalX());
                var dy = 1 - dx;

                int count = 1;
                if (dx == 1) {
                    count = (SizeX - 1) / (doorway.Width + 1);
                } else {
                    count = (SizeY - 1) / (doorway.Width + 1);
                }

                int closed = rand.Next(0, count);
                var indices = Enumerable.Range(0, count).ToList();

                while (closed-- > 0) indices.RemoveAt(rand.Next(indices.Count));

                for (int i = 0; i < count; ++i) {
                    if (indices.Contains(i)) {
                        doorway.DoorPosition = 2;
                    } else {
                        doorway.DoorPosition = 0;
                    }

                    doorway.Generate(district, tiles, rand);
                    doorway.GenerateOpposite(district, tiles, rand);
                    doorway.X += dx * (doorway.Width + 1);
                    doorway.Y += dy * (doorway.Width + 1);
                }

                new Rooms.Warehouse {
                    X = X, Y = Y, SizeX = SizeX, SizeY = SizeY, Height = rheight
                }.Generate(district, tiles, rand);
            }
        }
开发者ID:alexturpin,项目名称:Zombles,代码行数:84,代码来源:Warehouse.cs

示例4: Generate

        public Block Generate(District district, int borderLeft, int borderTop,
            int borderRight, int borderBottom, Random rand)
        {
            int width = district.Width;
            int height = district.Height;

            TileBuilder[,] tiles = new TileBuilder[width, height];

            for (int tx = 0; tx < width; ++tx) for (int ty = 0; ty < height; ++ty)
                    tiles[tx, ty] = new TileBuilder();

            int innerLeft = borderLeft;
            int innerTop = borderTop;
            int innerRight = width - borderRight;
            int innerBottom = height - borderBottom;
            int innerWidth = width - borderLeft - borderRight;
            int innerHeight = height - borderTop - borderBottom;

            Func<int, int, ResourceLocator> roadFunc = delegate(int tx, int ty) {
                return rand.NextTexture("floor/road/", 0, 4);
            };

            GenHelper.BuildFloor(tiles, 0, 0, width, height, 0, roadFunc);
            GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, innerWidth + 2, innerHeight + 2, 0,
                (x, y) => {
                    if (Tools.Random.NextDouble() < 0.75) {
                        return "floor/concrete/0";
                    } else {
                        return Tools.Random.NextTexture("floor/concrete", 1, 4);
                    }
                });

            int texOffset = 0; bool horz = false;
            Func<int, int, ResourceLocator> pavementFunc = delegate(int tx, int ty) {
                if ((horz && tx % 8 == 4) || (!horz && ty % 8 == 4))
                    return "floor/pavement/" + (texOffset + 2).ToString("X").ToLower();

                return rand.NextTexture("floor/pavement/", texOffset, texOffset + 2);
            };

            if (borderBottom > 1) {
                texOffset = 0; horz = true;
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerBottom, innerWidth + 2, 1, 0, pavementFunc);
            }
            if (borderRight > 1) {
                texOffset = 4; horz = false;
                GenHelper.BuildFloor(tiles, innerRight, innerTop - 1, 1, innerHeight + 2, 0, pavementFunc);
            }
            if (borderTop > 1) {
                texOffset = 8; horz = true;
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, innerWidth + 2, 1, 0, pavementFunc);
            }
            if (borderLeft > 1) {
                texOffset = 12; horz = false;
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, 1, innerHeight + 2, 0, pavementFunc);
            }

            if (borderBottom > 1 && borderRight > 1)
                GenHelper.BuildFloor(tiles, innerRight, innerBottom, 1, 1, 0, "floor/pavement/3");
            if (borderTop > 1 && borderRight > 1)
                GenHelper.BuildFloor(tiles, innerRight, innerTop - 1, 1, 1, 0, "floor/pavement/7");
            if (borderTop > 1 && borderLeft > 1)
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, 1, 1, 0, "floor/pavement/b");
            if (borderBottom > 1 && borderLeft > 1)
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerBottom, 1, 1, 0, "floor/pavement/f");

            Generate(district, tiles, borderLeft, borderTop, borderRight, borderBottom, rand);

            Block block = new Block(district);
            block.BuildTiles(tiles);
            return block;
        }
开发者ID:alexturpin,项目名称:Zombles,代码行数:72,代码来源:BlockGenerator.cs


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