private void BtnClick(object sender, EventArgs e) { MouseEventArgs M = (MouseEventArgs)e; Btn s = (sender as Btn); if (M.Button == MouseButtons.Right) { s.Lock(); if (s.islocked()) { bc--; s.BackgroundImage = imageList1.Images[1]; s.BackgroundImageLayout = ImageLayout.Center; } else { s.BackgroundImage = null; bc++; } return; } bool gameOver = !open(s.x, s.y); if (s.val == 0) { SoundPlayer player = new SoundPlayer("magic.wav"); player.Play(); } if (gameOver) { DialogResult d = MessageBox.Show("Game Over!!\nTry again??", "Over", MessageBoxButtons.YesNo); if (d == DialogResult.Yes) { button1_Click(button1, null); } else { System.Windows.Forms.Application.Exit(); } } else if (rest == boom) { SoundPlayer player = new SoundPlayer("winner.wav"); player.Play(); DialogResult d = MessageBox.Show("Winner Winner!!\nPlay again??", "Winer", MessageBoxButtons.YesNo); if (d == DialogResult.Yes) { button1_Click(button1, null); } else { System.Windows.Forms.Application.Exit(); } } label1.Text = bc.ToString(); }
private void Generate2(int n) { int h = Math.Min(panel1.Width, panel1.Height); int a = (h * h) / (n * n); a = (int)(Math.Sqrt(a)); panel1.Width = panel1.Height = a * n; int px = 0, py = 0; for (int i = 0; i < n; i++, py += a, px = 0) { for (int j = 0; j < n; j++, px += a) { grid[i, j] = new Btn(i, j, val[i, j]); grid[i, j].SetBounds(px, py, a, a); panel1.Controls.Add(grid[i, j]); grid[i, j].MouseDown += BtnClick; } } }