private void btnSpeichern_Click(object sender, EventArgs e) { int PlayerC = 0, Player2C = 0, HausC = 0, Haus2C = 0, Fehler = 0; for (int f = 0; f < panel1.Controls.Count; f++) { switch ((panel1.Controls[f].Tag + "").Split('.')[0]) { case "Player": PlayerC++; break; case "Player2": Player2C++; break; case "Haus": HausC++; break; case "Haus2": Haus2C++; break; } if ((panel1.Controls[f].Tag + "").Split('.')[0] != "Mauer" || (panel1.Controls[f].Tag + "").Split('.')[0] != "Eis" || (panel1.Controls[f].Tag + "").Split('.')[0] != "Teleporter") { for (int g = 0; g < panel1.Controls.Count; g++) { if (panel1.Controls[f].Location == panel1.Controls[g].Location && panel1.Controls[f] != panel1.Controls[g]) { Fehler++; panel1.Controls[f].BackColor = panel1.Controls[g].BackColor = Color.Orange; } } } } if (PlayerC != 1 || Player2C > 1 || Player2C < 0) { MessageBox.Show("Nur ein/zwei Spieler!"); Fehler++; } if (HausC != 1 || Haus2C > 1 || Haus2C < 0) { MessageBox.Show("Nur ein/zwei Haus/Häuser!"); Fehler++; } if (Player2C == 1 && Haus2C != 1) { MessageBox.Show("Zweites Haus fehlt"); Fehler++; } if (Fehler > 0) { return; } if (!beatbeiten) { speicher.Add(panel1.Controls, panel1.Size, Hohe, Breite, txBName.Text, checkBox2.Checked, Level); } else { speicher.Add(panel1.Controls, panel1.Size, Hohe, Breite, txBName.Text, checkBox2.Checked); } speicher.speichern(Directory.GetCurrentDirectory() + @"\Datenbank.txt"); MessageBox.Show("Erfolgreich gespeichert"); button1.Visible = button2.Visible = true; }
private void button1_Click(object sender, EventArgs e) { openFileDialog1.Filter = "Text Datei|*.txt"; openFileDialog1.Title = "Text Datei öffnen"; DialogResult temp = openFileDialog1.ShowDialog(); if (temp == DialogResult.OK || temp == DialogResult.Yes) { try { speicher.Add(File.ReadAllLines(openFileDialog1.FileName)); } catch (Exception) { MessageBox.Show("Text Datei ist keine LevelDatei"); return; } } Temp_FormClosed(null, null); comBox.SelectedIndex = comBox.Items.Count - 2; speicher.speichern(Directory.GetCurrentDirectory() + @"\Datenbank.txt"); }