Example #1
0
        /// <summary>
        /// check if finished the maze
        /// </summary>
        /// <param name="row">row in maze</param>
        /// <param name="column">column in maze</param>
        private void checkIfFinished(int row, int column)
        {
            Maze2d maze2d = (Maze2d)(m_maze.MAZE3dArray[cur_layer]);

            if (maze2d.getGoalPosition().X == row && maze2d.getGoalPosition().Y == column && cur_layer == goal_layer)
            {
                MessageBox.Show(" ### Congratulaions! You finished the Maze! ###");
            }
        }
Example #2
0
        /// <summary>
        /// color the maze
        /// </summary>
        /// <param name="mazewall2d">maze 2d</param>
        /// <param name="maze">maze 3d m</param>
        /// <param name="curr_layer">current layer</param>
        /// <param name="final_layer">final layer</param>
        /// <param name="s">name of maze</param>
        private void colorMazeWall(Grid mazewall2d, Maze maze, int curr_layer, int final_layer)
        {
            Maze2d maze2d = maze as Maze2d;

            for (int row = 0; row < maze2d.MX * 2 - 1; row++)
            {
                for (int column = 0; column < maze2d.MY * 2 - 1; column++)
                {
                    if (curr_layer == 0 && maze2d.getStartPosition().X == row && maze2d.getStartPosition().Y == column)
                    {
                        StartControl StartCell = new StartControl();
                        Grid.SetColumn(StartCell, column);
                        Grid.SetRow(StartCell, row);
                        mazewall2d.Children.Add(StartCell);
                    }

                    else
                    {
                        if (curr_layer == final_layer - 1 && maze2d.getGoalPosition().X == row && maze2d.getGoalPosition().Y == column)
                        {
                            EndControl EndCell = new EndControl();
                            Grid.SetColumn(EndCell, column);
                            Grid.SetRow(EndCell, row);
                            mazewall2d.Children.Add(EndCell);
                        }
                        else
                        {
                            if (maze2d.MAZE2d[row, column] == 1)
                            {
                                MazeCell1 CellWall = new MazeCell1();
                                Grid.SetColumn(CellWall, column);
                                Grid.SetRow(CellWall, row);
                                mazewall2d.Children.Add(CellWall);
                            }

                            else
                            {
                                GrassCell grassCell = new GrassCell();
                                Grid.SetColumn(grassCell, column);
                                Grid.SetRow(grassCell, row);
                                mazewall2d.Children.Add(grassCell);
                            }
                        }
                    }
                }
            }
            m_layerOfGrid[curr_layer] = mazewall2d;
        }
Example #3
0
        /// <summary>
        /// when the key is up
        /// </summary>
        /// <param name="sender">object sender</param>
        /// <param name="e">eventargs e</param>
        public void Grid_KeyUp(object sender, KeyEventArgs e)
        {
            e.Handled = true;
            ScaleY    = Canvas.GetTop(m_player);
            ScaleX    = Canvas.GetLeft(m_player);
            if (Double.IsNaN(ScaleY))
            {
                ScaleY = 0;
            }
            if (Double.IsNaN(ScaleX))
            {
                ScaleX = 0;
            }
            switch (e.Key)
            {
            case Key.Up:
            {
                if (CheckIfInLimits(m_row - 1, m_column) == true && CheckIfWall(m_row - 1, m_column) == false)
                {
                    ScaleY -= cellHeight;
                    m_row--;
                    checkIfFinished(m_row, m_column);
                }
                break;
            }

            case Key.Down:
            {
                if (CheckIfInLimits(m_row + 1, m_column) == true && CheckIfWall(m_row + 1, m_column) == false)
                {
                    ScaleY += cellHeight;
                    m_row++;
                    checkIfFinished(m_row, m_column);
                }
                break;
            }

            case Key.Left:
            {
                if (CheckIfInLimits(m_row, m_column - 1) == true && CheckIfWall(m_row, m_column - 1) == false)
                {
                    ScaleX -= cellWidth;
                    m_column--;
                    checkIfFinished(m_row, m_column);
                }
                break;
            }

            case Key.Right:
            {
                if (CheckIfInLimits(m_row, m_column + 1) == true && CheckIfWall(m_row, m_column + 1) == false)
                {
                    ScaleX += cellWidth;
                    m_column++;
                    checkIfFinished(m_row, m_column);
                }
                break;
            }

            case Key.PageUp:
            {
                Maze2d maze2d = ((Maze2d)m_maze.MAZE3dArray[cur_layer]);
                if (maze2d.getGoalPosition().X == m_row && maze2d.getGoalPosition().Y == m_column)
                {
                    if (cur_layer == goal_layer)
                    {
                        MessageBox.Show("You are in the final level!");
                    }
                    else
                    {
                        PanelUp.Children.Clear();
                        cur_layer++;
                        CreateTheMaze();
                        CreatePlayer();
                        checkIfFinished(m_row, m_column);
                    }
                }
                break;
            }

            case Key.PageDown:
            {
                Maze2d maze2d = ((Maze2d)m_maze.MAZE3dArray[cur_layer]);
                if (maze2d.getGoalPosition().X == m_row && maze2d.getGoalPosition().Y == m_column)
                {
                    if (cur_layer == 0)
                    {
                        MessageBox.Show("You are in the lowest level!");
                    }
                    else
                    {
                        PanelUp.Children.Clear();
                        cur_layer--;
                        CreateTheMaze();
                        CreatePlayer();
                        checkIfFinished(m_row, m_column);
                    }
                }
                break;
            }
            }
            Canvas.SetTop(m_player, ScaleY);
            Canvas.SetLeft(m_player, ScaleX);
        }
