Exemple #1
0
 /// <summary>
 /// Hides the maze solution
 /// </summary>
 /// <param name="sender">No implementation</param>
 /// <param name="e">No implementation</param>
 private void hideSolutionClick(object sender, RoutedEventArgs e)
 {
     solutionButton.Visibility     = Visibility.Visible;
     hideSolutionButton.Visibility = Visibility.Hidden;
     staticMaze     = originalWinMaze;
     solutionExists = true;
     printMaze(staticMaze, staticMaze.PosZ);
 }
Exemple #2
0
        public void printMaze(WinMaze winMaze, int floor)
        {
            if ((winMaze.PosZ == 0) && (winMaze.PosX == (winMaze.getMaze().MyColumns - 1)) &&
                (winMaze.PosY == (winMaze.getMaze().MyRows - 1)) && !mFinished)
            {
                mFinished = true;
                FinishWindow finishWindow = new FinishWindow();
                finishWindow.Show();
            }

            staticMaze = winMaze;
            if (solutionExists)
            {
                solutionExists = false;
                winMaze        = originalWinMaze;
                winMaze.clearSolution();
            }
            else
            {
                originalWinMaze = winMaze;
            }

            MazeBoard mazeBoard = new MazeBoard(winMaze, winMaze.PosZ, winMaze.CellSize, 0);

            cnvs_main.Children.Clear();
            cnvs_main.Children.Add(mazeBoard);
            Canvas.SetLeft(mazeBoard, 30);
            Canvas.SetTop(mazeBoard, 10);
            cnvs_second.Children.Clear();

            if ((winMaze.PosZ + 1) < winMaze.getMaze().MyHeight)
            {
                MazeBoard upMazeBoard = new MazeBoard(winMaze, floor, 10, 1);
                cnvs_second.Children.Add(upMazeBoard);
                Canvas.SetLeft(upMazeBoard, 0);
                Canvas.SetTop(upMazeBoard, 30);
            }

            if ((winMaze.PosZ - 1) >= 0)
            {
                MazeBoard downMazeBoard = new MazeBoard(winMaze, floor, 10, -1);
                cnvs_second.Children.Add(downMazeBoard);
                Canvas.SetLeft(downMazeBoard, 0);
                Canvas.SetTop(downMazeBoard, 200);
            }
            mazeExists = true;
            staticMaze = winMaze;
            Debug.WriteLine("exiting printmaze");
        }
 /// <summary>
 /// MazeBoard Constructor
 /// </summary>
 /// <param name="maze">Current WinMaze</param>
 /// <param name="floor">Current floor</param>
 /// <param name="mazeCellSize">Size of the cells</param>
 /// <param name="showLevel">Show this/lower/upper level</param>
 public MazeBoard(WinMaze maze, int floor, int mazeCellSize, int showLevel)
 {
     InitializeComponent();
     if (showLevel == 0) // Current
     {
         CreateMaze(maze, floor, mazeCellSize);
     }
     if (showLevel == 1) // Up
     {
         CreateMaze(maze, floor + 1, mazeCellSize);
     }
     if (showLevel == -1) // Down
     {
         CreateMaze(maze, floor - 1, mazeCellSize);
     }
 }
