Sayı Tahmin Oyunu[C#]
Blog > Sayı Tahmin Oyunu[C#]30 Mayıs 2010 – 14:02
C# ile yapılmış olan başlangıç seviyesinde olan içinler faydalı olucak sayı tahmin oyunu.
![Sayı Tahmin Oyunu[C#] csharptr_sayitahmin](http://i48.tinypic.com/35bgfpl.png)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace SayıOyunu { public class Form1 : System.Windows.Forms.Form { internal System.Windows.Forms.Button button2; internal System.Windows.Forms.Button button1; internal System.Windows.Forms.Label label7; internal System.Windows.Forms.Label Label6; internal System.Windows.Forms.Label label5; internal System.Windows.Forms.Label Label4; internal System.Windows.Forms.Label label3; internal System.Windows.Forms.Label Label2; internal System.Windows.Forms.TextBox textBox1; internal System.Windows.Forms.Label Label1; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } [STAThread] static void Main() { Application.Run(new Form1()); } int sayı; private void Form1_Load(object sender, System.EventArgs e) { textBox1.Text = ""; button1.Enabled = false; this.AcceptButton = button1;//entere tuşuna basılınca otomatik çalışsın } private void button2_Click(object sender, System.EventArgs e) { //Başla düğmesi button1.Enabled = true; button2.Enabled = false; Random r = new Random(); sayı = r.Next(100); //0-100 arası bir sayı tut label7.Text = "1000"; //başlangıçta 1000 puan label5.Text = "0"; //tahmin sayısı 0 label3.Text = ""; } private void button1_Click(object sender, System.EventArgs e) { int tahmin_sayısı, puan, tahmin; try { tahmin = int.Parse(textBox1.Text); } catch { MessageBox.Show("Geçersiz sayı"); return;//prosedürden çık } tahmin_sayısı = int.Parse(label5.Text); tahmin_sayısı ++;//Tahmin sayısını artır label5.Text = tahmin_sayısı.ToString(); puan = int.Parse(label7.Text); puan = puan - tahmin_sayısı*10; label7.Text = puan.ToString(); //Puanı azalt //Tutulan sayı ile tahmin edileni karşılaştır if (sayı < tahmin) label3.Text = "Sayıyı küçültünüz"; else if (sayı > tahmin) label3.Text = "Sayıyı büyütünüz"; else { label3.Text = "Tebrikler. " + label5.Text + " defada bilip " + label7.Text + " puan aldınız."; button2.Enabled = true; button1.Enabled = false; } textBox1.Text = ""; } } } |
Linkler
Csharptr
Etiketler: ”c# sayı oyunu”
2 yorum yapılmış
Teşşekkürler çok işime yaradı. Sağolasın.
24 Haziran 2010 - 02:51