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


C# IGrid.SetCell方法代码示例

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


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

示例1: GenerateGrid

        /// <summary>
        /// Generete game field
        /// </summary>
        /// <param name="grid">Field member</param>
        /// <param name="player"Player member></param>
        /// <returns>Genereted game filed</returns>
        public IGrid GenerateGrid(IPlayer player, IGrid grid)
        {
            DefaultRandomGenerator random = DefaultRandomGenerator.Instance();
            int percentageOfBlockedCells = random.Next(GlobalConstants.MinimumPercentageOfBlockedCells, GlobalConstants.MaximumPercentageOfBlockedCells);

            for (int row = 0; row < grid.TotalRows; row++)
            {
                for (int col = 0; col < grid.TotalCols; col++)
                {
                    int num = random.Next(0, 100);
                    if (num < percentageOfBlockedCells)
                    {
                        grid.SetCell(row, col, GlobalConstants.BlockedCellSymbol);
                    }
                    else
                    {
                        grid.SetCell(row, col, GlobalConstants.FreeCellSymbol);
                    }
                }
            }

            grid.SetCell(grid.TotalRows / 2, grid.TotalCols / 2, GlobalConstants.PlayerSignSymbol);

            this.MakeAtLeastOneExitReachable(grid, player);
            return grid;
        }
开发者ID:TeamLabyrinth5-Telerik,项目名称:Labyrinth,代码行数:32,代码来源:Initializer.cs

示例2: MakeAtLeastOneExitReachable

        /// <summary>
        /// Маке аt least one possible way out of the maze
        /// </summary>
        /// <param name="generatedGrid">Genereted game field</param>
        /// <param name="player">Player member</param>
        public void MakeAtLeastOneExitReachable(IGrid generatedGrid, IPlayer player)
        {
            DefaultRandomGenerator random = DefaultRandomGenerator.Instance();
            int[] dirX = { 0, 0, 1, -1 };
            int[] dirY = { 1, -1, 0, 0 };
            int numberOfDirections = 4;

            while (this.IsGameOver(player, generatedGrid) == false)
            {
                int randomIndex = random.Next(0, numberOfDirections);

                var nextPosition = new Position(player.Position.X + dirX[randomIndex], player.Position.Y + dirY[randomIndex]);

                if (this.IsInsideGrid(nextPosition, generatedGrid))
                {
                    player.Position = nextPosition;
                    generatedGrid.SetCell(player.Position.X, player.Position.Y, GlobalConstants.FreeCellSymbol);
                }
            }

            player.Position = new Position(generatedGrid.TotalRows / 2, generatedGrid.TotalCols / 2);
            generatedGrid.SetCell(generatedGrid.TotalRows / 2, generatedGrid.TotalCols / 2, GlobalConstants.PlayerSignSymbol);
        }
开发者ID:TeamLabyrinth5-Telerik,项目名称:Labyrinth,代码行数:28,代码来源:Initializer.cs


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