Home » » C# — Gelişmiş XOX Oyunu

C# — Gelişmiş XOX Oyunu

Gelişmiş XOX Oyunu — C#




Giriş Formu


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;//www.gorselprogramlama.com

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace Gelişmiş_XOX_game

{

public partial class frmGiris : Form

{

public frmGiris()

{

InitializeComponent();

}

private void rbPc_CheckedChanged(object sender, EventArgs e)

{

if (rbPc.Checked)//www.gorselprogramlama.com

{

txtN2.ReadOnly = true;

txtN2.Text = "";

}

}

private void rbTwo_CheckedChanged(object sender, EventArgs e)

{

if (rbTwo.Checked)

{

txtN2.ReadOnly = false;

}

}

private void btnStart_Click(object sender, EventArgs e)

{

frmOyun frmO = new frmOyun();

//www.gorselprogramlama.com

if (rbTwo.Checked && txtN2.Text.Length == 0 || txtN1.Text.Length == 0)

{

MessageBox.Show("Oyuncuların Nickini girmediniz.");

return;

}

frmO.n1 = txtN1.Text;

//www.gorselprogramlama.com

if (rbTwo.Checked)

{

frmO.n2 = txtN2.Text;

frmO.ikiKisilik = true;

}

else

frmO.n2 = "Bilgisayar";

frmO.Show();//www.gorselprogramlama.com

this.Hide();

}

private void frmGiris_Load(object sender, EventArgs e)

{

}

}

}


Oyun Formu

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;//www.gorselprogramlama.com

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace Gelişmiş_XOX_game

