コード例 #1
0
ファイル: Pathfinder.cs プロジェクト: midgithub/KouXiaGu
        /// <summary>
        /// 开始寻路;若无法找到目标点则返回异常;
        /// </summary>
        public WayPath <T> Search(IWalker <T> map, IRange <T> searchRange, T starting, T destination)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            if (searchRange == null)
            {
                throw new ArgumentNullException("searchRange");
            }

            Walker      = map;
            SearchRange = searchRange;
            Starting    = starting;
            Destination = destination;

            if (starting.Equals(destination))
            {
                throw new ArgumentException("起点与终点为同一个位置;");
            }
            if (SearchRange.IsOutRange(Destination))
            {
                throw new DestinationNotFoundException("目的地超出了最大搜索范围的定义;");
            }
            if (IsTrapped(Starting))
            {
                throw new TrappedException("起点周围不可行走,物体可能被困住;");
            }
            if (IsTrapped(Destination))
            {
                throw new TrappedException("目的地本身或周围不可行走;");
            }

            return(Search());
        }