コード例 #1
0
ファイル: BinaryTree.cs プロジェクト: z0dd42d1/MazeLib
        internal override MazeTransformationStep TryPlaceExit()
        {
            List <MazeCoordinate> possibleExits = new List <MazeCoordinate>();

            // collect all possible exits
            for (int y = CurrentMaze.GetHeight() - 2; y >= CurrentMaze.GetHeight() / 2; y--)
            {
                possibleExits.Add(new MazeCoordinate(0, y));
            }

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

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

            throw new Exception("Could not place a valid exit.");
        }
コード例 #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);
        }