Formda Köstebek Oyunu Yapma
- ByAdmin
- 21 Ara 2015
- 2 dakikada okunur

Bilgisayarın Random Sayı Üretmesini Sağlayarak Kutularda Rastgele Geziyor Ve Sizde Beyaz Olan Yerlere Tıkladıgınızda Puan Kazanarak Level Atlıyorsunuz...
Kodları:
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 WFA_Kostebek { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { lblPuan.Text = puan.ToString(); for (int i = 1; i <= 20; i++) { Button btn = new Button(); btn.Name = i.ToString(); btn.Width = 50; btn.Height = 50; btn.Click += btn_Click; flowLayoutPanel1.Controls.Add(btn); } timer1.Start(); } int puan = 0; void btn_Click(object sender, EventArgs e) { Button btn = (Button)sender; if (btn.BackColor == Color.White) { puan += 5; if (puan < 50 && puan >= 25) { lblLevel.Text = "2.Level"; timer1.Interval = 1800; }
else if (puan > 50 && puan < 75) { lblLevel.Text = "3.Level"; timer1.Interval = 1500; }
else if (puan > 75 && puan < 100) { lblLevel.Text = "4.Level"; timer1.Interval = 1000; }
lblPuan.Text = puan.ToString(); btn.Enabled = false; } else {
puan -= 5; if (puan < 0) { DialogResult sonuc = MessageBox.Show("Oyun Bitii", "Tekrar oynamak istermisiniz", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (sonuc == DialogResult.Yes) { Application.Restart(); } else { Close(); } }
btn.Enabled = false; } }
private void timer1_Tick(object sender, EventArgs e) { Random rnd = new Random();
int sayi = rnd.Next(1, 21);
foreach (var item in flowLayoutPanel1.Controls) { if (item is Button) { Button btn = (Button)item; if (btn.Name == sayi.ToString()) { btn.BackColor = Color.White; } else { btn.BackColor = Color.Black; } } } }
} }
Comments