Пример #1
0
    private List<Vector2> findNeigboursForNode(NodeController node, List<Vector2> neighbours)
    {
        neighbours.Clear();
        Vector2 nodeLocation = node.getNodeCoordinates();

        for (int xOffset = -1; xOffset<=1; xOffset++)
        {
            int neighbourX = (int)nodeLocation.x + xOffset;

            if (neighbourX < 0 ||
                neighbourX >= boardWidth) continue;

            for (int yOffset = -1; yOffset<= 1; yOffset++)
            {
                int neighbourY = (int)nodeLocation.y + yOffset;

                if(neighbourY < 0 ||
                   neighbourY >= boardHeight ||
                   (neighbourX == nodeLocation.x && neighbourY == nodeLocation.y)) continue;

                Vector2 neighbourLocalCoordinates = new Vector2(neighbourX, neighbourY);
                neighbours.Add (neighbourLocalCoordinates);
            }
        }
        return neighbours;
    }