void EmptyFieldClick(ButtonExtended button) { for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { if (allButtons[x, y] == button) { button.Text = "" + CountBombsAround(x, y); } } } }
void FieldClick(object sender, EventArgs e) { ButtonExtended button = (ButtonExtended)sender; if (button.isBomb) { Explode(button); } else { EmptyFieldClick(button); } }
void Explode(ButtonExtended button) { for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { if (allButtons[x, y].isBomb) { allButtons[x, y].Text = "*"; } } } MessageBox.Show("You Died"); }
private void Form1_Load(object sender, EventArgs e) { allButtons = new ButtonExtended[width, height]; Random rng = new Random(); for (int x = 10; (x - 10) < width * distanceBetweenButtons; x += distanceBetweenButtons) { for (int y = 10; (y - 10) < height * distanceBetweenButtons; y += distanceBetweenButtons) { ButtonExtended button = new ButtonExtended(); button.Location = new Point(x, y); button.Size = new Size(30, 30); if (rng.Next(0, 101) < 20) { button.isBomb = true; } allButtons[(x - 10) / distanceBetweenButtons, (y - 10) / distanceBetweenButtons] = button; Controls.Add(button); button.Click += new EventHandler(FieldClick); } } }