Esempio n. 1
0
        private void MainForm_MouseDown(object sender, 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.IsGameOver())
            {
                // Display winner dialog box just inside window
                MessageBox.Show(this, "Congratulations!  You've won!", "Lights Out!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 2
0
        private void MainForm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            //// Make sure click was inside the grid
            //if (e.X < GridOffset || e.X > CellLength * NumCells + GridOffset ||
            //e.Y < GridOffset || e.Y > CellLength * 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
            for (int i = r - 1; i <= r + 1; i++)
            {
                for (int j = c - 1; j <= c + 1; j++)
                {
                    if (i >= 0 && i < NumCells && j >= 0 && j < NumCells)
                    {
                        grid[i, j] = !grid[i, j];
                    }
                }
            }
            lightsOutGame.Move(r, c);
            // Redraw grid
            this.Invalidate();
            // Check to see if puzzle has been solved
            if (PlayerWon())
            {
                // Display winner dialog box
                MessageBox.Show(this, "Congratulations! You've won!", "Lights Out!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 3
0
        //private bool PlayerWon()
        //{
        //    //bool won = true;
        //    //for (int r = 0; r < NumCells; r++)
        //    //{
        //    //    for (int c = 0; c < NumCells; c++)
        //    //    {
        //    //        if (grid[r, c] == true)
        //    //            won = false;
        //    //    }
        //    //}
        //    //return won;
        //}

        //private void Button1_Click(object sender, EventArgs e)
        //{
        //    for (int r = 0; r < NumCells; r++)
        //        for (int c = 0; c < NumCells; c++)
        //            grid[r, c] = rand.Next(2) == 1;

        //    this.Invalidate();
        //}

        private void MainForm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.X < GridOffset || e.X > CellLength * game.GridSize + GridOffset ||
                e.Y < GridOffset || e.Y > CellLength * game.GridSize + GridOffset)
            {
                return;
            }

            int r = (e.Y - GridOffset) / CellLength;
            int c = (e.X - GridOffset) / CellLength;

            //for (int i = r - 1; i <= r + 1; i++)
            //    for (int j = c - 1; j <= c + 1; j++)
            //        if (i >= 0 && i < game.GridSize && j >= 0 && j < game.GridSize)
            //            grid[i, j] = !grid[i, j];

            game.Move(r, c);

            this.Invalidate();

            if (game.IsGameOver())
            {
                MessageBox.Show(this, "Congratulations! You've won!", "Lights Out!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 4
0
        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.X < GridOffset || e.X > CellLength * game.GridSize + GridOffset || e.Y < GridOffset || e.Y > CellLength * game.GridSize + GridOffset)
            {
                return;
            }

            int r = (e.Y - GridOffset) / CellLength;
            int c = (e.X - GridOffset) / CellLength;

            game.Move(r, c);
            this.Invalidate();

            if (game.IsGameOver())
            {
                MessageBox.Show(this, "Congratulations! You've Won!", "Lights Out!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 5
0
        private void Rect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Get row and column from Rectangle's Tag
            Rectangle rect   = sender as Rectangle;
            var       rowCol = (Point)rect.Tag;
            int       row    = (int)rowCol.X;
            int       col    = (int)rowCol.Y;

            game.Move(row, col);

            // TODO: Redraw the grid and see if the game is over
            DrawGrid();
            if (game.IsGameOver())
            {
                MessageBox.Show("You've won!");
            }

            // Event was handled
            e.Handled = true;
        }
Esempio n. 6
0
        private void MainForm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // 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);
            this.Invalidate();
            // Check to see if puzzle has been solved
            if (PlayerWon())
            {
                // Display winner dialog box
                MessageBox.Show(this, "Congratulations! You've won!", "Lights Out!",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }