1. Anasayfa
  2. Nesne Tabanlı Programlama

C# Örnekleri – 2 Kişilik Zar Oyunu

C# Örnekleri – 2 Kişilik Zar Oyunu
0

Cihan arkadaşımız tarafından paylaşılan çift kişilik zar atma oyunu, her oyuncu ayrı yarı zar atıyor ve gelen sayıya göre puan kazanıyor programın kaynak kodları ve indirme linki konu sonunda
zaroyun

Random yeni = new Random();
        int sayi;
        int sayi2;
        private void button1_Click(object sender, EventArgs e)
        {
            label9.Text = "2";
            button1.Visible = false;
            button2.Visible = true;
            int rand = yeni.Next(1, 7);
            sayi += rand;
            label14.Text = sayi.ToString();
            if (rand == 1)
            {

                pictureBox1.ImageLocation = "1.png";
            }
            else if (rand == 2)
            {

                pictureBox1.ImageLocation = "2.png";
            }
            else if (rand == 3)
            {
                pictureBox1.ImageLocation = "3.png";
            }
            else if (rand == 4)
            {
                pictureBox1.ImageLocation = "4.png";
            }
            else if (rand == 5)
            {
                pictureBox1.ImageLocation = "5.png";
            }
            else
            {
                pictureBox1.ImageLocation = "6.png";
                MessageBox.Show("Helal Olsun "+label7.Text+"\nDüşeş Attın Bence Galibiyet Sende", "Düşeşin Mutluluğu");
            }
            if (sayi >= 50)
            {
                this.Hide();
                Form3 gal = new Form3();
                gal.Show();
                MessageBox.Show("Tebrikler " + textBox1.Text + " Toplam Skorun = " + sayi,"Oyun Bitti");

            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" ||textBox2.Text == "")
            {
                MessageBox.Show("Oyunu Başlatmak İçin 2 Tane Oyuncu İsmi Girmelisiniz","Oyuncu İsimleri Eksik");
            }
            else
            {
                label7.Text = textBox1.Text;
                label8.Text = textBox2.Text;
                label7.Visible = true;
                label8.Visible = true;
                button1.Visible = true;
                button2.Visible = false;
                label4.Visible = false;
                label5.Visible = false;
                label6.Visible = false;
                textBox1.Visible = false;
                textBox2.Visible = false;
                button3.Visible = false;
                label9.Visible = true;
                label10.Visible = true;
                label11.Visible = true;
                label12.Visible = true;
                label13.Visible = true;
                label14.Visible = true;
                label15.Visible = true;
                label16.Visible = true;
                button4.Visible = true;
                button5.Visible = true;
                label17.Visible = true;
                label3.Text = "Oyun Başladı\nBaşarılar\nRasgele Zar Atın\nVe Karşınızdakine\nKarşı Zafer\nKazanın";
            }

        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            label9.Text = "1";
            button1.Visible = true;
            button2.Visible = false;
            int rand2 = yeni.Next(1, 7);
            sayi2 += rand2;
            label15.Text = sayi2.ToString();
            if (rand2 == 1)
            {
                pictureBox2.ImageLocation = "1.png";

            }
            else if (rand2 == 2)
            {
                pictureBox2.ImageLocation = "2.png";
            }
            else if (rand2 == 3)
            {
                pictureBox2.ImageLocation = "3.png";
            }
            else if (rand2 == 4)
            {
                pictureBox2.ImageLocation = "4.png";
            }
            else if (rand2 == 5)
            {
                pictureBox2.ImageLocation = "5.png";
            }
            else
            {
                pictureBox2.ImageLocation = "6.png";
                MessageBox.Show("Helal Olsun "+label8.Text+"\nDüşeş Attın Bence Galibiyet Sende", "Düşeşin Mutluluğu");
            }
            if (sayi2 >= 50)
            {
                this.Hide();
                Form4 gali = new Form4();
                gali.Show();
                MessageBox.Show("Tebrikler " + textBox2.Text + " Toplam Skorun = " + sayi2,"Oyun Bitti");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label14.Text = sayi.ToString();
            label15.Text = sayi2.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form2 form = new Form2();
            form.Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            int toplam = sayi + sayi2;
            if (toplam < 10)
            {
                MessageBox.Show("Oyunu Yeniden Başlatmak İçin En Az Toplam Skor 10 Olmalı.");
            }
            else
            {
                Application.Restart();
            }
        }

İndir “Çift Kişilik Zar Oyunu”

Coyun.rar – 3287 defa indirildi – 1,22 KB
Bu İçeriğe Tepkin Ne Oldu?
  • 2
    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
Subscribe
Bildir
guest

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

0 Yorum
Inline Feedbacks
View all comments