本文整理汇总了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;
}
示例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);
}