ŞEHİR BULMACA OYUNU


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;


namespace sehri_bulma_oyunu

{

    public partial class FORM : Form

    {

        string[] sehirlerListesi = { "İSTANBUL", "ANKARA", "İZMİR", "ADANA","AFYONKARAHİSAR", "AĞRI", "AKSARAY", "AMASYA", "ANTALYA", "ARDAHAN", "ARTVİN", "AYDIN", "BALIKESİR", "BARTIN", "BATMAN", "BAYBURT", "BİLECİK", "BİNGÖL", "BİTLİS", "BOLU", "BURDUR", "BURSA", "ÇANAKKALE", "ÇANKIRI", "ÇORUM", "DENİZLİ", "DİYARBAKIR", "DÜZDE", "EDİRNE", "ELAZIĞ", "ERZİNCAN", "ERZURUM", "ESKİŞEHİR", "GAZİANTEP", "GİRESUN", "GÜMÜŞHANE", "HAKKARİ", "HATAY", "IĞDIR", "ISPARTA", "KAHRAMANMARAŞ", "KARABÜK", "KARAMAN", "KARS", "KASTAMONU", "KAYSERİ", "KIRIKKALE", "KIRKLARELİ", "KIRŞEHİR", "KİLİS", "KOCAELİ", "KONYA", "KÜTAHYA", "MALATYA", "MANİSA", "MARDİN", "MERSİN", "MUĞLA", "MUŞ", "NEVŞEHİR", "NİĞDE", "ORDU", "OSMANİYE", "RİZE", "SAKARYA", "SAMSUN", "SİİRT", "SİNOP", "SİVAS", "ŞIRNAK", "TEKİRDAĞ", "TOKAT", "TRABZON", "TUNCELİ", "ŞANLIURFA", "UŞAK", "VAN", "YALOVA", "YOZGAT", "ZONGULDAK" };

        string bulunacakSehirIsmi = "";

        int bulunanHarfSayisi = 0;

        int kalanHak = 4;

        Random rastgele;

        public FORM()

        {

            InitializeComponent();

        }

        private void BTNBASLAT_Click(object sender, EventArgs e)

        {

                bulunanHarfSayisi = 0;

                BTNHARF.Enabled = true;

                BTNTAHMIN.Enabled = true;

                lblGirilenHarfler.Text = "";

                kalanHak = 4;

                lblKalanHak.Text = kalanHak.ToString();


                YeniSehirSec();

                grpOyunAlani.Controls.Clear();

                for (int i = 0; i < bulunacakSehirIsmi.Length; i++)

                {

                Label label1 = new Label();

                label1.Location = new Point(35 * i + 100, 40);

                label1.Text = bulunacakSehirIsmi[i].ToString();

                label1.Font = new System.Drawing.Font("Segoe UI", 15.50F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(162)));

                label1.Size = new System.Drawing.Size(30, 40);

                label1.BackColor = Color.Blue;

                label1.ForeColor = Color.Blue;

                grpOyunAlani.Controls.Add(label1);

            }

        }

        private void BTNHARF_Click(object sender, EventArgs e)

        {

                bool harfVarMi = false;

                if (txtHarf.Text.Length != 1)

                {

                    MessageBox.Show("LÜTFEN TEK HARF GİRİNİZ!", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }

                else

                {

                    if (lblGirilenHarfler.Text.Contains(txtHarf.Text))

                    {

                        MessageBox.Show("BU HARFİ DAHA ÖNCE GİRDİNİZ!", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        txtHarf.Text = "";

                        txtHarf.Focus();

                        return;

                    }

                    foreach (Control item in grpOyunAlani.Controls)

                    {

                        if (item is Label)

                        {

                            Label label = item as Label;

                            if (label.Text.ToUpper() == txtHarf.Text.ToUpper())

                            {

                                label.ForeColor = Color.Black;

                                label.BackColor = Color.Lime;

                                harfVarMi = true;

                                bulunanHarfSayisi++;

                            }

                        }

                    }

                }

                if (!harfVarMi)

                {

                    kalanHak--;


                    lblKalanHak.Text = kalanHak.ToString();


                    if (kalanHak == 0)

                    {

                        BTNHARF.Enabled = false;

                        BTNTAHMIN.Enabled = false;

                        MessageBox.Show("OYUN BİTTİ! **KAYBETTİNİZ** \n Yeni Oyun için yeni kelime giriniz. \n Cevap : " + bulunacakSehirIsmi, "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }

                }

                lblGirilenHarfler.Text += txtHarf.Text + "  ";

                if (bulunanHarfSayisi == bulunacakSehirIsmi.Length)

                {

                    BTNHARF.Enabled = false;

                    BTNTAHMIN.Enabled = false;

                    MessageBox.Show("OYUN BİTTİ! **KAZANDINIZ** \n Yeni Oyun için yeni kelime giriniz.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }


                txtHarf.Text = "";

                txtHarf.Focus();

            }

        private void BTNTAHMIN_Click(object sender, EventArgs e)

        {

                if (bulunacakSehirIsmi.ToUpper() == txtKelime.Text.ToUpper())

                {

                    foreach (Control item in grpOyunAlani.Controls)

                    {

                        if (item is Label)

                        {

                            Label label = item as Label;

                            label.ForeColor = Color.Black;

                            label.BackColor = Color.Lime;

                        }

                    }

                    MessageBox.Show("OYUN BİTTİ! **TEBRİKLER KAZANDINIZ** \n Yeni Oyun için yeni kelime giriniz.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

                else

                {

                    MessageBox.Show("OYUN BİTTİ! **KAYBETTİNİZ** \n Yeni Oyun için yeni kelime giriniz. \n Cevap : " + bulunacakSehirIsmi, "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

                BTNHARF.Enabled = false;

                BTNTAHMIN.Enabled = false;

        }

        private void FORM_Load(object sender, EventArgs e)

        {

                BTNHARF.Enabled = false;

                BTNTAHMIN.Enabled = false;

                rastgele = new Random();


                this.AcceptButton = BTNHARF;

            }

            private void YeniSehirSec()

            {

                int rastgeleSayi = rastgele.Next(0, sehirlerListesi.Length);


                bulunacakSehirIsmi = sehirlerListesi[rastgeleSayi];

            }

    }

}



...




Yorumlar

Yorum Gönder

Popüler Yayınlar