C# ile Adam Asmaca 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 AdamAsmaca
{
    public partial class Form1 : Form
    {
        string secilenkelime = "";
        Label[] labels;
        int say = 0;

        public Form1()
        {
            InitializeComponent();
            picbox_AdamAs.ImageLocation = @"..\..\Images\adamasmaca.png";
            picbox_AdamAs.Load();
            ButonEkle();
            LabelEkle();
        }

        private void LabelEkle()
        {
            string[] kelimeler = new string[] { "TÜRKİYE", "AMERİKA", "RUSYA", "UGANDA", "ISPANYA", "KUVEYT", "ÇİN", "KORE", "ITALYA", "GÜRCİSTAN", "UKRAYNA", "SOMALİ" };
            Random rnd = new Random();
            secilenkelime = kelimeler[rnd.Next(kelimeler.Length)];
            labels = new Label[secilenkelime.Length];
            int x = 310, y = 150;

            for (int i = 0; i < secilenkelime.Length; i++)
            {
                Label lbl = new Label();
                lbl.Name = "lbl_" + secilenkelime[i];
                lbl.Text = "_";
                lbl.Size = new Size(40, 40);
                lbl.Location = new Point(x, y);
                lbl.Font = new Font("Arial", 24, FontStyle.Bold);
                this.Controls.Add(lbl);
                labels[i] = lbl;
                labels[i].Text = "_";
                x += 40;
            }
        }

        private void ButonEkle()
        {
            string[] harfler = new string[] { "A", "B", "C", "Ç", "D", "E", "F", "G", "Ğ", "H", "I", "İ", "J", "K", "L", "M", "N", "O", "Ö", "P", "Q", "R", "S", "Ş", "T", "U", "Ü", "V", "W", "X", "Y", "Z" };
            int x = 0, y = 0;

            for (int i = 0; i < harfler.Length; i++)
            {
                Button btn = new Button();
                btn.Name = "btn_" + harfler[i];
                btn.Text = harfler[i].ToString();
                btn.Click += new EventHandler(button_Click);
                btn.Size = new Size(40, 40);

                if (i % 5 == 0)
                {
                    x = 40; y += 40;
                }
                else
                {
                    x += 40;
                }
                btn.Location = new Point(x, y);

                this.Controls.Add(btn);
            }

        }

        private void button_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            btn.Enabled = false;
            bool buludumu = false;

            if (say <= 6)
            {
                for (int i = 0; i < secilenkelime.Length; i++)
                {
                    if (btn.Text == secilenkelime[i].ToString())
                    {
                        labels[i].Text = btn.Text;
                        buludumu = true;
                    }
                }
            }
            else
            {
                MessageBox.Show("Kaybettiniz!!!");
            }

            if (buludumu == false)
            {
                say++;
                AdamAs();
            }

        }

        private void AdamAs()
        {
            switch (say)
            {
                case 1:
                    picbox_AdamAs.ImageLocation = @"..\..\Images\adamasmaca1.png";
                    picbox_AdamAs.Load();
                    break;
                case 2:
                    picbox_AdamAs.ImageLocation = @"..\..\Images\adamasmaca2.png";
                    picbox_AdamAs.Load();
                    break;
                case 3:
                    picbox_AdamAs.ImageLocation = @"..\..\Images\adamasmaca3.png";
                    picbox_AdamAs.Load();
                    break;
                case 4:
                    picbox_AdamAs.ImageLocation = @"..\..\Images\adamasmaca4.png";
                    picbox_AdamAs.Load();
                    break;
                case 5:
                    picbox_AdamAs.ImageLocation = @"..\..\Images\adamasmaca5.png";
                    picbox_AdamAs.Load();
                    break;
                case 6:
                    picbox_AdamAs.ImageLocation = @"..\..\Images\adamasmaca6.png";
                    picbox_AdamAs.Load();
                    break;
            }

        }

        private void yeniToolStripMenuItem_Click(object sender, EventArgs e)
        {
            picbox_AdamAs.ImageLocation = @"..\..\Images\adamasmaca.png";
            ButonEkle();
            LabelEkle();
        }

        private void bitirToolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }
    }
}

Bir Cevap Yazın