Exemple #1
0
        private void InitMineField()
        {
            int cols  = 10;
            int rows  = 10;
            int mines = 10;

            game = MineSweeperGame.Instance;
            game.Initialize(cols, rows, mines);
            Console.WriteLine(game);

            mineFieldGrid.Controls.Clear();
            mineFieldGrid.ColumnCount = game.Cols;
            mineFieldGrid.Location    = new System.Drawing.Point(0, 55);
            mineFieldGrid.AutoSize    = true;
            this.AutoSize             = true;
            this.Controls.Add(mineFieldGrid);

            buttonSquares = new List <ButtonSquare>();
            int i = 0;

            foreach (Square square in game.Squares.Values)
            {
                ButtonSquare button = new ButtonSquare(i, square.ToString());
                button.Size = new System.Drawing.Size(30, 30);
                button.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                button.MouseDown += new MouseEventHandler(OnClick);

                mineFieldGrid.Controls.Add(button);
                buttonSquares.Add(button);
                i++;
            }

            newGame.Image = pic_Start;
        }
Exemple #2
0
        private void OnClick(object sender, MouseEventArgs e)
        {
            ButtonSquare square = ((ButtonSquare)sender);

            switch (e.Button)
            {
            case MouseButtons.Left:
                game.Uncover(square.Position);
                paintButtons();
                break;

            case MouseButtons.Right:
                game.ToggleFlag(square.Position);
                paintButtons();
                break;

            default:
                break;
            }
        }