1. Anasayfa
  2. Visual Studio C#

C# Örnekleri – Nehirden Geçme Oyunu

C# Örnekleri – Nehirden Geçme Oyunu
0

C# Örneklerimize nehirden geçme oyunu ile devam ediyoruz, Nehrin bir ucunda kedi,köpek ve fare var bunları nehrin diğer tarafına taşımak lazım ama ateş ile barut yan yana durmaz kedi-köpek,kedi-fare ikilisini yalnız bırakmadan bu işi yapmak gerekiyor, şimdi oyun için ilk olarak aşağıdaki form tasarımını yapıyoruz.
kedikopek
Kodlarımız.. Programı konu sonundan indirebilirsiniz….

 int sefer_sayısı = 0;
        //http://www.bilisimogretmeni.com/
        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                if (listBox1.SelectedItem.ToString() != "KAYIK")
                {
                    string hayvan = listBox1.SelectedItem.ToString();
                    listBox2.Items.Add(hayvan);
                    listBox1.Items.Remove(hayvan);
                }
            }
            listBox1.Items.Remove("KAYIK");
            listBox2.Items.Add("KAYIK");

            button1.Enabled = false;
            button2.Enabled = true;

            KontrolEt(listBox1);
        }
        //-http://www.bilisimogretmeni.com/
        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedItem != null)
            {
                if (listBox2.SelectedItem.ToString() != "KAYIK")
                {
                    string hayvan = listBox2.SelectedItem.ToString();
                    listBox1.Items.Add(hayvan);
                    listBox2.Items.Remove(hayvan);
                }
            }
            listBox2.Items.Remove("KAYIK");
            listBox1.Items.Add("KAYIK");

            button2.Enabled = false;
            button1.Enabled = true;

            KontrolEt(listBox2);
        }
        //http://www.bilisimogretmeni.com/
        private void KontrolEt(ListBox listBox)
        {
            sefer_sayısı++;
            DialogResult dr = DialogResult.Ignore;

            lblDurum.Text = "Durum:" + sefer_sayısı + " sefer yapıldı";

            if (listBox.Items.Contains("Köpek") && listBox.Items.Contains("Kedi"))
                dr = MessageBox.Show("Köpek kediyi yedi!\nTekrar oynamak istermisiniz?",
                   "Kaybettiniz!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            else if (listBox.Items.Contains("Fare") && listBox.Items.Contains("Kedi"))
                dr = MessageBox.Show("Kedi fareyi yedi!\nTekrar oynamak istermisiniz?",
                   "Kaybettiniz!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            else
                if (listBox2.Items.Count == 4)
                    dr = MessageBox.Show("Tebrikler!\nTekrar oynamak istermisiniz?",
                       "Kazandınız!", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            //http://www.bilisimogretmeni.com/
            if (dr == DialogResult.Yes)
            {
                listBox1.Items.Clear();
                listBox2.Items.Clear();
                button1.Enabled = true;
                button2.Enabled = false;
                listBox1.Items.AddRange(new string[] { "Kedi", "Köpek", "Fare", "KAYIK" });
            }
            else if (dr == DialogResult.No)
            {
                Close();
            }
        }
        //http://www.bilisimogretmeni.com/

 

İndir “C# Örnekleri - Nehirden Geçme Oyunu”

KediKopekFareOyunu.zip – 2985 defa indirildi – 54,81 KB
Bu İçeriğe Tepkin Ne Oldu?
  • 1
    ba_ar_l_
    Başarılı
  • 0
    gayet_yi
    Gayet İyi
  • 0
    te_ekk_rler
    Teşekkürler
  • 0
    anlamad_m
    Anlamadım
  • 0
    yetersiz
    Yetersiz
İlginizi Çekebilir
Subscribe
Bildir
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Yorum
Inline Feedbacks
View all comments