Exemple #1
0
        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            int cellLength = gridLength / gameBoard.NumCells;

            // Make sure click was inside the grid
            if (e.X < GridOffset || e.X > cellLength * gameBoard.NumCells + GridOffset ||
                e.Y < GridOffset || e.Y > cellLength * gameBoard.NumCells + GridOffset)
            {
                return;
            }

            // Find row, col of mouse press
            int r = (e.Y - GridOffset) / cellLength;
            int c = (e.X - GridOffset) / cellLength;

            // Invert selected box and all surrounding boxes
            gameBoard.MakeMove(r, c);

            // Redraw grid
            this.Invalidate();

            // Check to see if puzzle has been solved
            if (gameBoard.PlayerWon())
            {
                // Display winner dialog box just inside window
                MessageBox.Show(this, "Congratulations!  You've won!", "Lights Out!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #2
0
        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.X < GRIDOFFSET || e.X > cellLength * gameBoard.NumCells + GRIDOFFSET ||
                e.Y < GRIDOFFSET || e.Y > cellLength * gameBoard.NumCells + GRIDOFFSET)
            {
                return;
            }

            int row    = (e.Y - GRIDOFFSET) / cellLength;
            int column = (e.X - GRIDOFFSET) / cellLength;

            gameBoard.MakeMove(row, column);

            Invalidate();

            if (gameBoard.CheckForWin())
            {
                MessageBox.Show(this, "Congratulations!, You've won!", "Lights Out!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }