Bu uygulama ile 4 kişilik bir ekiple tombala oynuyoruz kişi ben adlı kartı kendisi oynuyor eğer çekilen sayı kartında varsa kartında olan yere tıklayarak çinko yolunda ilerliyor:)
button1 -> TORBA , button2->kart belirle, button3->çekilişi oluştur adlı buton.
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;
using System.Collections;
using System.IO;
namespace Tombala_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int y1=0,y2=0,y3=0,y4=0;
int[] dizi = new int[66];
int[] oy1 = new int[6];
int[] oy2 = new int[6];
int[] oy3 = new int[6];
int[] oy4 = new int[6];
int b = 0;
private void button2_Click(object sender, EventArgs e)
{
b++;
if (b > 1)
Application.Restart();
//***********************************************
Random rasgele = new Random();
int sayi=rasgele.Next(1,67);
oy1[0]=sayi;
for (int i = 1; i < 6; i++)
{
sayi = rasgele.Next(1, 67);
for (int j = 0; j < i; j++)
{
if (oy1[j] == sayi)
{
i–;
break;
}
else
{
oy1[i] = sayi;
}
}
}
text1.Text += oy1[0];
text2.Text += oy1[1];
text3.Text += oy1[2];
text4.Text += oy1[3];
text5.Text += oy1[4];
text6.Text += oy1[5];
for (int i = 0; i < 6; i++)
oy1[i] = oy1[i];
/* ******************************** */
int sayi1 = rasgele.Next(1, 67);
oy2[0] = sayi1;
for (int i = 1; i < 6; i++)
{
sayi1 = rasgele.Next(1, 67);
for (int j = 0; j < i; j++)
{
if (oy2[j] == sayi1)
{
i–;
break;
}
else
{
oy2[i] = sayi1;
}
}
}
text7.Text +=oy2[0];
text8.Text +=oy2[1];
text9.Text +=oy2[2];
text10.Text +=oy2[3];
text11.Text +=oy2[4];
text12.Text +=oy2[5];
for (int i = 0; i < 6; i++)
oy2[i] =oy2[i];
/***********************************************************/
int sayi2 = rasgele.Next(1, 67);
oy3[0] = sayi2;
for (int i = 1; i < 6; i++)
{
sayi2 = rasgele.Next(1, 67);
for (int j = 0; j < i; j++)
{
if (oy3[j] == sayi2)
{
i–;
break;
}
else
{
oy3[i] = sayi2;
}
}
}
text13.Text += oy3[0];
text14.Text += oy3[1];
text15.Text += oy3[2];
text16.Text += oy3[3];
text17.Text += oy3[4];
text18.Text += oy3[5];
for (int i = 0; i < 6; i++)
oy3[i] = oy3[i];
/**********************************************************/
int sayi3 = rasgele.Next(1, 67);
oy4[0] = sayi3;
for (int i = 1; i < 6; i++)
{
sayi3 = rasgele.Next(1, 67);
for (int j = 0; j < i; j++)
{
if (oy4[j] == sayi3)
{
i–;
break;
}
else
{
oy4[i] = sayi3;
}
}
}
text19.Text += oy4[0];
text20.Text += oy4[1];
text21.Text += oy4[2];
text22.Text += oy4[3];
text23.Text += oy4[4];
text24.Text += oy4[5];
for (int i = 0; i < 6; i++)
oy4[i] = oy4[i];
StreamWriter sw = new StreamWriter(@”C:\5452.txt”, true);
sw.WriteLine(“1.OYUNCUNUN NUMARALARI”);
for (int i = 0; i < 6; i++)
sw.WriteLine(oy1[i]);
sw.WriteLine(“2.OYUNCUNUN NUMARALARI”);
for (int i = 0; i < 6; i++)
sw.WriteLine(oy2[i]);
sw.WriteLine(“BEN OYUNCUNUN NUMARALARI”);
for (int i = 0; i < 6; i++)
sw.WriteLine(oy3[i]);
sw.WriteLine(“4.OYUNCUNUN NUMARLARI”);
for (int i = 0; i < 6; i++)
sw.WriteLine(oy4[i]);
sw.Close();
}
private void button3_Click(object sender, EventArgs e)
{
int sayi;
Random rasgele = new Random();
int[] cekilen = new int[66];
sayi = rasgele.Next(1, 67);
cekilen[0] = sayi;
for (int k = 1; k < 66; k++)
{
sayi = rasgele.Next(1, 67);
for (int i = 0; i < k; i++)
{
if (cekilen[i] == sayi)
{
k–;
break;
}
else
cekilen[k] = sayi;
}
}
for (int i = 0; i < 66; i++)
dizi[i] = cekilen[i];
MessageBox.Show(“Cekiliş Yapildi”);
}
int a = 0;
private void button1_Click_1(object sender, EventArgs e)
{
textBox1.Text=Convert.ToString( dizi[a]);
StreamWriter sw1 = new StreamWriter(@”C:\5452.txt”,true);
sw1.WriteLine(“*****cekilen sayılar*****”);
sw1.WriteLine(dizi[a]);
sw1.Close();
//************** 1.oyuncu için çinko
if (oy1[0] == dizi[a])
{
text1.Text=”dolu”;
y1++;
}
if (oy1[1] == dizi[a])
{
text2.Text = “dolu”;
y1++;
}
if (oy1[2] == dizi[a])
{
text3.Text = “dolu”;
y1++;
}
if (oy1[3] == dizi[a])
{
text4.Text = “dolu”;
y1++;
}
if (oy1[4] == dizi[a])
{
text5.Text = “dolu”;
y1++;
}
if (oy1[5] == dizi[a])
{
text6.Text = “dolu”;
y1++;
}
//************** 2.oyuncu için çinko
if (oy2[0] == dizi[a])
{
text7.Text = “dolu”;
y2++;
}
if (oy2[1] == dizi[a])
{
text8.Text = “dolu”;
y2++;
}
if (oy2[2] == dizi[a])
{
text9.Text = “dolu”;
y2++;
}
if (oy2[3] == dizi[a])
{
text10.Text = “dolu”;
y2++;
}
if (oy2[4] == dizi[a])
{
text11.Text = “dolu”;
y2++;
}
if (oy2[5] == dizi[a])
{
text12.Text = “dolu”;
y2++;
}
//************** 4.oyuncu için çinko
if (oy4[0] == dizi[a])
{
text19.Text = “dolu”;
y4++;
}
if (oy4[1] == dizi[a])
{
text20.Text = “dolu”;
y4++;
}
if (oy4[2] == dizi[a])
{
text21.Text = “dolu”;
y4++;
}
if (oy4[3] == dizi[a])
{
text22.Text = “dolu”;
y4++;
}
if (oy4[4] == dizi[a])
{
text23.Text = “dolu”;
y4++;
}
if (oy4[5] == dizi[a])
{
text24.Text = “dolu”;
y4++;
}
a++;
//************* kazananı belirleme
if (y1 == 6)
{
MessageBox.Show(“çinkoooo….. 1 . oyuncu kazandı”); // dosyaya yazma kazananı
StreamWriter sw = new StreamWriter(@”C:\5452.txt”, true);
// ikinci parametre olan appen a true değeri girilmesi verileri dosyanın sonuna ekler .false olsa üzerine yazar.
sw.WriteLine(“1.oyuncu kazandı”);
sw.WriteLine(“numaraları”);
for (int i = 0; i < 6; i++)
sw.WriteLine(oy1[i]);
sw.Close();
DialogResult sonuc;
sonuc = MessageBox.Show(“cikis (hayır) yeni oyun için(evet)”, “Onay Kutusu”, MessageBoxButtons.YesNo);
if (sonuc == DialogResult.Yes)
Application.Restart();
else
Application.Exit();
}
if (y2 == 6)
{
MessageBox.Show(” çinkooo….. 2. oyuncu kazandı”);
StreamWriter sw = new StreamWriter(@”C:\5452.txt”, true);
sw.WriteLine(“2.oyuncu kazandı”);
sw.WriteLine(“numaraları”);
for (int i = 0; i < 6; i++)
sw.WriteLine(oy2[i]);
sw.Close();
DialogResult sonuc;
sonuc = MessageBox.Show(“cikis (hayır) yeni oyun için(evet)”, “Onay Kutusu”, MessageBoxButtons.YesNo);
if (sonuc == DialogResult.Yes)
Application.Exit();
else
Application.Restart();
}
if (y3 == 6)
{
MessageBox.Show(” çinkooooo…:) kazandınız tebrikler”);
StreamWriter sw = new StreamWriter(@”C:\5452.txt”, true);
sw.WriteLine(“3.oyuncu kazandı”);
sw.WriteLine(“numaraları”);
for (int i = 0; i < 6; i++)
sw.WriteLine(oy3[i]);
sw.Close();
DialogResult sonuc;
sonuc = MessageBox.Show(“cikis (hayır) yeni oyun için(evet)”, “Onay Kutusu”, MessageBoxButtons.YesNo);
if (sonuc == DialogResult.Yes)
Application.Exit();
else
Application.Restart();
}
if (y4 == 6)
{
MessageBox.Show(“çinkooo…..4. oyuncu kazandı”);
StreamWriter sw = new StreamWriter(@”C:\5452.txt”, true);
sw.WriteLine(“4.oyuncu kazandı”);
sw.WriteLine(“numaraları”);
for (int i = 0; i < 6; i++)
sw.WriteLine(oy4[i]);
sw.Close();
DialogResult sonuc;
sonuc = MessageBox.Show(“cikis (hayır) yeni oyun için(evet) “, “Onay Kutusu”, MessageBoxButtons.YesNo);
if (sonuc == DialogResult.Yes)
Application.Restart();
else
Application.Exit();
}
}
Kullanıcının aktif olarak oynayabilmesi için ben adlı kart üzerindeki textbox ların mouseclick olaylarını aktif ediyoruz.
(properties->Events->mouseclick üstüne çift tıklıyoruz.)
//**************** ben oyuncu için çinko
private void text13_MouseClick(object sender, MouseEventArgs e)
{
if (dizi[a – 1] == oy3[0])
{
if (e.Clicks == 1)
{
text13.Text = “dolu”;
y3++;
}
}
else
MessageBox.Show(“eşleşme yok “);
}
private void text14_MouseClick(object sender, MouseEventArgs e)
{
if(dizi[a-1]==oy3[1])
{
if (e.Clicks == 1)
{
text14.Text = “dolu”;
y3++;
}
}
else
MessageBox.Show(“eşleşme yok “);
}
private void text15_MouseClick(object sender, MouseEventArgs e)
{
if (dizi[a-1] == oy3[2])
{
if (e.Clicks == 1)
{
text15.Text = “dolu”;
y3++;
}
}
else
MessageBox.Show(“eşleşme yok “);
}
private void text16_MouseClick(object sender, MouseEventArgs e)
{
if (dizi[a – 1] == oy3[3])
{
if (e.Clicks == 1)
{
text16.Text = “dolu”;
y3++;
}
}
else
MessageBox.Show(“eşleşme yok “);
}
private void text17_MouseClick(object sender, MouseEventArgs e)
{
if (dizi[a – 1] == oy3[4])
{
if (e.Clicks == 1)
{
text17.Text = “dolu”;
y3++;
}
}
else
MessageBox.Show(“eşleşme yok “);
}
private void text18_MouseClick(object sender, MouseEventArgs e)
{
if (dizi[a – 1] == oy3[5])
{
if (e.Clicks == 1)
{
text18.Text = “dolu”;
y3++;
}
}
else
MessageBox.Show(“eşleşme yok “);
}
}
}
kodun açıklamaları ve kodun tamamı aşağıdaki dosyada mevcuttur.