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;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
int charch,chch,b1=1,b2=1,b3=1,b4=1,b5=1,b6=1,b7=1,b8=1,b9=1;
int bn1, bn2, bn3, bn4, bn5, bn6, bn7, bn8, bn9;
int win = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
if (b1 == 1)
{
charch = charch + 1;
chch = charch % 2;
if (chch == 1)
{
button1.Text = "o";
bn1 = 1;
}
else
{
button1.Text = "x";
bn1 = 2;
}
b1 = 2;
}
if (win == 0)
{
if (bn1 == bn2)
{
if (bn2 == bn3)
{
if (bn1 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn1 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn1 == bn4)
{
if (bn4 == bn7)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn2 == bn5)
{
if (bn5 == bn8)
{
if (bn2 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn2 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn6)
{
if (bn6 == bn9)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn4 == bn5)
{
if (bn5 == bn6)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn5)
{
if (bn5 == bn7)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn7 == bn8)
{
if (bn8 == bn9)
{
if (bn7 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn7 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
label2.Text = Convert.ToString(win);
}
private void button2_Click(object sender, EventArgs e)
{
if (b2 == 1)
{
charch = charch + 1;
chch = charch % 2;
if (chch == 1)
{
button2.Text = "o";
bn2 = 1;
}
else
{
button2.Text = "x";
bn2 = 2;
}
b2 = 2;
}
if (win == 0)
{
if (bn1 == bn2)
{
if (bn2 == bn3)
{
if (bn1 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn1 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn1 == bn4)
{
if (bn4 == bn7)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn2 == bn5)
{
if (bn5 == bn8)
{
if (bn2 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn2 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn6)
{
if (bn6 == bn9)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn4 == bn5)
{
if (bn5 == bn6)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn5)
{
if (bn5 == bn7)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn7 == bn8)
{
if (bn8 == bn9)
{
if (bn7 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn7 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
label2.Text = Convert.ToString(charch);
}
private void button3_Click(object sender, EventArgs e)
{
if (b3 == 1)
{
charch = charch + 1;
chch = charch % 2;
if (chch == 1)
{
button3.Text = "o";
bn3 = 1;
}
else
{
button3.Text = "x";
bn3 = 2;
}
b3 = 2;
}
if (win == 0)
{
if (bn1 == bn2)
{
if (bn2 == bn3)
{
if (bn1 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn1 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn1 == bn4)
{
if (bn4 == bn7)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn2 == bn5)
{
if (bn5 == bn8)
{
if (bn2 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn2 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn6)
{
if (bn6 == bn9)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn4 == bn5)
{
if (bn5 == bn6)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn5)
{
if (bn5 == bn7)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn7 == bn8)
{
if (bn8 == bn9)
{
if (bn7 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn7 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
label2.Text = Convert.ToString(win);
}
private void button4_Click(object sender, EventArgs e)
{
if (b4 == 1)
{
charch = charch + 1;
chch = charch % 2;
if (chch == 1)
{
button4.Text = "o";
bn4 = 1;
}
else
{
button4.Text = "x";
bn4 = 2;
}
b4 = 2;
}
if (win == 0)
{
if (bn1 == bn2)
{
if (bn2 == bn3)
{
if (bn1 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn1 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn1 == bn4)
{
if (bn4 == bn7)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn2 == bn5)
{
if (bn5 == bn8)
{
if (bn2 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn2 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn6)
{
if (bn6 == bn9)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn4 == bn5)
{
if (bn5 == bn6)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn5)
{
if (bn5 == bn7)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn7 == bn8)
{
if (bn8 == bn9)
{
if (bn7 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn7 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
label2.Text = Convert.ToString(win);
}
private void button6_Click(object sender, EventArgs e)
{
if (b6 == 1)
{
charch = charch + 1;
chch = charch % 2;
if (chch == 1)
{
button6.Text = "o";
bn6 = 1;
}
else
{
button6.Text = "x";
bn6 = 2;
}
b6 = 2;
}
if (win == 0)
{
if (bn1 == bn2)
{
if (bn2 == bn3)
{
if (bn1 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn1 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn1 == bn4)
{
if (bn4 == bn7)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn2 == bn5)
{
if (bn5 == bn8)
{
if (bn2 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn2 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn6)
{
if (bn6 == bn9)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn4 == bn5)
{
if (bn5 == bn6)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn5)
{
if (bn5 == bn7)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn7 == bn8)
{
if (bn8 == bn9)
{
if (bn7 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn7 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
label2.Text = Convert.ToString(win);
}
private void button5_Click(object sender, EventArgs e)
{
if (b5 == 1)
{
charch = charch + 1;
chch = charch % 2;
if (chch == 1)
{
button5.Text = "o";
bn5 = 1;
}
else
{
button5.Text = "x";
bn5 = 2;
}
b5 = 2;
}
if (win == 0)
{
if (bn1 == bn2)
{
if (bn2 == bn3)
{
if (bn1 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn1 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn1 == bn4)
{
if (bn4 == bn7)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn2 == bn5)
{
if (bn5 == bn8)
{
if (bn2 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn2 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn6)
{
if (bn6 == bn9)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn4 == bn5)
{
if (bn5 == bn6)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn5)
{
if (bn5 == bn7)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn7 == bn8)
{
if (bn8 == bn9)
{
if (bn7 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn7 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
label2.Text = Convert.ToString(win);
}
private void button7_Click(object sender, EventArgs e)
{
if (b7 == 1)
{
charch = charch + 1;
chch = charch % 2;
if (chch == 1)
{
button7.Text = "o";
bn7 = 1;
}
else
{
button7.Text = "x";
bn7 = 2;
}
b7 = 2;
}
if (win == 0)
{
if (bn1 == bn2)
{
if (bn2 == bn3)
{
if (bn1 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn1 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn1 == bn4)
{
if (bn4 == bn7)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn2 == bn5)
{
if (bn5 == bn8)
{
if (bn2 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn2 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn6)
{
if (bn6 == bn9)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn4 == bn5)
{
if (bn5 == bn6)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn5)
{
if (bn5 == bn7)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn7 == bn8)
{
if (bn8 == bn9)
{
if (bn7 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn7 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
label2.Text = Convert.ToString(win);
}
private void button8_Click(object sender, EventArgs e)
{
if (b8 == 1)
{
charch = charch + 1;
chch = charch % 2;
if (chch == 1)
{
button8.Text = "o";
bn8 = 1;
}
else
{
button8.Text = "x";
bn8 = 2;
}
b8 = 2;
}
if (win == 0)
{
if (bn1 == bn2)
{
if (bn2 == bn3)
{
if (bn1 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn1 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn1 == bn4)
{
if (bn4 == bn7)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn2 == bn5)
{
if (bn5 == bn8)
{
if (bn2 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn2 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn6)
{
if (bn6 == bn9)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn4 == bn5)
{
if (bn5 == bn6)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn5)
{
if (bn5 == bn7)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn7 == bn8)
{
if (bn8 == bn9)
{
if (bn7 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn7 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
label2.Text = Convert.ToString(win);
}
private void button9_Click(object sender, EventArgs e)
{
if (b9 == 1)
{
charch = charch + 1;
chch = charch % 2;
if (chch == 1)
{
button9.Text = "o";
bn9 = 1;
}
else
{
button9.Text = "x";
bn9 = 2;
}
b9 = 2;
}
if (win == 0)
{
if (bn1 == bn2)
{
if (bn2 == bn3)
{
if (bn1 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn1 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn1 == bn4)
{
if (bn4 == bn7)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn2 == bn5)
{
if (bn5 == bn8)
{
if (bn2 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn2 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn6)
{
if (bn6 == bn9)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn4 == bn5)
{
if (bn5 == bn6)
{
if (bn4 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn4 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn3 == bn5)
{
if (bn5 == bn7)
{
if (bn3 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn3 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
if (win == 0)
{
if (bn7 == bn8)
{
if (bn8 == bn9)
{
if (bn7 == 1)
{
MessageBox.Show("O win");
win = 1;
}
else if (bn7 == 2)
{
MessageBox.Show("X win");
win = 1;
}
}
}
}
label2.Text = Convert.ToString(win);
}
private void button10_Click(object sender, EventArgs e)
{
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = "";
b1 = 1;
b2 = 2;
b3 = 3;
b4 = 4;
b5 = 5;
b6 = 6;
b7 = 7;
b8 = 8;
b9 = 9;
bn1 = 0;
bn2 = 0;
bn3 = 0;
bn4 = 0;
bn5 = 0;
bn6 = 0;
bn7 = 0;
bn8 = 0;
bn9 = 0;
charch = 0;
win = 0;
}
}
}
沒有留言:
張貼留言