示例#1
0
 private bool CanReach(Point start, int x, int y, bool IsIgnoreCorner)
 {
     if (!CanReach(x, y) || ListHelp.Exists(CloseList, x, y))
     {
         return(false);
     }
     else
     {
         //判断是否是上下左右走
         if (System.Math.Abs(x - start.X) + System.Math.Abs(y - start.Y) == 1)
         {
             return(true);
         }
         //如果是斜方向移动, 判断是否 "拌脚"
         else
         {
             if (CanReach(start.X, y) || CanReach(x, start.Y))
             {
                 return(true);
             }
             else
             {
                 return(IsIgnoreCorner);
             }
         }
     }
 }
示例#2
0
 //一次寻路的函数,因为路径找的时候是从end到start,所以已经把函数中所有的end的地方和start的地方互换了
 public void FindOncePath(Point start, Point end, bool IsIgnoreCorner)
 {
     OpenList.Add(end);
     while (OpenList.Count != 0)
     {
         //找出F值最小的点
         Point tempStart = ListHelp.MinPoint(ref OpenList);//ref为引用调用
         OpenList.RemoveAt(0);
         CloseList.Add(tempStart);
         //找出它相邻的点
         List <Point> surroundPoints = SurroundPoints(tempStart, IsIgnoreCorner);
         foreach (Point point in surroundPoints)
         {
             if (ListHelp.Exists(OpenList, point))
             {
                 //如果已经在开始列表里了,计算G值, 如果比原来的大, 就什么都不做, 否则设置它的父节点为当前点,并更新G和F
                 FoundPoint(tempStart, point);
             }
             else
             {
                 //如果它们不在开始列表里, 就加入, 并设置父节点,并计算GHF
                 NotFoundPoint(tempStart, start, point);
             }
         }
         if (ListHelp.Get(OpenList, start) != null)
         {
             parent = ListHelp.Get(OpenList, start);
             return;
         }
     }
     parent = ListHelp.Get(OpenList, start);
 }