Exemplo n.º 1
0
        private void MainForm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            int CellLength = GridLength / game.GridSize;

            // Make sure click was inside the grid
            if (e.X < GridOffset || e.X > CellLength * game.GridSize + GridOffset ||
                e.Y < GridOffset || e.Y > CellLength * game.GridSize + GridOffset)
            {
                return;
            }
            // Find row, col of mouse press
            int r = (e.Y - GridOffset) / CellLength;
            int c = (e.X - GridOffset) / CellLength;

            game.Move(r, c);


            // Redraw grid
            this.Invalidate();
            // Check to see if puzzle has been solved
            if (game.isWinner())
            {
                //Display winner dialog box
                MessageBox.Show(this, "Congratulations! You've won!", "Lights Out!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }