示例#1
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                oyun?.Ucaksavar.HareketEt(Yonler.Saga);
            }
            else if (e.KeyCode == Keys.Left)
            {
                oyun?.Ucaksavar.HareketEt(Yonler.Sola);
            }
            else if (e.KeyCode == Keys.Space)
            {
                oyun?.Ucaksavar.AtesEt();
            }
            else if (e.KeyCode == Keys.Enter)
            {
                if (oyun == null)
                {
                    this.Controls.Clear();
                    this.Controls.Add(menuStrip1);
                    oyun = new UcakOyunu(this);
                    timer1.Start();
                }
            }

            if (e.KeyCode == Keys.P)
            {
                if (oyun.durduMu == true)
                {
                    timer1.Start();
                    oyun.durduMu = false;
                }
                else
                {
                    lbl.Text  = "Oyun Duraklatıldı. Devam Etmek İçin P'ye basınız..";
                    this.Text = lbl.Text;
                    timer1.Stop();
                    if (oyun != null)
                    {
                        oyun.durduMu = true;
                    }
                    else
                    {
                        return;
                    }
                }
            }
            if (e.KeyCode == Keys.W)
            {
                if (oyun != null)
                {
                    timer1.Start();
                    oyun.durduMu = false;
                }
                else
                {
                    return;
                }
            }
        }
示例#2
0
        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);
                    }
                }
            }
        }
示例#3
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     this.Text = $"Skor: {oyun.Skor} Toplam Roket: {oyun.Ucaksavar.Roketler.Count} Toplam Uçak: {oyun.Ucaklar.Count}";
     if (oyun.OyunDurduMu)
     {
         timer1.Stop();
         DialogResult cevap = MessageBox.Show($"Oyun bitti. Skor: {oyun.Skor}\nYeniden başlamak istiyor musun?", "Kaybettin", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (cevap == DialogResult.Yes)
         {
             this.Controls.Clear();
             oyun = new UcakOyunu(this);
             timer1.Start();
         }
         else
         {
             Application.Exit();
         }
     }
 }
示例#4
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         if (oyun == null)
         {
             oyun = new UcakOyunu(this);
         }
     }
     else if (e.KeyCode == Keys.Space)
     {
         oyun?.Ucaksavar.AtesEt();
     }
     else if (e.KeyCode == Keys.Left)
     {
         oyun?.Ucaksavar.HareketEt(Yonler.Sola);
     }
     else if (e.KeyCode == Keys.Right)
     {
         oyun?.Ucaksavar.HareketEt(Yonler.Saga);
     }
     else if (e.KeyCode == Keys.Escape)
     {
         oyun?.OyunuDuraklat();
         DialogResult cevap = MessageBox.Show("Oyun kaydedilsin mi?", "Duraklatıldı", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
         if (cevap == DialogResult.Yes)
         {
             oyun?.OyunuKaydet();
             Application.Exit();
         }
         else if (cevap == DialogResult.No)
         {
             Application.Exit();
         }
         else
         {
             oyun?.OyunuDevamEttir();
         }
     }
 }
示例#5
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Right)
     {
         oyun?.Ucaksavar.HareketEt(Yonler.Saga);
     }
     else if (e.KeyCode == Keys.Left)
     {
         oyun?.Ucaksavar.HareketEt(Yonler.Sola);
     }
     else if (e.KeyCode == Keys.Space)
     {
         oyun?.Ucaksavar.AtesEt();
     }
     else if (e.KeyCode == Keys.Enter)
     {
         if (oyun == null)
         {
             this.Controls.Clear();
             oyun = new UcakOyunu(this);
             timer1.Start();
         }
     }
     //oyun kaydetme
     else if (e.KeyCode == Keys.Escape)
     {
         DialogResult cevap = MessageBox.Show($"Kaydetmek istiyor musun?", "Kaydet", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (cevap == DialogResult.Yes)
         {
             Application.Exit();
         }
         else
         {
             Application.Exit();
         }
     }
 }
示例#6
0
        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");
            }
        }