Exemple #4
0
        /// <summary>
        /// MyPresenter Constructor
        /// </summary>
        /// <param name="model">Current Model</param>
        /// <param name="view">Current View (WPF)</param>
        public MyPresenter(IModel model, IView view)
        {
            m_commands = new Dictionary <string, ICommand>();
            m_model    = model;
            m_view     = view;

            m_view.ViewStart += delegate()  // View Start
            {
                createConsoleCommands();
                m_commands = m_view.getAllCommands();
            };

            m_view.ViewChanged += delegate()  // View Changed
            {
                string[] userCommand = m_view.getUserCommand();
                string   commandName = m_view.getUserCommandName();
                if (commandName == "exit")
                {
                    m_model.exit();
                }
                m_commands[commandName].DoCommand(userCommand);
                m_model.modelEvent();
            };

            m_model.ModelChanged += delegate()  // Model Changed
            {
                string[] instructions = m_model.getInstructions();
                string[] userCommand  = m_view.getUserCommand();
                string   commandName  = m_view.getUserCommandName();

                if (commandName == "exit")
                {
                    m_view.exit();
                }
                if (commandName == "generate3dmaze")
                {
                    WinMaze winMaze = m_model.getWinMaze(userCommand[0]);
                    m_view.printMaze(winMaze, winMaze.PosZ);
                }
                if (commandName == "displaysolution")
                {
                    WinMaze winMaze = m_model.getWinMaze("maze");
                    m_view.printMaze(winMaze, winMaze.PosZ);
                }
                if (instructions.Length > 0)
                {
                    if (instructions[0] == "display")
                    {
                        WinMaze winMaze = m_model.getWinMaze(instructions[1]);
                        if (null == winMaze)
                        {
                            m_view.errorOutput("winMaze in model presenter is = null");
                        }
                        else
                        {
                            m_view.printMaze(winMaze, winMaze.PosZ);
                        }
                    }
                }
            };

            m_view.Start();
        }
        /// <summary>
        /// Creates the maze & displays it on the screen
        /// </summary>
        /// <param name="maze">Current WinMaze</param>
        /// <param name="floor">Current floor</param>
        /// <param name="mazeCellSize">Size of the cells</param>
        private void CreateMaze(WinMaze maze, int floor, int mazeCellSize)
        {
            MazeCell mazeCell;
            Cell     cell3d;
            Dictionary <int, int[, ]> solutionDictByLevel = new Dictionary <int, int[, ]>();

            if (maze.isSolutionExists())
            {
                solutionDictByLevel = maze.solutionCoordinatesByLevel();
            }
            for (int row = 0; row < maze.getMaze().MyRows; row++)
            {
                for (int column = 0; column < maze.getMaze().MyColumns; column++)
                {
                    cell3d = maze.getMaze().getMazeByFloor(floor).getCell(column, row);
                    int[] cellWalls = cell3d.getWallsAroundCell();
                    int   isSpecial = 0;
                    if (1 == cell3d.BlockOrEmpty)
                    {
                        isSpecial = 1;
                    }
                    if (maze.isSolutionExists()) // mark the solution
                    {
                        if (solutionDictByLevel[floor][column, row] == 1)
                        {
                            isSpecial = 5;
                        }
                    }
                    if (column == maze.getMaze().MyColumns - 1)
                    {
                        cellWalls[1] = 1;
                    }
                    if (row == maze.getMaze().MyRows - 1)
                    {
                        cellWalls[3] = 1;
                    }
                    if ((column == maze.getMaze().MyColumns - 1) && (row == maze.getMaze().MyRows - 1) && (floor == 0))
                    {
                        cellWalls[1] = 0;
                        isSpecial    = 4;
                    }
                    if ((column == 0) && (row == 0) && (floor == maze.getMaze().MyHeight - 1))
                    {
                        cellWalls[0] = 0;
                        isSpecial    = 3;
                    }
                    int currX = maze.PosX;
                    int currY = maze.PosY;
                    if ((column == currX) && (row == currY))
                    {
                        isSpecial = 2;
                    }
                    if (column + 1 < maze.getMaze().MyColumns)
                    {
                        Cell  cell3dright    = maze.getMaze().getMazeByFloor(floor).getCell(column + 1, row);
                        int[] cellWallsright = cell3dright.getWallsAroundCell();
                        if ((cellWallsright[0] == 0) || (cellWalls[1] == 0))
                        {
                            cellWalls[1] = 0;
                        }
                    }
                    if (row + 1 < maze.getMaze().MyRows)
                    {
                        Cell  cell3dforward    = maze.getMaze().getMazeByFloor(floor).getCell(column, row + 1);
                        int[] cellWallsforward = cell3dforward.getWallsAroundCell();
                        if ((cellWallsforward[2] == 0) || (cellWalls[3] == 0))
                        {
                            cellWalls[3] = 0;
                        }
                    }
                    if (isSpecial == 1)
                    {
                        cellWalls[0] = 1; cellWalls[1] = 1; cellWalls[2] = 1; cellWalls[3] = 1; cellWalls[4] = 1; cellWalls[5] = 1;
                    }
                    if (column == 0)
                    {
                        cellWalls[0] = 1;
                    }
                    if (row == 0)
                    {
                        cellWalls[2] = 1;
                    }
                    mazeCell = new MazeCell(mazeCellSize, isSpecial, cellWalls[0] == 1, cellWalls[1] == 1, cellWalls[2] == 1, cellWalls[3] == 1, column == 0, row == 0);

                    mazeBoard.Children.Add(mazeCell);
                    Canvas.SetLeft(mazeCell, mazeCellSize * column);
                    Canvas.SetTop(mazeCell, mazeCellSize * row);
                }
            }
        }