當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。