private void btnBaslat_Click(object sender, EventArgs e) { if (cmbKayitliOyunlar.SelectedIndex > -1) { string jsonkayit = ""; string filename = cmbKayitliOyunlar.SelectedItem.ToString(); string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + $"\\UcaksavarKayit\\"; Directory.CreateDirectory(path); FileStream file = new FileStream(path + filename, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(file); jsonkayit = reader.ReadToEnd(); reader.Close(); file.Close(); oyun = new UcakOyunu(this); if (!string.IsNullOrWhiteSpace(jsonkayit)) { OyunKayit kayit = JsonConvert.DeserializeObject <OyunKayit>(jsonkayit); oyun.Skor = kayit.Skor; oyun.PictureArkaplan1.Location = new Point(kayit.Arkaplan[0].X, kayit.Arkaplan[0].Y); oyun.PictureArkaplan2.Location = new Point(kayit.Arkaplan[1].X, kayit.Arkaplan[1].Y); foreach (UcaklarKayit item in kayit.Ucak) { Ucak u = new Ucak(new Point(item.X, item.Y)); oyun.Ucaklar.Add(u); this.Controls.Add(u.ResimKutusu); } foreach (YananUcaklarKayit item in kayit.YananUcak) { Ucak u = new Ucak(new Point(item.X, item.Y)); u.YanmaSuresi = item.YanmaSuresi; u.ResimKutusu.Image = Properties.Resources.yanma; oyun.YananUcaklar.Add(u); this.Controls.Add(u.ResimKutusu); } oyun.Ucaksavar.ResimKutusu.Location = new Point(kayit.Ucaksavar.X, kayit.Ucaksavar.Y); foreach (MermilerKayit item in kayit.Mermi) { Roket r = new Roket(new Point(item.X, item.Y)); oyun.Ucaksavar.Roketler.Add(r); this.Controls.Add(r.ResimKutusu); } } } }
private void yükleToolStripMenuItem_Click(object sender, EventArgs e) { oyun.durduMu = true; lbl.Text = "Oyun Duraklatıldı. Devam Etmek İçin P'ye basınız.."; this.Text = lbl.Text; timer1.Stop(); dosyaAc.Title = "Bir Kisi XML dosyasını seçiniz"; dosyaAc.Filter = "XML Format | *.xml"; dosyaAc.Multiselect = false; dosyaAc.FileName = string.Empty; dosyaAc.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (dosyaAc.ShowDialog() == DialogResult.OK) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <Konumlar>)); TextReader reader = new StreamReader(dosyaAc.FileName); oyun = new UcakOyunu(this); oyun.durduMu = false; oyun.roketKonumları.AddRange((List <Konumlar>)xmlSerializer.Deserialize(reader)); this.Controls.Clear(); this.Controls.Add(menuStrip1); foreach (var item in oyun.roketKonumları) { Point pnt = new Point() { X = Convert.ToInt32(item.x), Y = Convert.ToInt32(item.y) }; Roket rkt = new Roket(pnt); rkt.ResimKutusu.Image = Properties.Resources.mermi1; this.Controls.Add(rkt.ResimKutusu); oyun.Ucaksavar.Roketler.Add(rkt); oyun.Skor = Convert.ToInt32(item.skor); } foreach (var item in oyun.roketKonumları) { Point pnt = new Point() { X = Convert.ToInt32(item.z), Y = Convert.ToInt32(item.c) }; Ucak uck = new Ucak(pnt); uck.ResimKutusu.Image = Properties.Resources.ucak; this.Controls.Add(uck.ResimKutusu); oyun.Ucaklar.Add(uck); } this.Controls.Add(oyun.Ucaksavar.ResimKutusu); reader.Close(); reader.Dispose(); //timer1.Start(); lbl.Text = "Oyun Duraklatıldı. Devam Etmek İçin P'ye basınız.."; this.Text = lbl.Text; oyun.durduMu = true; MessageBox.Show($"Oyun {dosyaAc.FileName} adresinden başarıyla yüklendi"); } }