Example #1
0
    public void RemoveObstacle_OutOfMaterix()
    {
        Vector2 obstaclePosition = new Vector2(5, 3);

        AStarBase aStar = new AStarBase(10, 10);

        aStar.SetObstacle(obstaclePosition);

        aStar.RemoveObstacle(new Vector2(100, 5));
        aStar.RemoveObstacle(new Vector2(5, 100));
        aStar.RemoveObstacle(new Vector2(-10, 5));
        aStar.RemoveObstacle(new Vector2(5, -10));

        for (int x = 0; x < aStar.matrix.GetLength(0); x++)
        {
            for (int y = 0; y < aStar.matrix.GetLength(1); y++)
            {
                if (x != (int)obstaclePosition.x || y != (int)obstaclePosition.y)
                {
                    Assert.IsTrue(aStar.matrix[x, y].canThrough);
                }
                else
                {
                    Assert.IsFalse(aStar.matrix[x, y].canThrough);
                }
            }
        }
    }
Example #2
0
    public void RemoveObstacle_Normal()
    {
        Vector2 obstaclePosition = new Vector2(5, 3);

        AStarBase aStar = new AStarBase(10, 10);

        aStar.SetObstacle(obstaclePosition);
        aStar.RemoveObstacle(obstaclePosition);

        foreach (AstarBaseNode node in aStar.matrix)
        {
            Assert.IsTrue(node.canThrough);
        }
    }
Example #3
0
    void MouseMiddleDown()
    {
        Vector2 position = GetMousePosition();

        AstarBaseNode node = _aStar.GetNode(position);

        if (node == null)
        {
            return;
        }

        if (node.canThrough)
        {
            _aStar.SetObstacle(position);
        }
        else
        {
            _aStar.RemoveObstacle(position);
        }

        DoFindPath();
    }