Dört İşlem Oyunu (Rastgele Üretilen İşlemlere Göre Hesap Yapma) — Csharp
[code lang=”csharp”]
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;
//www.gorselprogramlama.com
namespace Coelho2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Random r = new Random();
char[] islemler = new char[4];
int ilkSayi = 0;
int sonSayi = 0;
int sonuc = 0;
char islem;
int puan = 0;//www.gorselprogramlama.com
int kalanSure = 60;
private void Form1_Load(object sender, EventArgs e)
{
islemler[0] = ‘+’;
islemler[1] = ‘-‘;
islemler[2] = ‘*’;
islemler[3] = ‘/’;
islem = islemler[r.Next(0, 4)];
ilkSayi = r.Next(1, 10);
sonSayi = r.Next(1, 10);
lblSayi1.Text = ilkSayi.ToString();
lblSayi2.Text = sonSayi.ToString();
lbl_islem.Text = islem.ToString();
switch (islem)
{
case ‘+’://www.gorselprogramlama.com
sonuc = ilkSayi + sonSayi;
break;
case ‘-‘:
sonuc = ilkSayi – sonSayi;
break;
case ‘*’:
sonuc = ilkSayi * sonSayi;
break;
case ‘/’:
sonuc = ilkSayi / sonSayi;
break;//www.gorselprogramlama.com
}
tmrSure.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
int tahmin = Convert.ToInt32(textBox1.Text);
if (sonuc == tahmin)
{
puan += 10;
lblPuan.Text = "Puanınız : " + puan.ToString();
}
islem = islemler[r.Next(0, 4)];
//www.gorselprogramlama.com
ilkSayi = r.Next(1, 10);
sonSayi = r.Next(1, 10);
lblSayi1.Text = ilkSayi.ToString();
lblSayi2.Text = sonSayi.ToString();
lbl_islem.Text = islem.ToString();
switch (islem)
{
case ‘+’:
sonuc = ilkSayi + sonSayi;
break;
case ‘-‘:
sonuc = ilkSayi – sonSayi;
break;
case ‘*’:
sonuc = ilkSayi * sonSayi;
break;
case ‘/’:
sonuc = ilkSayi / sonSayi;
break;
}
textBox1.Text = "";
textBox1.Focus();
}
private void tmrSure_Tick(object sender, EventArgs e)
{//www.gorselprogramlama.com
if (kalanSure == 0)
{
tmrSure.Enabled = false;
MessageBox.Show("Oyun Bitti. Süreniz Dolmuştur.");
}
else
{
kalanSure–;
lblKalanSure.Text = "Kalan Süre : " + kalanSure.ToString();
}
}
}
}
//www.gorselprogramlama.com
[/code]

