private void buttonStart_Click(object sender, EventArgs e) { time = new Label(); time.Location = new Point(20, 20); Controls.Add(time); time.Font = new Font(time.Font.FontFamily, 16); label.Visible = false; buttonStart.Visible = false; numericUpDown.Visible = false; dimensiune = (int)numericUpDown.Value; this.Text = "MineSweeper " + dimensiune.ToString() + "x" + dimensiune.ToString(); btn = new Buton[dimensiune, dimensiune]; this.Size = new Size(65 + 40 * dimensiune, 75 + 40 * (dimensiune + 1)); width = 65 + 40 * dimensiune; for (int i = 0; i < dimensiune; i++) { for (int j = 0; j < dimensiune; j++) { btn[i, j] = new Buton(); btn[i, j].Font = new Font(btn[i, j].Font.FontFamily, 20); btn[i, j].Size = new Size(40, 40); btn[i, j].Location = new Point(25 + i * 40, 50 + j * 40); this.Controls.Add(btn[i, j]); btn[i, j].x = i; btn[i, j].y = j; btn[i, j].MouseDown += new MouseEventHandler(ApasClick); } } nrBome = (dimensiune * dimensiune) / 2; nrNuBombe = (dimensiune * dimensiune) - nrBome; nrNuBombeAfisate = 0; Random rnd = new Random(); int x, y; for (int i = 0; i < nrBome; i++) { do { x = rnd.Next(dimensiune); y = rnd.Next(dimensiune); } while (btn[x, y].Bomba); btn[x, y].Bomba = true; } for (int i = 0; i < dimensiune; i++) { for (int j = 0; j < dimensiune; j++) { NumaraBombe(i, j); } } minute = 0; secunde = 0; SetTime(); timer.Start(); }
private void ApasClick(object sender, MouseEventArgs e) { Buton x = (Buton)sender; if (e.Button == MouseButtons.Left) { if (!x.Blocat) { if (!x.Bomba) { Show(x.x, x.y); if (nrNuBombeAfisate == nrNuBombe) { WinForm winForm = new WinForm(); win++; winForm.Text = "WIN " + win.ToString() + " - " + lose.ToString(); //WIN 1 - 0 timer.Stop(); EndShow(); DialogResult dialogResult = winForm.ShowDialog(); if (dialogResult == DialogResult.OK) { startAgainToolStripMenuItem_Click(this, e); } if (dialogResult == DialogResult.No) { Application.Exit(); } } } else { MessageBoxForm messageBoxForm = new MessageBoxForm(); lose++; messageBoxForm.Text = "GAME OVER " + win.ToString() + " - " + lose.ToString(); //GAME OVER 0 - 1 timer.Stop(); EndShow(); DialogResult dialogResult = messageBoxForm.ShowDialog(); if (dialogResult == DialogResult.OK) { startAgainToolStripMenuItem_Click(this, e); } if (dialogResult == DialogResult.No) { Application.Exit(); } } } } if (e.Button == MouseButtons.Right) { x.BlocareDeblocare(); } }