/// <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);
		}
Exemple #2
0
		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;
		}