18 Temmuz 2008 Cuma

C# Sayı Tahmin Oyunu


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 SayiTahminiUygulamasi
{
public partial class Form1 : Form
{
int tahminEdilecek = 0;
int KalanHak = 5;
int Sayi;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnBasla_Click(object sender, EventArgs e)
{
Random r = new Random();
tahminEdilecek = r.Next(1, 101);
btnTahmin.Enabled = true;
KalanHak = 5;
txtTahmin.Focus();
}
private void btnTahmin_Click(object sender, EventArgs e)
{
if (txtTahmin.Text == "")
{
MessageBox.Show("Geçersiz Bir Değer Girdiniz, Lütfen Tekrar Deneyiniz.");
}
else
{
Sayi = Convert.ToInt16(txtTahmin.Text);
if (tahminEdilecek == Sayi)
{
lblSonuc.Text = "Tebrikler Bildiniz";
pictureBox1.Visible = true;
pictureBox2.Visible = false;
}
if (tahminEdilecek < text = "Daha Aşağı!" visible =" true;" text =" KalanHak.ToString();"> Sayi)
{
lblSonuc.Text = "Daha Yukarı!";
pictureBox2.Visible = true;
KalanHak--;
lblHak.Text = KalanHak.ToString();
}
if (KalanHak == 0)
{
MessageBox.Show("Hakkınız Bitti");
btnTahmin.Enabled = false;
}
}
}
}
}

Hiç yorum yok: