Пример #1
0
    public static List <ANode> CalClosedNode(this ANode node, Dictionary <string, ANode> nodeDict, List <ANode> closedList)
    {
        List <ANode> returnList = new List <ANode>();

        if (node == null)
        {
            return(null);
        }
        var offset = node.offset;

        //下面是四个方向的~~~~~~判断 可以做成一个方法
        ANode tempNode = null;

        nodeDict.TryGetValue((node.x + offset).ToString() + node.y, out tempNode);
        if (tempNode != null && tempNode.canReached == true && !closedList.Contains(tempNode))
        {
            tempNode.SetParentNode(node);
            returnList.Add(tempNode);
        }

        tempNode = null;
        nodeDict.TryGetValue((node.x - offset).ToString() + node.y, out tempNode);
        if (tempNode != null && tempNode.canReached == true && !closedList.Contains(tempNode))
        {
            tempNode.SetParentNode(node);
            returnList.Add(tempNode);
        }

        tempNode = null;
        nodeDict.TryGetValue(node.x.ToString() + (node.y + offset), out tempNode);
        if (tempNode != null && tempNode.canReached == true && !closedList.Contains(tempNode))
        {
            tempNode.SetParentNode(node);
            returnList.Add(tempNode);
        }

        tempNode = null;
        nodeDict.TryGetValue(node.x.ToString() + (node.y + offset), out tempNode);
        if (tempNode != null && tempNode.canReached == true && !closedList.Contains(tempNode))
        {
            tempNode.SetParentNode(node);
            returnList.Add(tempNode);
        }

        //nodeList = new List<ANode>{new ANode(node.x+offset,node.y),new ANode(node.x-offset,node.y),
        //    new ANode(node.x,node.y+offset),new ANode(node.x,node.y-offset)
        //};

        return(returnList);
    }