1. Anasayfa
  2. Nesne Tabanlı Programlama

C# Örnekleri – C# Mega Hafıza Oyunu

C# Örnekleri – C# Mega Hafıza Oyunu
0

Amaç ekrana 0-99 arasında rastgele değere sahip butonları sırasıyla en hızlı şekilde bularak tıklamak. 10 saniye içinde sıradaki butonu bulamazsanız program size butonu gösteriyor. Butonu gösterdikten sonra ne kadar beklerseniz o kadar puanınız eksiliyor. Programın çalışan halini konu sonundan indirebilirsiniz.
megahafiza

const int BUTONSAY=100;
        const int YUK=50;
        const int GEN=50;
        const int BOS=0;

        Button[] butonlar = new Button[BUTONSAY];
        Stopwatch krmetre = new Stopwatch();
        long bzaman = 0;
        long skor;
        bool eksi=false;

        void sesCalMetot(object ses)
        {
            if (ses is int && sesToolStripMenuItem.Checked)
            {
                int s = (Int32) ses;

                if (s == 1)
                {
                    //Console.Beep(1500, 100);
                    Console.Beep(750, 100);
                }
                if (s == 0)
                {
                    //Console.Beep(750, 100);
                    Console.Beep(500, 100);
                }
                if (s == 2)
                {
                    Console.Beep(400, 200);
                }
            }

        }

        int sayac;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void çıkışToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult cevap = MessageBox.Show( "Çıkmak istiyor musunuz?","Çıkış", MessageBoxButtons.YesNo);
            if (cevap == DialogResult.Yes)
                Application.Exit();
        }

        private void yeniToolStripMenuItem_Click(object sender, EventArgs e)
        {
            do
                if (panelButonlar.Controls.Count > 0)
                    panelButonlar.Controls.RemoveAt(0);
            while (panelButonlar.Controls.Count > 0);

            int[] dizi = new int[BUTONSAY];
            Random rnd = new Random();
            for (int i = 0; i < dizi.Length; i++)
            {
                bool bulundu;
                int s;
                do
                {
                    s = rnd.Next(100);
                    bulundu = false;
                    for (int j = 0; j < i; j++)
                        if (dizi[j] == s) bulundu = true;
                } while (bulundu);
                dizi[i] = s;
            }

            panelButonlar.Width = 10 * (GEN + BOS);
            panelButonlar.Height = 10 * (GEN + BOS);
            sayac = 0;
            lblSiradaki.Text = sayac.ToString();

            for (int i = 0; i < butonlar.Length; i++)
            {
                butonlar[i] = new Button();
                butonlar[i].Size = new Size(GEN, YUK);
                butonlar[i].Text = dizi[i].ToString();
                butonlar[i].BackColor = Color.Black;
                butonlar[i].ForeColor = Color.White;
                butonlar[i].Location = new Point((i % 10) * (GEN + BOS), (i / 10) * (YUK + BOS));
                butonlar[i].Font = new Font("Arial",10, FontStyle.Bold);
                butonlar[i].TabStop = false;
                panelButonlar.Controls.Add(butonlar[i]);
                butonlar[i].Click += butonTiklat;

            }
            skor = 0;
            lblSkor.Text = skor.ToString();
            eksi = false;
            bzaman = 0;
            krmetre.Reset();
            krmetre.Start();

        }

        private void butonTiklat(object nesne, EventArgs e)
        {
            Button btn = nesne as Button;
            int s = Convert.ToInt32(btn.Text);
            if (sayac == s)
            {
                btn.Visible = false;
                sayac++;
                lblSiradaki.Text = sayac.ToString();
                new Thread(sesCalMetot).Start(1);
                if (eksi)
                {
                    skor += (bzaman-krmetre.ElapsedMilliseconds - 5000) / 10;
                    eksi = false;
                }
                else
                    skor += (10000-(krmetre.ElapsedMilliseconds - bzaman)) / 10;
                bzaman = krmetre.ElapsedMilliseconds;
                lblSkor.Text = skor.ToString();
            }
            else
            {
                new Thread(sesCalMetot).Start(0);
            }

            if (sayac == 100)
            {
                krmetre.Stop();
                MessageBox.Show(string.Format("{0} Saniyede bitirdiniz.\nSkorunuz: {1}", krmetre.ElapsedMilliseconds / 1000,skor));
            }

        }

        private void oyunToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lblKron.Text = string.Format("{0:00}:{1:00}:{2:00}", krmetre.Elapsed.Hours,
                                                                 krmetre.Elapsed.Minutes,
                                                                 krmetre.Elapsed.Seconds);

            if (eksi)
                lblEklePuan.Text = ((bzaman - krmetre.ElapsedMilliseconds - 5000) / 10).ToString();
            else
                lblEklePuan.Text = ((10000 - (krmetre.ElapsedMilliseconds - bzaman)) / 10).ToString();

            if (krmetre.ElapsedMilliseconds - bzaman > 10000 && !eksi)
            {
                for (int i = 0; i < panelButonlar.Controls.Count; i++)
                {
                    Button btn = panelButonlar.Controls[i] as Button;
                    if (btn.Text == sayac.ToString())
                    {
                        btn.BackColor = Color.Red;
                        eksi = true;
                        new Thread(sesCalMetot).Start(2);

                    }
                }
                bzaman = krmetre.ElapsedMilliseconds;
            }

        }

        private void sesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            sesToolStripMenuItem.Checked = !sesToolStripMenuItem.Checked;
        }

 

İndir “C# Mega Hafıza Oyunu”

megahafiza.rar – 2675 defa indirildi – 333,60 KB
Bu İçeriğe Tepkin Ne Oldu?
  • 0
    ba_ar_l_
    Başarılı
  • 0
    gayet_yi
    Gayet İyi
  • 1
    te_ekk_rler
    Teşekkürler
  • 1
    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