Example #4
0
        /// <summary>
        /// create the maze
        /// </summary>
        private void CreateTheMaze()
        {
            double PositionX = 0;
            double PositionY = 0;
            Maze2d maze2d    = m_maze.MAZE3dArray[cur_layer] as Maze2d;

            for (int row = 0; row < maze2d.MX * 2 - 1; row++)
            {
                PositionX = 0;
                for (int column = 0; column < maze2d.MY * 2 - 1; column++)
                {
                    if (cur_layer == 0 && maze2d.getStartPosition().X == row && maze2d.getStartPosition().Y == column)
                    {
                        StartControl s = new StartControl();
                        s.Width  = cellWidth;
                        s.Height = cellHeight;
                        Canvas.SetLeft(s, PositionX);
                        Canvas.SetTop(s, PositionY);
                        PanelDown.Children.Add(s);
                    }

                    else
                    {
                        if (cur_layer == goal_layer && maze2d.getGoalPosition().X == row && maze2d.getGoalPosition().Y == column)
                        {
                            EndControl EndCell = new EndControl();
                            EndCell.Width  = cellWidth;
                            EndCell.Height = cellHeight;
                            Canvas.SetLeft(EndCell, PositionX);
                            Canvas.SetTop(EndCell, PositionY);
                            PanelDown.Children.Add(EndCell);
                        }
                        else
                        {
                            if (maze2d.getGoalPosition().X == row && maze2d.getGoalPosition().Y == column)
                            {
                                ArrowControl arrow = new ArrowControl();
                                arrow.Width  = cellWidth;
                                arrow.Height = cellHeight;
                                Canvas.SetLeft(arrow, PositionX);
                                Canvas.SetTop(arrow, PositionY);
                                PanelDown.Children.Add(arrow);
                            }
                            else
                            {
                                if (maze2d.MAZE2d[row, column] == 1)
                                {
                                    MazeCell1 wall = new MazeCell1();
                                    wall.Width  = cellWidth;
                                    wall.Height = cellHeight;
                                    Canvas.SetLeft(wall, PositionX);
                                    Canvas.SetTop(wall, PositionY);
                                    PanelDown.Children.Add(wall);
                                }

                                else
                                {
                                    if (maze2d.MAZE2d[row, column] == 0)
                                    {
                                        GrassCell grass = new GrassCell();
                                        grass.Width  = cellWidth;
                                        grass.Height = cellHeight;
                                        Canvas.SetLeft(grass, PositionX);
                                        Canvas.SetTop(grass, PositionY);
                                        PanelDown.Children.Add(grass);
                                    }
                                }
                            }
                        }
                    }
                    PositionX += cellWidth;
                }
                PositionY += cellHeight;
            }
        }