예제 #1
0
        private void showMaze()
        {
            for (int i = 0; i < Maze.length; ++i)
            {
                for (int j = 0; j < Maze.length; ++j)
                {
                    MazeButton button = new MazeButton();
                    button.X         = i; button.Y = j;
                    button.FlatStyle = FlatStyle.Flat;
                    button.Height    = LENGTH / Maze.length;
                    button.Width     = LENGTH / Maze.length;
                    button.Margin    = new Padding(0, 0, 0, 0);
                    button.Location  = new Point(i * button.Height, j * button.Width);
                    button.Enabled   = false;

                    button = mazeColoring(mazeCells, i, j, button, _startColor, _endColor, _wallColor, _pathColor);

                    mazeButtons[i, j] = button;
                    mazePanel.Controls.Add(button);
                }
            }
            foreach (Button btn in mazeButtons)
            {
                btn.MouseEnter += btn_MouseEnter;
            }
        }
예제 #2
0
        private MazeButton mazeColoring(Cell[,] mazeCells, int i, int j, MazeButton button, Color startColor, Color endColor, Color wallColor, Color pathColor)
        {
            if (mazeCells[i, j].isWall())
            {
                if (mazeCells[i, j].isStart())
                {
                    setButtonColor(button, startColor, startColor, startColor);
                    button.Enabled = true;
                }
                else if (mazeCells[i, j].isEnd())
                {
                    setButtonColor(button, endColor, endColor, endColor);
                }

                else
                {
                    setButtonColor(button, wallColor, wallColor, wallColor);
                }
            }
            else
            {
                setButtonColor(button, pathColor, pathColor, pathColor);
            }

            return(button);
        }
예제 #3
0
        public void mazeInit(Mode mode)
        {
            maze             = new Maze(mode);
            mazeCells        = maze.mazeGeneration();
            mazeButtons      = new MazeButton[Maze.length, Maze.length];
            coordinates['x'] = 1; coordinates['y'] = 0;
            previousButton   = new MazeButton();
            previousButton.X = 1; previousButton.Y = 0;

            setMazeColorScheme(Color.Blue, Color.ForestGreen, Color.Black, Color.White, Color.BlueViolet, Color.Red);

            endGame = false;
            showMaze();
        }
예제 #4
0
 private void outcome(MazeButton button)
 {
     if (mazeCells[button.X, button.Y].isWall() && !mazeCells[button.X, button.Y].isStart() && !mazeCells[button.X, button.Y].isEnd())
     {
         controlButton.Font = new System.Drawing.Font("Microsoft PhagsPa", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
         controlButton.Text = "YOU LOST\nRestart?";
         enableAllButtons(false);
         endGame = true;
     }
     else if (mazeCells[button.X, button.Y].isEnd() && button.Y == previousButton.Y + 1)
     {
         controlButton.Font = new System.Drawing.Font("Microsoft PhagsPa", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
         controlButton.Text = "YOU WON\nRestart?";
         enableAllButtons(false);
         endGame = true;
     }
 }
예제 #5
0
        private void walkThroughMazeButtonsKeyboard(MazeButton button, Keys keyData)
        {
            if (maze.getMaze()[button.X, button.Y].isStart() && keyData == Keys.Up)
            {
                return;
            }
            else
            {
                switch (keyData)
                {
                case (Keys.Up):
                    button.Y -= 1;
                    break;

                case (Keys.Down):
                    button.Y += 1;
                    break;

                case (Keys.Left):
                    button.X -= 1;
                    break;

                case (Keys.Right):
                    button.X += 1;
                    break;
                }

                if (!maze.getMaze()[button.X, button.Y].isEnd() && !maze.getMaze()[button.X, button.Y].isStart())
                {
                    if (maze.getMaze()[button.X, button.Y].isWall())
                    {
                        setButtonColor(mazeButtons[button.X, button.Y], _visitedWallColor, _visitedWallColor, _visitedWallColor);
                    }
                    else
                    {
                        setButtonColor(mazeButtons[button.X, button.Y], _visitedPathColor, _visitedPathColor, _visitedPathColor);
                    }
                }

                outcome(mazeButtons[button.X, button.Y]);
                previousButton = mazeButtons[button.X, button.Y];
            }
        }
예제 #6
0
        private void btn_MouseEnter(object sender, EventArgs e)
        {
            var button = (MazeButton)sender;

            if (button.BackColor == _startColor)
            {
                enableAllButtons(true);
            }

            if (button.BackColor == _wallColor)
            {
                button.BackColor = _visitedWallColor;
            }
            else
            if (!(button.BackColor == _startColor) && !(button.BackColor == _endColor) && (Math.Abs(button.X - previousButton.X) == 1 || Math.Abs(button.Y - previousButton.Y) == 1))
            {
                setButtonColor(button, _visitedPathColor, _visitedPathColor, _visitedPathColor);
                previousButton = button;
            }

            outcome(button);
        }