Esempio n. 1
0
 private static void DetectNearby(List <TileManager.PathResult> openList, TileManager.PathResult checkCell, int moveCost)
 {
     openList.Add(new TileManager.PathResult
     {
         NowCell = new Point(checkCell.NowCell.X - 1, checkCell.NowCell.Y),
         Parent  = checkCell.NowCell,
         MovLeft = checkCell.MovLeft - moveCost
     });
     openList.Add(new TileManager.PathResult
     {
         NowCell = new Point(checkCell.NowCell.X + 1, checkCell.NowCell.Y),
         Parent  = checkCell.NowCell,
         MovLeft = checkCell.MovLeft - moveCost
     });
     openList.Add(new TileManager.PathResult
     {
         NowCell = new Point(checkCell.NowCell.X, checkCell.NowCell.Y - 1),
         Parent  = checkCell.NowCell,
         MovLeft = checkCell.MovLeft - moveCost
     });
     openList.Add(new TileManager.PathResult
     {
         NowCell = new Point(checkCell.NowCell.X, checkCell.NowCell.Y + 1),
         Parent  = checkCell.NowCell,
         MovLeft = checkCell.MovLeft - moveCost
     });
 }
Esempio n. 2
0
        public List <TileManager.PathResult> GetPathAttack(int x, int y, int atkCount, byte myCamp)
        {
            List <TileManager.PathResult> openList  = new List <TileManager.PathResult>();
            List <TileManager.PathResult> closeList = new List <TileManager.PathResult>();
            var srcPoint = new TileManager.PathResult {
                NowCell = new Point(x, y), Parent = new Point(-1, -1), MovLeft = atkCount
            };

            openList.Add(srcPoint);
            while (openList.Count > 0)
            {
                var oldOpenList = openList.ToArray();
                openList.Clear();
                foreach (var openCell in oldOpenList)
                {
                    if (openCell.NowCell.X >= width || openCell.NowCell.X < 0 || openCell.NowCell.Y >= height || openCell.NowCell.Y < 0)
                    {
                        continue; //非法节点
                    }
                    var closeNode = closeList.Find(p => p.NowCell.X == openCell.NowCell.X && p.NowCell.Y == openCell.NowCell.Y);
                    if (closeNode != null && closeNode.MovLeft >= openCell.MovLeft)
                    {
                        continue;              //已经遍历过
                    }
                    var myCost = 1;            //攻击射程固定消耗1点
                    if (openCell.Parent.X < 0) //初始格不算消耗
                    {
                        myCost = 0;
                    }
                    if (openCell.MovLeft < myCost) //步数不足
                    {
                        continue;
                    }

                    if (closeNode != null)
                    {
                        closeNode.MovLeft = openCell.MovLeft;
                        closeNode.Parent  = openCell.Parent;
                    }
                    else
                    {
                        closeList.Add(openCell);
                    }

                    if (openCell.MovLeft <= 0)
                    {
                        continue;
                    }

                    DetectNearby(openList, openCell, myCost);
                }
            }

            closeList.Remove(srcPoint);
            closeList.RemoveAll(node => TileManager.Instance.GetTile(node.NowCell.X, node.NowCell.Y).Camp == myCamp); //把同阵营剔除

            return(closeList);
        }