Exemplo n.º 1
0
        //DRAW THE PLAYER
        public MazePlayer DrawPlayer()
        {
            MazePlayer newPlayer = new MazePlayer();

            newPlayer.Display.BackColor = this.ColorPlayer;
            return(newPlayer);
        }
Exemplo n.º 2
0
        //METHODS
        //GENERATION OF THE MAZE
        public Panel GenMaze()
        {
            Panel panel = new Panel();

            try
            {
                ArrayOfCells    = new MazeCell[MazeHeight, MazeWidth];
                ArrayOfCellsOld = new MazeCell[MazeHeight, MazeWidth];
                ArrayOfPosition = new byte[_mazeHeight, MazeWidth];

                panel.Width    = this.MazeWidth * this.CELLSIZE;
                panel.Height   = this.MazeHeight * this.CELLSIZE;
                panel.Location = new Point(140, 30);

                //CREATION OF THE ARRAY FOR PATHS AND WALLS
                MazeCreator creator = new MazeCreator(this.MazeHeight, this.MazeWidth, new Point(1, 1));
                ArrayOfPosition = creator.CreateMaze();

                //CREATE, DRAW AND PLACE THE PLAYER
                _player = this.DrawPlayer();
                _player.Display.Location = new Point(0, _mazeHeight * CELLSIZE - CELLSIZE);
                panel.Controls.Add(_player.Display);
                //_player.Position = new int[_mazeHeight, MazeWidth];
                //_player.Position[0, MazeWidth-1] = 1;

                for (int rangee = 0; rangee < ArrayOfPosition.GetLength(0); rangee++)
                {
                    for (int colonne = 0; colonne < ArrayOfPosition.GetLength(1); colonne++)
                    {
                        _newCell = new MazeCell();
                        //THESE FOUR EXCEPTIONS ARE THE BEGINNIG AND THE END OF THE MAZE
                        ArrayOfPosition[0, ArrayOfPosition.GetLength(0) - 1] = 2;
                        ArrayOfPosition[0, ArrayOfPosition.GetLength(0) - 2] = 0;
                        ArrayOfPosition[ArrayOfPosition.GetLength(1) - 1, 0] = 2;
                        ArrayOfPosition[ArrayOfPosition.GetLength(1) - 1, 1] = 0;


                        switch (ArrayOfPosition[rangee, colonne])
                        {
                        //IF THE ARRAY IS 0, THE CELL ISN'T A WALL
                        case 0:
                            _newCell.Display.BackColor = ColorCell;
                            break;

                        //ELSE THE CELL IS A WALL
                        case 1:
                            _newCell.IsAWall           = true;
                            _newCell.Display.BackColor = this.ColorCellWall;
                            break;

                        //OR THE BEGINNING OR THE END OF THE MAZE
                        case 2:
                            _newCell.Display.BackColor = Color.Purple;
                            break;
                        }
                        //PLACE THE CELL IN THE PANEL
                        _newCell.Display.Location = new Point(rangee * CELLSIZE, colonne * CELLSIZE);
                        //IF THE BORDER WAS CHECKED
                        if (Border)
                        {
                            _newCell.Display.BorderStyle = BorderStyle.FixedSingle;
                        }
                        else
                        {
                            _newCell.Display.BorderStyle = BorderStyle.None;
                        }
                        //ADD THE GENERATED PICTUREBOX TO THE PANEL
                        panel.Controls.Add(_newCell.Display);

                        //ADD THE NEW CREATED CELL IN THE GENERAL ARRAY AND THE RECOVER ARRAY
                        ArrayOfCells[rangee, colonne]    = _newCell;
                        ArrayOfCellsOld[rangee, colonne] = _newCell;
                    }
                }
            }
            catch (Exception e)
            {
                CallMessage(Messages.Generation);
            }
            return(panel);
        }