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


C# Random.GetRandomDirections方法代码示例

本文整理汇总了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);
		}
开发者ID:Foxbow74,项目名称:my-busycator,代码行数:74,代码来源:TreeMazeDungeonLayer.cs

示例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;
		}
开发者ID:Foxbow74,项目名称:my-busycator,代码行数:28,代码来源:LayerHelper.cs


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