Пример #1
0
        /// <summary>
        /// Drunken walk or Kill until its not possible anymore
        /// </summary>
        private void Kill()
        {
            while (PathStillUseable(_currentRow, _currentColumn))
            {
                int direction = RandomDirection.Random();

                if (direction == RandomDirection.North && CellAvailable(_currentRow - 1, _currentColumn)) //North
                {
                    DestroyWall(Cells[_currentRow, _currentColumn].WallNorthObject);
                    DestroyWall(Cells[_currentRow - 1, _currentColumn].WallSouthObject);
                    _currentRow--;
                }
                else if (direction == RandomDirection.South && CellAvailable(_currentRow + 1, _currentColumn)) //South
                {
                    DestroyWall(Cells[_currentRow, _currentColumn].WallSouthObject);
                    DestroyWall(Cells[_currentRow + 1, _currentColumn].WallNorthObject);
                    _currentRow++;
                }
                else if (direction == RandomDirection.East && CellAvailable(_currentRow, _currentColumn + 1)) //East
                {
                    DestroyWall(Cells[_currentRow, _currentColumn].WallEastObject);
                    DestroyWall(Cells[_currentRow, _currentColumn + 1].WallWestObject);
                    _currentColumn++;
                }
                else if (direction == RandomDirection.West && CellAvailable(_currentRow, _currentColumn - 1)) //West
                {
                    DestroyWall(Cells[_currentRow, _currentColumn].WallWestObject);
                    DestroyWall(Cells[_currentRow, _currentColumn - 1].WallEastObject);
                    _currentColumn--;
                }

                Cells[_currentRow, _currentColumn].Visited = true;
            }
        }
Пример #2
0
        /// <summary>
        /// destroys the neighboring wall to continue building the maze
        /// </summary>
        /// <param name="row">the row position of the cell</param>
        /// <param name="column">the column position of the cell</param>
        private void DestroyNeighboringWall(int row, int column)
        {
            bool destroyedWall = false;

            while (!destroyedWall)
            {
                int direction = RandomDirection.Random();

                if (direction == RandomDirection.North && row > 0 && Cells[row - 1, column].Visited) //North
                {
                    DestroyWall(Cells[row, column].WallNorthObject);
                    DestroyWall(Cells[row - 1, column].WallSouthObject);
                    destroyedWall = true;
                }
                else if (direction == RandomDirection.South && row < (Rows - 2) && Cells[row + 1, column].Visited) //South
                {
                    DestroyWall(Cells[row, column].WallSouthObject);
                    DestroyWall(Cells[row + 1, column].WallNorthObject);
                    destroyedWall = true;
                }
                else if (direction == RandomDirection.West && column > 0 && Cells[row, column - 1].Visited) //West
                {
                    DestroyWall(Cells[row, column].WallWestObject);
                    DestroyWall(Cells[row, column - 1].WallEastObject);
                    destroyedWall = true;
                }
                else if (direction == RandomDirection.East && column < (Columns - 2) && Cells[row, column + 1].Visited) //East
                {
                    DestroyWall(Cells[row, column].WallEastObject);
                    DestroyWall(Cells[row, column + 1].WallWestObject);
                    destroyedWall = true;
                }
            }
        }