예제 #1
0
        private void DoMin_MouseDown(object sender, MouseEventArgs e) // bắt sự kiên click chuột
        {
            buttons but = (buttons)(System.Windows.Forms.Button)sender;

            if (e.Button == MouseButtons.Right && win != 0)
            {
                if (but.flag == false && flagging > 0)
                {
                    flagging--;
                    btFlagging.Text           = flagging.ToString();
                    but.flag                  = true;
                    but.BackgroundImage       = Image.FromFile(Application.StartupPath + @"\images\flag.png");
                    but.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                }
                else if (but.flag == true && flagging >= 0)
                {
                    flagging++;
                    btFlagging.Text     = flagging.ToString();
                    but.flag            = false;
                    but.BackgroundImage = null;
                }
            }
            else if (e.Button == MouseButtons.Left)
            {
                if (but.flag == false)
                {
                    timerCountTime.Start(); // Khởi tạo chạy thời gian khi click;
                    prgCountTime.Value = 0;
                    if (but.mine == true)
                    {
                        but.BackgroundImage       = Image.FromFile(Application.StartupPath + @"\images\main.png");
                        but.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                        EndGame();
                    }
                    else
                    {
                        mark(but.vitri / level, but.vitri % level, level);
                    }
                }
            }

            FocusButton();
            ConditionOfWin();
        }
예제 #2
0
 void DrawBoardGame(int weight, int height) // Vẽ bảng
 {
     pnlBoardGame.Controls.Clear();
     timerCountTime.Stop();
     prgCountTime.Value   = 0;
     pnlBoardGame.Enabled = true;
     for (int i = 0; i < weight; i++)
     {
         board[i] = new buttons[weight];
         for (int j = 0; j < height; j++)
         {
             board[i][j]            = new buttons();
             board[i][j].Name       = ("button" + i * level + j + 1);
             board[i][j].Size       = new System.Drawing.Size(30, 30);
             board[i][j].MouseDown += DoMin_MouseDown;
             board[i][j].BackColor  = System.Drawing.Color.White;
             board[i][j].vitri      = i * level + j;
             board[i][j].Location   = new System.Drawing.Point(5 + 30 * j, 6 + 30 * i);
             pnlBoardGame.Controls.Add(board[i][j]);
         }
     }
 }