本文整理汇总了C#中System.Random.GetRandomDirections方法的典型用法代码示例。如果您正苦于以下问题:C# Random.GetRandomDirections方法的具体用法?C# Random.GetRandomDirections怎么用?C# Random.GetRandomDirections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Random
的用法示例。
在下文中一共展示了Random.GetRandomDirections方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddConnectionPoints
/// <summary>
/// добавление коридоров, идущих из комнат
/// </summary>
private IEnumerable<ConnectionPoint> AddConnectionPoints(BaseMapBlock _block, Room _room, Random _rnd)
{
if (_block.BlockId == BaseMapBlock.GetBlockId(EnterCoords) &&
_room.RoomRectangle.Contains(BaseMapBlock.GetInBlockCoords(EnterCoords)))
{
_room.IsConnected = true;
}
var trys = 0;
do
{
trys++;
var cps = new List<ConnectionPoint>();
var dirs = _rnd.GetRandomDirections();
foreach (var dir in dirs.AllDirectionsIn())
{
int val;
Point begin;
switch (dir)
{
case EDirections.UP:
val = _room.RoomRectangle.Left + _rnd.Next(_room.RoomRectangle.Width);
begin = new Point(val, _room.RoomRectangle.Top - 1);
break;
case EDirections.DOWN:
val = _room.RoomRectangle.Left + _rnd.Next(_room.RoomRectangle.Width);
begin = new Point(val, _room.RoomRectangle.Bottom);
break;
case EDirections.LEFT:
val = _room.RoomRectangle.Top + _rnd.Next(_room.RoomRectangle.Height);
begin = new Point(_room.RoomRectangle.Left - 1, val);
break;
case EDirections.RIGHT:
val = _room.RoomRectangle.Top + _rnd.Next(_room.RoomRectangle.Height);
begin = new Point(_room.RoomRectangle.Right, val);
break;
default:
throw new ArgumentOutOfRangeException();
}
var end = begin;
var delta = dir.GetDelta();
if (!m_mazeBlocks.ContainsKey(BaseMapBlock.GetBlockId(begin + _block.BlockId*Constants.MAP_BLOCK_SIZE + delta*Constants.MAP_BLOCK_SIZE)))
{
continue;
}
do
{
end += delta;
if (!_room.AreaRectangle.Contains(end)) break;
} while (true);
cps.Add(new ConnectionPoint(begin + _block.BlockId*Constants.MAP_BLOCK_SIZE, end + _block.BlockId*Constants.MAP_BLOCK_SIZE, _room, dir));
}
if (cps.Count > 1 || (trys > 5 && cps.Count > 0) || trys > 20)
{
foreach (var connectionPoint in cps)
{
yield return connectionPoint;
}
break;
}
} while (true);
}
示例2: Add
private static IEnumerable<Point> Add(Point _xy, EMapBlockTypes[,] _map, ref int _size, EMapBlockTypes _set, Random _rnd, EMapBlockTypes _empty)
{
var list = new List<Point>();
if (_map[_xy.X, _xy.Y] == _empty)
{
list.Add(_xy);
_map[_xy.X, _xy.Y] = _set;
if (_size == 0 || _rnd.NextDouble() < 0.1)
{
return list;
}
_size--;
}
var dirs = _rnd.GetRandomDirections();
foreach (var dir in dirs.AllDirectionsIn())
{
var xy = _xy + dir.GetDelta();
if (_map.GetLength(0) <= xy.X || xy.X < 0) continue;
if (_map.GetLength(1) <= xy.Y || xy.Y < 0) continue;
if (_map[xy.X, xy.Y] == _empty)
{
list.AddRange(Add(xy, _map, ref _size, _set, _rnd, _empty));
}
}
return list;
}