BÜYÜK RİSK Yarışması — Csharp
Form2
[code lang=”csharp”]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;//www.gorselprogramlama.com
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace buyuk_risk_yarimasi
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();//www.gorselprogramlama.com
}
private void btnGiris_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
frm1.radioButton1.Text=textBox1.Text;
frm1.radioButton2.Text = textBox2.Text;
frm1.radioButton3.Text = textBox3.Text;
frm1.Show();
this.Hide();
}
}
}
<span style="text-decoration: underline;">Form1</span>
[code lang="csharp"]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;//www.gorselprogramlama.com
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace buyuk_risk_yarimasi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Button[] butonDizi;
public OleDbConnection bag = new OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0;Data Source=data.accdb");
public OleDbCommand kmt = new OleDbCommand();
string[] baslikDizi;
int[] sayilar = new int[10];
string[] sorular = new string[25];
string[] cevaplar = new string[25];
Random r = new Random();
int randomSayac = 0, baslikSay=0, cevapPuan, puan1, puan2, puan3,dak=0,etap,risk1, risk2, risk3;
string cevap = "",finalCevap="",finalSorusu="",finalBaşlık="",cevap1, cevap2, cevap3;
Boolean durum = true;
void butonOlustur3()
{//www.gorselprogramlama.com
int x=0,y=0,deger=0;
butonDizi = new Button[25];
for (int i = 0; i < butonDizi.Length; i++)
{
if (i % 5 == 0)
{
x = x + 100;
y = 50;
deger = 100;
}
else
{
y = y + 35;
deger = deger + 100;
}
//www.gorselprogramlama.com
butonDizi[i] = new Button();
butonDizi[i].Name = i.ToString();
butonDizi[i].ForeColor = Color.Blue;
butonDizi[i].Text = deger.ToString();
butonDizi[i].BackColor = Color.Yellow;
butonDizi[i].Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold);
butonDizi[i].Click += new EventHandler(islem);
this.Controls.Add(butonDizi[i]);
butonDizi[i].Location = new Point(x , y);
}
}
void butonOlustur2()
{
int x = 0, y = 0, deger = 0;
butonDizi = new Button[25];
for (int i = 0; i < butonDizi.Length; i++)
{
if (i % 5 == 0)
{
x = x + 100;
y = 50;
deger = 200;
}
else
{
y = y + 35;
deger = deger + 200;//www.gorselprogramlama.com
}
butonDizi[i] = new Button();
butonDizi[i].Name = i.ToString();
butonDizi[i].ForeColor = Color.Blue;
butonDizi[i].Text = deger.ToString();
butonDizi[i].BackColor = Color.Yellow;
butonDizi[i].Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold);
butonDizi[i].Click += new EventHandler(islem);
this.Controls.Add(butonDizi[i]);
butonDizi[i].Location = new Point(x, y);
}
}
void butonOlustur(int a,int b)
{
int x = 0, y = 0, deger = 0;
butonDizi = new Button[25];
for (int i = 0; i < butonDizi.Length; i++)//www.gorselprogramlama.com
{
if (i % 5 == 0)
{
x = x + 100;
y = 50;
deger = a;
}
else
{
y = y + 35;
deger = deger + b;
}
butonDizi[i] = new Button();
butonDizi[i].Name = i.ToString();
butonDizi[i].ForeColor = Color.Blue;//www.gorselprogramlama.com
butonDizi[i].Text = deger.ToString();
butonDizi[i].BackColor = Color.Yellow;
butonDizi[i].Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold);
butonDizi[i].Click += new EventHandler(islem);
this.Controls.Add(butonDizi[i]);
butonDizi[i].Location = new Point(x, y);
}
}
void rastgeleSayi(int a)
{
int rastgele;
randomSayac = 0;
while (randomSayac < 10)
{
rastgele = r.Next(1, a);//1 ile KAYIT SAYISI arasında rastgele sayı üretiliyor
if (Array.IndexOf(sayilar, rastgele) == -1) //dizinin içinde aynı sayı yoksa
{
sayilar[randomSayac] = rastgele;
randomSayac++;
}//www.gorselprogramlama.com
}
}
void basliklar()
{
int sayac=0;
baslikSay = 0;
bag.Open();
kmt.Connection = bag;
kmt.CommandText = "SELECT COUNT(baslik) FROM (SELECT DISTINCT baslik FROM sorular)";
baslikSay = int.Parse(kmt.ExecuteScalar().ToString());
baslikDizi = new string[baslikSay+1];
kmt.CommandText = "Select DISTINCT baslik from sorular";
OleDbDataReader oku;
oku = kmt.ExecuteReader();
while (oku.Read())
{
baslikDizi[sayac] = oku[0].ToString();//www.gorselprogramlama.com
sayac++;
}
oku.Dispose();
bag.Close();
}
void sorularDiziEkle()
{
int sayac2=0,baslangic,bitis;
bag.Open();
OleDbDataReader oku;
if (etap == 1)
{
baslangic = 0; bitis = 5;
}
else
{
baslangic = 5; bitis = 10;
}//www.gorselprogramlama.com
for (int i = baslangic; i < bitis; i++)
{
kmt.Connection = bag;
kmt.CommandText = "SELECT soru FROM sorular where baslik=@baslik";
kmt.Parameters.AddWithValue("@baslik", baslikDizi[sayilar[i]]);
label6.Text=label6.Text+ " —- " + baslikDizi[sayilar[i]].ToString();
oku = kmt.ExecuteReader();
while (oku.Read())
{
sorular[sayac2] = oku[0].ToString();
sayac2++;
}
oku.Dispose();
kmt.Parameters.Clear();//www.gorselprogramlama.com
}
bag.Close();
}
void cevaplarDiziEkle()
{
int sayac2 = 0, baslangic,bitis;
if (etap == 1)
{
baslangic = 0; bitis = 5;
}
else //www.gorselprogramlama.com
{
baslangic = 5; bitis = 10;
}
bag.Open();
OleDbDataReader oku;
for (int i = baslangic; i < bitis; i++)
{
kmt.Connection = bag;
kmt.CommandText = "SELECT cevap FROM sorular where baslik=@baslik";
kmt.Parameters.AddWithValue("@baslik", baslikDizi[sayilar[i]]);
oku = kmt.ExecuteReader();
while (oku.Read())
{
cevaplar[sayac2] = oku[0].ToString();//www.gorselprogramlama.com
sayac2++;
}
oku.Dispose();
kmt.Parameters.Clear();
}
bag.Close();
}
private void islem(object sender, EventArgs e)
{
if (durum == true)
{
Button tiklananButon = (sender as Button);
int tiklanan = int.Parse(tiklananButon.Name.ToString());//www.gorselprogramlama.com
label1.Text ="Soru –> " +sorular[tiklanan];
cevap = cevaplar[tiklanan];
cevapPuan = int.Parse(tiklananButon.Text);
tiklananButon.Enabled = false;
timer1.Enabled = true;
dak = 30;
label5.Text = dak.ToString();
durum =false;
}
else
{
MessageBox.Show("Ekranda cevaplanmayan soru var !");//www.gorselprogramlama.com
}
}
void puanYaz()
{
label2.Text = radioButton1.Text + " Puan = " + puan1.ToString();
label3.Text = radioButton2.Text + " Puan = " + puan2.ToString();
label4.Text = radioButton3.Text + " Puan = " + puan3.ToString();
}
void finalSoru()
{
bag.Open();
kmt.Connection = bag;
kmt.CommandText = "SELECT Count(*) FROM final";
int sinir = int.Parse(kmt.ExecuteScalar().ToString());//www.gorselprogramlama.com
int rsayi = r.Next(sinir);
kmt.CommandText = "Select * from final where id=@id";
kmt.Parameters.AddWithValue("@id", rsayi);
OleDbDataReader oku;
oku = kmt.ExecuteReader();
while (oku.Read())
{
finalSorusu= oku[1].ToString();//www.gorselprogramlama.com
finalCevap = oku[2].ToString();
finalBaşlık = oku[3].ToString();
}
oku.Dispose();
bag.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
etap = 1;
butonOlustur(100,100);
basliklar();
rastgeleSayi(baslikSay);//www.gorselprogramlama.com
sorularDiziEkle();
cevaplarDiziEkle();
dak = 30;
puanYaz();
}
private void btnCevapla_Click(object sender, EventArgs e)
{
if (textBox1.Text.ToLower() != cevap)
{
if (radioButton1.Checked)
{
puan1 = puan1 – cevapPuan;
}
if (radioButton2.Checked)
{
puan2 = puan2 – cevapPuan;//www.gorselprogramlama.com
}
if (radioButton3.Checked)
{
puan3 = puan3 – cevapPuan;
}
}
else
{
if (radioButton1.Checked)
{
puan1 = puan1 + cevapPuan;
}
if (radioButton2.Checked)
{
puan2 = puan2 + cevapPuan;
}
if (radioButton3.Checked)
{
puan3 = puan3 + cevapPuan;
}
}
puanYaz();
textBox1.Clear();
timer1.Enabled = false;
dak = 30;
label5.Text = dak.ToString();
durum = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (dak > 0)
{
dak–;
label5.Text = dak.ToString();
}//www.gorselprogramlama.com
else
{
if (radioButton1.Checked)
{
puan1 = puan1 – cevapPuan;
}//www.gorselprogramlama.com
if (radioButton2.Checked)
{
puan2 = puan2 – cevapPuan;
}
if (radioButton3.Checked)
{
puan3 = puan3 – cevapPuan;
}
puanYaz();
timer1.Enabled = false;
durum = true;//www.gorselprogramlama.com
MessageBox.Show("Süre Doldu !");
}
}
private void btnIkinciEtap_Click(object sender, EventArgs e)
{
etap = 2;
label6.Text = "";
for (int i = 0; i < 34; i++)
{
this.Controls.RemoveByKey(i.ToString());
}
butonOlustur(200, 200);
Array.Clear(sorular, 0, sorular.Length);
Array.Clear(cevaplar, 0, cevaplar.Length);
sorularDiziEkle();
cevaplarDiziEkle();
durum = true;
}
private void btnFinal_Click(object sender, EventArgs e)
{
finalSoru();
label7.Text = "Soru Başlığı –> " + finalBaşlık.ToString();//www.gorselprogramlama.com
etap = 3;
label6.Text = "";
for (int i = 0; i < 34; i++)
{
this.Controls.RemoveByKey(i.ToString());
}
textBox2.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
label7.Visible = true;
label1.Visible = false;
btnFinalSorusu.Visible = true;
btnCevapla.Visible = false;
textBox1.Visible = false;
textBox2.Text = radioButton1.Text + " Riskinizi Giriniz . ";
textBox3.Text = radioButton2.Text + " Riskinizi Giriniz . ";
textBox4.Text = radioButton3.Text + " Riskinizi Giriniz . ";//www.gorselprogramlama.com
}
private void btnFinalSorusu_Click(object sender, EventArgs e)
{
risk1 = int.Parse(textBox2.Text);
risk2 = int.Parse(textBox3.Text);
risk3 = int.Parse(textBox4.Text);
label7.Text = "Soru –> " + finalSorusu.ToString();
textBox2.Text = radioButton1.Text + " Cevabınızı Giriniz . ";
textBox3.Text = radioButton2.Text + " Cevabınızı Giriniz . ";
textBox4.Text = radioButton3.Text + " Cevabınızı Giriniz . ";//www.gorselprogramlama.com
cevap1 = textBox2.Text;
cevap2 = textBox3.Text;
cevap3 = textBox4.Text;
btnFinalCevapla.Visible = true;
}
private void btnFinalCevapla_Click(object sender, EventArgs e)
{
if (cevap1 == finalCevap) puan1 = risk1 * 2;
else puan1 = puan1 – risk1;
if (cevap2 == finalCevap) puan2 = risk2 * 2;
else puan2 = puan2 – risk2;
if (cevap3== finalCevap) puan3 = risk3 * 2;
else puan3 = puan3 – risk3;
textBox2.Text = radioButton1.Text + " Kazanılan Para " +puan1;
textBox3.Text = radioButton2.Text + " Kazanılan Para " + puan2;
textBox4.Text = radioButton3.Text + " Kazanılan Para " + puan3;
int[] puanlar=new int[3];
puanlar[0] = puan1; puanlar[1] = puan2; puanlar[2] = puan3;//www.gorselprogramlama.com
int mak=0,kaz=0;
mak = puanlar.Max();
for (int i = 0; i < 3; i++)
{
if (puanlar[i] == mak) kaz=(i+1);
}
if (kaz == 1) label7.Text = "Yarışmayı " + puan1+ " la "+ radioButton1.Text+" kazandı . ";
if (kaz == 2) label7.Text = "Yarışmayı " + puan2 + " la " + radioButton2.Text + " kazandı . ";
if (kaz == 3) label7.Text = "Yarışmayı " + puan3 + " la " + radioButton3.Text + " kazandı . ";
}//www.gorselprogramlama.com
}
}
[/code]







