本文整理汇总了C#中Grid.Fill方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.Fill方法的具体用法?C# Grid.Fill怎么用?C# Grid.Fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grid
的用法示例。
在下文中一共展示了Grid.Fill方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GridRun_ValidCells_ReturnsTrue
public void GridRun_ValidCells_ReturnsTrue()
{
var inputCells = new List<Cell>();
// row 0
inputCells.Add(new Cell(ColourEnum.Blue, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Red));
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Blue, ColourEnum.Yellow));
inputCells.Add(new Cell(ColourEnum.Blue, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Red));
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Red, ColourEnum.Blue));
// row 1
inputCells.Add(new Cell(ColourEnum.Red, ColourEnum.Blue, ColourEnum.Red, ColourEnum.Blue));
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Yellow, ColourEnum.Red));
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Red));
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Blue));
// row 2
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Blue, ColourEnum.Yellow));
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Blue));
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Red));
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Blue, ColourEnum.Red));
// row 3
inputCells.Add(new Cell(ColourEnum.Blue, ColourEnum.Red, ColourEnum.Blue, ColourEnum.Yellow));
inputCells.Add(new Cell(ColourEnum.Yellow, ColourEnum.Blue, ColourEnum.Blue, ColourEnum.Red));
inputCells.Add(new Cell(ColourEnum.Blue, ColourEnum.Yellow, ColourEnum.Red, ColourEnum.Red));
inputCells.Add(new Cell(ColourEnum.Red, ColourEnum.Blue, ColourEnum.Yellow, ColourEnum.Blue));
var grid = new Grid(6, true);
grid.Fill(inputCells);
grid.Print();
Assert.IsTrue(grid.IsComplete());
}
示例2: TownQuarter
/// <summary>
/// Creates new town quarter as map fragment. Generates roads, buildings, etc.
/// </summary>
/// <param name="size">Size of quarter without joining interface</param>
/// <param name="degree">Number of quarter's interfaces (joining streets)</param>
public TownQuarter(ActionGame game, Vector2 size, int degree)
{
owner = EmptyTownQuarterOwner.Instance;
this.game = game;
interfaces = new List<TownQuarterInterface>(degree);
if (nameRepository.Count > 0)
{
Random rand = new Random();
int nameIndex = rand.Next(0, nameRepository.Count - 1);
Name = nameRepository[nameIndex];
nameRepository.RemoveAt(nameIndex);
}
else
{
Name = emptyName;
}
int xSize = (int)Math.Floor(size.X / SquareWidth);
int ySize = (int)Math.Floor(size.Y / SquareWidth);
bitmapSize = new System.Drawing.Size(xSize, ySize);
mapBitmap = new MapFillType[bitmapSize.Width * bitmapSize.Height];
for (int i = 0; i < mapBitmap.Length; i++)
mapBitmap[i] = MapFillType.Empty;
spaceGrid = new Grid(bitmapSize.Width, bitmapSize.Height, GridFiledWidth, GridFiledWidth);
try
{
Generate(degree);
}
catch (Exception ex)
{
if (Name != emptyName)
{
nameRepository.Add(Name);
}
throw ex;
}
spaceGrid.Fill(GetAllSolidObjects());
}
示例3: FixRoads
public static List<GPoint> FixRoads (Grid g, List<GPoint> rVHplusO, Vector2 blockSize)
{
//we will need to create a temporary grid that contains all of the new points
//then iterate through it by the blocksize as done earlier
//for each intersection check if there is a road to the left or down
//if there is one left, then create a vertical road as done earlier
//if there is one down, then create a horizontal road as done earlier
//also create an intersection at the point
List<GPoint> fixedRoads = new List<GPoint> ();
Grid tG = new Grid (g);
tG.Fill (GPoint.PType.TILE_GRASS);
tG.UpdatePoints (rVHplusO);
for (float ix=1.0f; ix<tG.GetXYMax().x; ix+=blockSize.x) {
//iterate up by blocksize
for (float iy=1.0f; iy<tG.GetXYMax().y; iy+=blockSize.y) {
//iterate right by blocksize
//set the scan point to the current position on the grid
ScanPoint sp1 = new ScanPoint (new Vector2 (ix, iy));
//move the scanpoint to the left and check if is anything but background
if (!tG.GetPoint (sp1.VirtualMove (Direction.w)).IsBackgroundTile ()) {
//create a vertical road blocksize.y units long
//probably going to do this with a for loop
fixedRoads.Add (new GPoint (sp1.Position (), GPoint.PType.TILE_ROADI));
fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x, sp1.Position ().y + blockSize.y), GPoint.PType.TILE_ROADI));
for (float iy2 = 1.0f; iy2<blockSize.y; iy2+=1.0f) {
fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x, sp1.Position ().y + iy2), GPoint.PType.TILE_ROADV));
}
}
if (!tG.GetPoint (sp1.VirtualMove (Direction.s)).IsBackgroundTile ()) {
//create a horizontal road blocksize.x units long
//probably going to do this with a for loop
fixedRoads.Add (new GPoint (sp1.Position (), GPoint.PType.TILE_ROADI));
fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x + blockSize.x, sp1.Position ().y), GPoint.PType.TILE_ROADI));
for (float ix2 = 1.0f; ix2<blockSize.x; ix2+=1.0f) {
fixedRoads.Add (new GPoint (new Vector2 (sp1.Position ().x + ix2, sp1.Position ().y), GPoint.PType.TILE_ROADH));
}
}
}
}
return fixedRoads;
}
示例4: FillTarget
public void FillTarget(Grid<Tile> target, Point2 offset)
{
target.Fill(new Tile(), 0, 0, target.Width, target.Height);
}
示例5: CopySelect
[Test] public void CopySelect()
{
Grid<int> sourceGrid = new Grid<int>(4, 4);
Grid<string> targetGrid = new Grid<string>(4, 4);
sourceGrid.Fill(7, 1, 1, 2, 2);
targetGrid.Fill("Keep", 0, 0, 2, 2);
sourceGrid.CopyTo(targetGrid, selector: (i, s) => s != "Keep" ? i.ToString() : s);
CollectionAssert.AreEqual(new[] {
"Keep", "Keep", "0", "0",
"Keep", "Keep", "7", "0",
"0", "7", "7", "0",
"0", "0", "0", "0" }, targetGrid);
}
示例6: CopyConvert
[Test] public void CopyConvert()
{
Grid<int> sourceGrid = new Grid<int>(4, 4);
Grid<float> targetGrid = new Grid<float>(4, 4);
sourceGrid.Fill(7, 1, 1, 2, 2);
sourceGrid.CopyTo(targetGrid);
CollectionAssert.AreEqual(new[] {
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 7.0f, 7.0f, 0.0f,
0.0f, 7.0f, 7.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f }, targetGrid);
}
示例7: Fill
[Test] public void Fill()
{
Grid<int> grid = new Grid<int>(4, 4);
grid.Fill(7, 1, 1, 2, 2);
CollectionAssert.AreEqual(new[] {
0, 0, 0, 0,
0, 7, 7, 0,
0, 7, 7, 0,
0, 0, 0, 0 }, grid);
}