Kodi PHP:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TicTacToe
{
public partial class Form1 : Form
{
Random rnd = new Random();
bool loja_perfundoi;
string radha_lojtarit = String.Empty;
string strLojtari = String.Empty;
string[][] radhaArray;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
inicializo_lojen();
}
private void inicializo_lojen()
{
inicializo_butonat();
inicializo_matricen();
radha_lojtarit = "Lojtari";
loja_perfundoi = false;
loz();
}
protected override void OnPaint(PaintEventArgs e)
{
vizato(34, 135, 303, 135);
vizato(34, 228, 303, 228);
vizato(122, 47, 122, 316);
vizato(215, 47, 215, 316);
}
private void vizato(int p, int p_2, int p_3, int p_4)
{
System.Drawing.Pen lapsi_im;
lapsi_im = new System.Drawing.Pen(System.Drawing.Color.Black, 2);
System.Drawing.Graphics grafika_formes = this.CreateGraphics();
grafika_formes.DrawLine(lapsi_im, p, p_2, p_3, p_4);
lapsi_im.Dispose();
grafika_formes.Dispose();
}
private void loz()
{
if (!loja_perfundoi)
{
if (radha_lojtarit == "Kompjuteri")
{
strLojtari = "O";
kontrollo_potezin();
kontrollo_rezultatin();
radha_lojtarit = "Lojtari";
}
}
}
private void inicializo_matricen()
{
radhaArray = new string[8][];
radhaArray[0] = new string[3] { "b0", "b1", "b2" };
radhaArray[1] = new string[3] { "b3", "b4", "b5" };
radhaArray[2] = new string[3] { "b6", "b7", "b8" };
radhaArray[3] = new string[3] { "b0", "b3", "b6" };
radhaArray[4] = new string[3] { "b1", "b4", "b7" };
radhaArray[5] = new string[3] { "b2", "b5", "b8" };
radhaArray[6] = new string[3] { "b0", "b4", "b8" };
radhaArray[7] = new string[3] { "b2", "b4", "b6" };
}
private void inicializo_butonat()
{
int x = 34; int y = 47;
int z = 0;
for (int i = 0; i < 9; i++)
{
if (z <= 2)
{
krijo_butonat(x, y, i); x += 92; z++;
}
else
{
y += 92;x = 34;z = 0;i--;
}
}
}
private void krijo_butonat(int x, int y, int i)
{
Button b = new Button();
b.Name = "b" + i.ToString();
b.Text = String.Empty;
b.BackColor = Color.Transparent;
b.FlatAppearance.BorderSize = 0;
b.FlatStyle = FlatStyle.Flat;
b.Size = new Size(85, 85);
b.TextAlign = ContentAlignment.MiddleCenter;
FontFamily fontFamily = new FontFamily("Arial");
Font f = new Font(fontFamily, 55, FontStyle.Bold, GraphicsUnit.Pixel);
b.Font = f;
b.Anchor = (AnchorStyles.Left);
b.Location = new Point(x, y);
b.Click += new System.EventHandler(this.b_Click);
this.Controls.Add(b);
}
private void b_Click(object sender, System.EventArgs e)
{
Button butoni_shtypur = (Button)sender;
if (!loja_perfundoi)
{
if (butoni_shtypur.Text == String.Empty)
{
if (radha_lojtarit == "Lojtari")
{
strLojtari = "X";
butoni_shtypur.Text = strLojtari;
kontrollo_rezultatin();
radha_lojtarit = "Kompjuteri";
loz();
}
}
}
}
private void kontrollo_potezin()
{
ArrayList vek_empty = new ArrayList();
bool loz = false;
bool lojtari_avantazh = false;
bool kompjuteri_avantazh = false;
for (int i = 0; i < radhaArray.GetLength(0); i++)
{
int y = 0;
int w = 0;
if (!loz)
{
for (int j = 0; j < radhaArray[i].GetLength(0); j++)
{
if (this.Controls[radhaArray[i][j]].Text == "X")
y++;
else if (this.Controls[radhaArray[i][j]].Text == "O")
w++;
}
if (w == 2 && y == 0)
kompjuteri_avantazh = true;
else if (y == 2 && w == 0)
lojtari_avantazh = true;
}
}
if (kompjuteri_avantazh)
{
for (int i = 0; i < radhaArray.GetLength(0); i++)
{
int y = 0;
int w = 0;
if (!loz)
{
for (int j = 0; j < radhaArray[i].GetLength(0); j++)
{
if (this.Controls[radhaArray[i][j]].Text == "X")
y++;
else if (this.Controls[radhaArray[i][j]].Text == "O")
w++;
}
if (w == 2 && y == 0)
{
for (int z = 0; z < radhaArray[i].GetLength(0); z++)
{
if (this.Controls[radhaArray[i][z]].Text != "O")
{
this.Controls[radhaArray[i][z]].Text = strLojtari;
loz = true;
}
}
}
}
}
}
else if (lojtari_avantazh)
{
for (int i = 0; i < radhaArray.GetLength(0); i++)
{
int y = 0;
int w = 0;
if (!loz)
{
for (int j = 0; j < radhaArray[i].GetLength(0); j++)
{
if (this.Controls[radhaArray[i][j]].Text == "X")
y++;
else if (this.Controls[radhaArray[i][j]].Text == "O")
w++;
}
if (y == 2 && w == 0)
{
for (int z = 0; z < radhaArray[i].GetLength(0); z++)
{
if (this.Controls[radhaArray[i][z]].Text != "X")
{
this.Controls[radhaArray[i][z]].Text = strLojtari;
loz = true;
}
}
}
}
}
}
else
{
if (this.Controls["b4"].Text == String.Empty)
{
this.Controls["b4"].Text = strLojtari;
loz = true;
}
else
{
for (int m = 0; m < radhaArray.GetLength(0); m++)
{
for (int n = 0; n < radhaArray[m].GetLength(0); n++)
{
if (this.Controls[radhaArray[m][n]].Text == String.Empty)
{
vek_empty.Add(this.Controls[radhaArray[m][n]].Name.ToString());
}
}
}
if (!loz)
{
if (vek_empty.Count > 0)
{
int numri_random = rnd.Next(0, vek_empty.Count);
this.Controls[vek_empty[numri_random].ToString()].Text = strLojtari;
loz = true;
}
}
}
}
}
private void kontrollo_rezultatin()
{
for (int i = 0; i < radhaArray.GetLength(0); i++)
{
int y = 0;
for (int j = 0; j < radhaArray[i].GetLength(0); j++)
{
if (this.Controls[radhaArray[i][j]].Text == strLojtari)
y++;
if (y == 3)
{
lstRezultatet.Items.Add("Fitues " + radha_lojtarit);
loja_perfundoi = true;
MessageBox.Show("Fitues " + radha_lojtarit, "Informacion!",
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}
private void LojeRe_Click(object sender, EventArgs e)
{
pastrimi_kimik();
inicializo_lojen();
}
private void pastrimi_kimik()
{
List<Control> zhdukiButonat = new List<Control>();
foreach (Control c in this.Controls)
{
if (c is Button)
{
if (c.Name.Substring(0, 1) == "b")
{
zhdukiButonat.Add(c);
}
}
}
foreach (Control remove in zhdukiButonat)
{
this.Controls.Remove(remove);
remove.Dispose();
}
}
private void FshijRezultatin_Click(object sender, EventArgs e)
{
lstRezultatet.Items.Clear();
}
}
}
Nuk e ka grafiken te mire si ajo e Ukes por edhe une nuk e lashe pa u munduar
Krijoni Kontakt