21 Ocak 2014 Salı

C# ile Eşini Bul Oyunu

Aşağıda görüldüğü gibi 16 tane Button ekliyoruz Text lerini # yapıyoruz
3 tane Label ekliyoruz Label1'in Text özelliği Puan: yapıyoruz,Label2nin Text Özelliğini 0 ve Label 3 ün text Özelliğinide Sıfırla yazpıyoruz.

Kodlarda Şu Şekil

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Eşini_Bulma_Oyunu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Button btn, btn1;
        int puan = 10;
        private void dogrumu(Button parButton)
        {
            if (btn1 != null)
            {
                btn.Text = "#";
                btn1.Text = "#";
                btn = null;
                btn1 = null;
                if (puan != 0)
                    puan = puan - 1;
            }

            if (btn == null || btn == parButton)
            {
                btn = parButton;
                parButton.Text = parButton.Tag.ToString();
            }
            else
            {
                parButton.Text = parButton.Tag.ToString();
                if (parButton.Text == btn.Text)
                {

                    btn.Enabled = false;
                    parButton.Enabled = false;
                    btn1 = null;
                    btn = null;
                    label2.Text = Convert.ToString(puan + Convert.ToInt32(label2.Text));
                    puan = 10;
                }
                else
                {
                    parButton.Text = parButton.Tag.ToString();
                    btn1 = parButton;
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)//Eşref Yunus YILDIRICI
        {
            int[] sayi = new int[16];
            Random r = new Random();
            int sayac = 0;
            int rastgele = 0;
            while (sayac < 16)
            {
                rastgele = r.Next(1, 17);
                if (Array.IndexOf(sayi, rastgele) == -1)
                {
                    sayi[sayac++] = rastgele;
                }

            }

            for (int i = 0; i < 16; i++)
            {
                if (sayi[i] > 8)
                    sayi[i] = sayi[i] - 8;
            }
            int sayim = 0;
            foreach (Control c in this.Controls)
            {

                if (c is Button)
                {

                    ((Button)c).Tag = sayi[sayim].ToString();
                    sayim++;
                }
            }

        }
        //Eşref Yunus YILDIRICI
        private void button1_Click(object sender, EventArgs e)
        {
            dogrumu(button1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dogrumu(button2);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            dogrumu(button3);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            dogrumu(button4);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            dogrumu(button5);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            dogrumu(button6);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            dogrumu(button7);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            dogrumu(button8);
        }
        //Eşref Yunus YILDIRICI
        private void button9_Click(object sender, EventArgs e)
        {
            dogrumu(button9);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            dogrumu(button10);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            dogrumu(button11);
        }

        private void button12_Click(object sender, EventArgs e)
        {
            dogrumu(button12);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            dogrumu(button13);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            dogrumu(button14);
        }

        private void button15_Click(object sender, EventArgs e)
        {
            dogrumu(button15);//Eşref Yunus YILDIRICI
        }

        private void button16_Click(object sender, EventArgs e)
        {
            dogrumu(button16);
        }

        private void label3_Click(object sender, EventArgs e)
        {
            int[] sayi = new int[16];
            Random r = new Random();
            int sayac = 0;
            int rastgele = 0;
            while (sayac < 16)
            {
                rastgele = r.Next(1, 17);
                if (Array.IndexOf(sayi, rastgele) == -1)
                {
                    sayi[sayac++] = rastgele;
                }

            }

            for (int i = 0; i < 16; i++)           
            {                 if (sayi[i] > 8)
                    sayi[i] = sayi[i] - 8;
            }
            int sayim = 0;
            foreach (Control c in this.Controls)
            {

                if (c is Button)
                {

                    ((Button)c).Tag = sayi[sayim].ToString();
                    ((Button)c).Text = "#";
                    ((Button)c).Enabled = true;
                    //Eşref Yunus YILDIRICI
                    sayim++;
                }
            }
            label2.Text = "0";
            puan = 10;
        }
        }
    }

2 Yorum:

saat: 20 Ağustos 2020 14:14 , Blogger Backlink King dedi ki...

Theme360.Net
Bigcrunch.co - Dijital Ajans
Fecby.com - Tasarım Tişört

 
saat: 14 Kasım 2020 08:23 , Blogger BOGAZDA dedi ki...

Bu yorum yazar tarafından silindi.

 

Yorum Gönder

Kaydol: Kayıt Yorumları [Atom]

<< Ana Sayfa