本文整理汇总了C#中Random.DivFour方法的典型用法代码示例。如果您正苦于以下问题:C# Random.DivFour方法的具体用法?C# Random.DivFour怎么用?C# Random.DivFour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Random
的用法示例。
在下文中一共展示了Random.DivFour方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PaintRoom
void PaintRoom(ProcRoom room)
{
bool successful = false;
int attempts = 0;
map.BeginBulkEdit();
while (!successful && attempts < 5)
{
// get random coordinates to attempt to place new room
// int originX = (int) MLib.NextGaussian(mapColumns / 2, mapColumns / 2, mapMarginX, mapColumns);
// int originY = (int) MLib.NextGaussian(mapRows / 2, mapRows / 2, mapMarginY, mapRows);
Random rand = new Random();
int originX = rand.DivFour(mapMarginX, mapColumns - mapMarginX);
int originY = rand.DivFour(mapMarginY, mapRows - mapMarginY);
// check that room will fit within map bounds
if (RoomInBounds(originX, originY, room) &&
!TouchingRooms(originX, originY, room))
{
// paint room
for (int x = 0; x < room.width; x++)
{
for (int y = 0; y < room.height; y++)
{
map.EraseTile(originY + y, originX + x);
map.RefreshSurroundingTiles(originY + y, originX + x);
}
}
// with room succesfully placed, set origin then add to List
room.originX = originX;
room.originY = originY;
rooms.Add(room);
successful = true;
}
attempts++;
}
map.EndBulkEdit();
}