{

public partial class frmOyun : Form

{

public frmOyun()

{

InitializeComponent();

}

#region Değişkenler

string[,] XOX = new string[3, 3];

char oyanacakIsaret = 'X';

char yazilacakIsaret = 'X';//www.gorselprogramlama.com

string[,] kontrol = new string[8, 3];

public string n1, n2;

public bool ikiKisilik = false;

bool kazanilma = false;//www.gorselprogramlama.com

int skor_n1 = 0, skor_n2 = 0;

int tiklanma = 0;

#endregion

#region Yordam ve Func.

void IsaretSirasi(PictureBox pb)

{

if (pb.Image == null)

{

if (oyanacakIsaret == 'X')

{

pb.Image = Properties.Resources.x_pic;

if (ikiKisilik) lblSira.Text = "Oynama Sirası : " + n2;

yazilacakIsaret = 'X';

oyanacakIsaret = 'O';

}

else  //www.gorselprogramlama.com

{

pb.Image = Properties.Resources.o_pic;

if (ikiKisilik) lblSira.Text = "Oynama Sirası : " + n1;

yazilacakIsaret = 'O';

oyanacakIsaret = 'X';

}

}

}

void ihtimalKontrol(string koordinat)

{

for (int i = 0; i < 8; i++)

{

for (int j = 0; j < 3; j++)

{//www.gorselprogramlama.com

if (kontrol[i, j] == koordinat && !kazanilma)

{

XOXKontrol(i); // i

}

}

}

if (tiklanma >= 9 )

{

MessageBox.Show("Berabere kaldınız.");

Temizle();

}            //www.gorselprogramlama.com

kazanilma = false;

}

void XOXKontrol(int sira)

{

string[] k1 = kontrol[sira, 0].Split(',');

string[] k2 = kontrol[sira, 1].Split(',');

string[] k3 = kontrol[sira, 2].Split(',');

//MessageBox.Show(k1[0] + "," + k1[1] + " - " + k2[0] + "," + k2[1] + " - " + k3[0] + "," + k3[1] );

//MessageBox.Show(XOX[int.Parse(k1[0]), int.Parse(k1[1])].ToString() + " - " + XOX[int.Parse(k2[0]), int.Parse(k2[1])].ToString() + " - " + XOX[int.Parse(k3[0]), int.Parse(k3[1])].ToString());

if (XOX[int.Parse(k1[0]), int.Parse(k1[1])] == XOX[int.Parse(k2[0]), int.Parse(k2[1])] &&

XOX[int.Parse(k2[0]), int.Parse(k2[1])] == XOX[int.Parse(k3[0]), int.Parse(k3[1])])

{   //Oyun kazanma durumu

kazanilma = true;

tiklanma = 0;

string Pb1 = "PB" + k1[0] + "_" + k1[1];//www.gorselprogramlama.com

string Pb2 = "PB" + k2[0] + "_" + k2[1];

string Pb3 = "PB" + k3[0] + "_" + k3[1];

isaretBoya(Pb1, Pb2, Pb3);

if (yazilacakIsaret == 'X')

{

MessageBox.Show(n1 + " Oyunu Kazandı.");

skor_n1 += 5;

lblN1.Text = n1 + " : " + skor_n1;

}

else

{

MessageBox.Show(n2 + " Oyunu Kazandı.");

skor_n2 += 5;

lblN2.Text = n2 + " : " + skor_n2;

}

Temizle();//www.gorselprogramlama.com

}

}

void isaretBoya(params string[] pb)

{ //this.Controls.Find(pb[i], true)[0].BackgroundImage = Properties.Resources.o_pic_red;

foreach (Control item in this.groupBox2.Controls)

{

for (int i = 0; i < pb.Length; i++)

{

if (item.Name == pb[i])

{

if (yazilacakIsaret == 'X')

((PictureBox)item).Image = Properties.Resources.x_pic_red;

else

((PictureBox)item).Image = Properties.Resources.o_pic_red;

}

}

}        //www.gorselprogramlama.com

}

void Temizle()

{

for (int i = 0; i < 3; i++)

{

for (int j = 0; j < 3; j++)

{

XOX[i, j] = "";

}

}

PB0_0.Image = null;

PB0_1.Image = null;

PB0_2.Image = null;

PB1_0.Image = null;

PB1_1.Image = null;

PB1_2.Image = null;

PB2_0.Image = null;

PB2_1.Image = null;

PB2_2.Image = null;

//www.gorselprogramlama.com

tiklanma = 0;

// kazanilma = false;

}

void sanalOynat()

{

//if (XOX[0, 0] == XOX[0, 1] && XOX[0, 2] != "X" && XOX[0, 2] != "O" && XOX[0, 2] != "") // yatay 1 X - X - ?

}

#endregion

#region Pb Click

private void PB_Click(object sender, EventArgs e)

{

if (((PictureBox)sender).Image == null)

{

IsaretSirasi(((PictureBox)sender)); // Oynattık

string alanID = ((PictureBox)sender).Name.Remove(0, 2);

string[] koordinat = alanID.Split('_');

XOX[int.Parse(koordinat[0]), int.Parse(koordinat[1])] = yazilacakIsaret.ToString();

tiklanma++; //www.gorselprogramlama.com

ihtimalKontrol(koordinat[0] + "," + koordinat[1]);

}

}

#endregion

private void frmOyun_Load(object sender, EventArgs e)

{

lblN1.Text = n1 + " : 0";

lblN2.Text = n2 + " : 0";

lblSira.Text = "Oynama Sirasi : " + n1;

#region İhtimaller Koordinatları

kontrol[0, 0] = "0,0"; // yatay 1

kontrol[0, 1] = "0,1";

kontrol[0, 2] = "0,2";//www.gorselprogramlama.com

kontrol[1, 0] = "1,0"; // yatay 2

kontrol[1, 1] = "1,1";

kontrol[1, 2] = "1,2";

kontrol[2, 0] = "2,0"; // yatay 3

kontrol[2, 1] = "2,1";//www.gorselprogramlama.com

kontrol[2, 2] = "2,2";

kontrol[3, 0] = "0,0"; // dikey 1

kontrol[3, 1] = "1,0";

kontrol[3, 2] = "2,0";

kontrol[4, 0] = "0,1"; // dikey 2

kontrol[4, 1] = "1,1";

kontrol[4, 2] = "2,1";

kontrol[5, 0] = "0,2"; // dikey 3

kontrol[5, 1] = "1,2";

kontrol[5, 2] = "2,2";

kontrol[6, 0] = "0,0"; // çapraz 1

kontrol[6, 1] = "1,1";

kontrol[6, 2] = "2,2";

kontrol[7, 0] = "0,2"; // çapraz 2

kontrol[7, 1] = "1,1";

kontrol[7, 2] = "2,0";//www.gorselprogramlama.com

#endregion

Temizle();

}

}

}
 
Support : Vaganzi
Copyright © 2013. Visual Studio Kod Bankası - All Rights Reserved
Powered By Vaganzi