Beispiel #1
0
        internal override MazeTransformationStep TryPlaceExit()
        {
            List <MazeCoordinate> possibleExits = new List <MazeCoordinate>();

            // collect all possible exits
            for (int i = CurrentMaze.GetWidth() - 2; i >= 1; i--)
            {
                possibleExits.Add(new MazeCoordinate(i, downright.Y));
            }

            // check in random order if exit is valid
            while (possibleExits.Count > 0)
            {
                var possibleExit = possibleExits.ElementAt(Random.Next(possibleExits.Count));

                if (CurrentMaze.GetMazeTypeOnPos(possibleExit.X, possibleExit.Y + 1) == MazeFieldType.Corridor)
                {
                    return(CurrentMaze.SetMazeTypeOnPos(possibleExit, MazeFieldType.Exit));
                }
                else
                {
                    possibleExits.Remove(possibleExit);
                }
            }

            // TODO Maybe not the best way to handle this, but the maze is useless without valid exit.
            throw new Exception("Could not find a suitable exit position.");
        }
Beispiel #2
0
        public override IEnumerable <MazeTransformationStep> InitializeMaze()
        {
            downright = new MazeCoordinate(CurrentMaze.GetWidth() - 1, 0);
            upperleft = new MazeCoordinate(0, CurrentMaze.GetHeight() - 1);

            CurrentMaze.OverrideAllMazeFields(MazeFieldType.Wall);
            return(null);
        }
Beispiel #3
0
 internal override MazeTransformationStep TryPlaceEntrance()
 {
     // no need to check, the nature of the algorithm will guarantee that all positions on this side are valid entrances.
     return(this.CurrentMaze.SetMazeTypeOnPos(Random.Next(1, CurrentMaze.GetWidth() - 2), 0, MazeFieldType.Entrance));
 }