public void ClickButton(Button btn) { // check if button previously removed if (-1 < Controls.IndexOf(btn)) { CMineInfo mine = (CMineInfo)btn.Tag; // count bounding mines mine.Count = mine.GetCount(); // create label to replace button Label l = new Label(); l.Text = mine.Count.ToString(); l.Location = btn.Location; l.Size = btn.Size; l.AutoSize = false; l.TextAlign = ContentAlignment.MiddleCenter; int x = Controls.IndexOf(btn); Controls.RemoveAt(x); Controls.Add(l); Controls.SetChildIndex(l, x); // recursively call for removing buttons // note, this not most efficient method ... per Neil if (0 == mine.Count) { if (mine.N != null) { ClickButton(btns[mine.N.Row][mine.N.Column]); } if (mine.S != null) { ClickButton(btns[mine.S.Row][mine.S.Column]); } if (mine.E != null) { ClickButton(btns[mine.E.Row][mine.E.Column]); } if (mine.W != null) { ClickButton(btns[mine.W.Row][mine.W.Column]); } } } }
void picEmojy_Click(object sender, MouseEventArgs e)//Spiel neu Starten { //Prüfen, welcher Modus ausgewählt ist if (radioButton1.Checked == true) //Beginner Modus { saveRadioBtn = 1; width = 8; height = 8; bombenzahl = 10; } else if (radioButton2.Checked == true) // Intermediate Modus { saveRadioBtn = 2; width = 16; height = 16; bombenzahl = 40; } else if (radioButton3.Checked == true) // Expert Modus { saveRadioBtn = 3; width = 30; height = 16; bombenzahl = 99; } else if (radioButton4.Checked == true) // Costum Modus { saveRadioBtn = 4; width = Convert.ToInt32(WidthTextBox.Text); height = Convert.ToInt32(HeightTextBox.Text); bombenzahl = Convert.ToInt32(MinesTextBox.Text); } for (int ix = Controls.Count - 1; ix >= 0; --ix)//Controls-Einträge im Arbeitsspeicher löschen { var tmpObj = Controls[ix]; Controls.RemoveAt(ix); tmpObj.Dispose(); } timer4.Stop(); gameover = false; gamewin = false; timer = 0; aufgedecktefelder = 0; this.Controls.Clear(); //Alle Form-Objekte im Fenster löschen StartGame(width, height, bombenzahl); //erneutes Aufrufen der StartGame-Methode switch (saveRadioBtn) //Prüfen, welcher Radiobutton aktiv war { case 1: radioButton1.Checked = true; break; case 2: radioButton2.Checked = true; break; case 3: radioButton3.Checked = true; break; case 4: radioButton4.Checked = true; break; } WidthTextBox.Text = Convert.ToString(width); HeightTextBox.Text = Convert.ToString(height); MinesTextBox.Text = Convert.ToString(bombenzahl); }