Esempio n. 1
0
        public override Path Route(Road previous, int moveCount, Path result = null)
        {
            if (previous == null)
            {
                throw new ArgumentNullException(nameof(previous));
            }
            if (!CanEnterFrom(previous))
            {
                throw new ArgumentException($"无法通过{nameof(previous)}进入此道路", nameof(previous));
            }
            if (moveCount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(moveCount));
            }
            if (!Exits.Any( ))
            {
                throw new InvalidOperationException("没有可用的出口");
            }

            Path current = result ?? new Path( );

            current.AddRoute(this);
            if (BlockMoving || moveCount == 0)
            {
                return(current);
            }

            List <Road> exits = Exits.Where(road => road != previous).ToList( );

            if (exits.Count == 0)
            {
                return(previous.Route(this, moveCount - 1, result));
            }

            return(exits.RandomItem( ).Route(this, moveCount - 1, result));
        }
Esempio n. 2
0
 public override bool CanEnterFrom(Road road)
 {
     return(Entrances.Contains(road));
 }
Esempio n. 3
0
 /// <summary>
 ///     获取能否从某个道路进入这个道路
 /// </summary>
 /// <param name="road">前一个道路</param>
 /// <returns>能否进入</returns>
 public abstract bool CanEnterFrom(Road road);
Esempio n. 4
0
 /// <summary>
 ///     获取路径的末端和末端之前的路径
 /// </summary>
 /// <param name="previous">前一个路径</param>
 /// <param name="moveCount">能延长的路径长度</param>
 /// <param name="result"></param>
 /// <returns>路径</returns>
 public abstract Path Route(Road previous, int moveCount, Path result = null);