예제 #1
0
 public void BottomLeftWorks()
 {
     Assert.AreEqual(point.BottomLeft(), new Point2D(4, 4));
 }
        private bool isValidCarvePoint(Maze maze, Point2D origin, Point2D option)
        {
            // Can't carve the outer wall of the maze or things out of bounds.
            if (option.x < 1)
            {
                return(false);
            }
            if (option.y < 1)
            {
                return(false);
            }
            // Has already been carved.
            if (!maze.hasWallAt(option))
            {
                return(false);
            }

            List <Point2D> pointsToCheck = new List <Point2D>()
            {
                // Check surrounding points
                option.Up(),
                           option.Down(),
                           option.Left(),
                           option.Right(),
                // Also want the corner points
                           option.TopLeft(),
                           option.TopRight(),
                           option.BottomLeft(),
                           option.BottomRight()
            };

            foreach (Point2D point in pointsToCheck)
            {
                // Don't disqualify if we are looking at the origin
                if (point.Equals(origin))
                {
                    continue;
                }
                // Or something connected to the origin!
                if (point.Equals(origin.Up()))
                {
                    continue;
                }
                if (point.Equals(origin.Down()))
                {
                    continue;
                }
                if (point.Equals(origin.Left()))
                {
                    continue;
                }
                if (point.Equals(origin.Right()))
                {
                    continue;
                }
                // All other points should be walls?
                if (!maze.hasWallAt(point))
                {
                    return(false);
                }
            }

            return(true);
        }