10899679_921057504580642_1064189089_n10922034_921057507913975_1464011500_n  

 

 

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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
int c = 0;
public Form1()
{
InitializeComponent();

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)
{
int r;
button1.Text = "o";
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button1.Text = "o";
}
else
{
button1.Text = "x";
}
button1.Enabled = false;
judge();
}

private void button2_Click(object sender, EventArgs e)
{
int r;
button2.Text = "o";
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button2.Text = "o";
}
else
{
button2.Text = "x";
}
button2.Enabled = false;
judge();
}

private void button3_Click(object sender, EventArgs e)
{
int r;
button3.Text = "o";
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button3.Text = "o";
}
else
{
button3.Text = "x";
}
button3.Enabled = false;
judge();
}

private void button4_Click(object sender, EventArgs e)
{
int r;
button4.Text = "o";
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button4.Text = "o";
}
else
{
button4.Text = "x";
}
button4.Enabled = false;
judge();
}

private void button5_Click(object sender, EventArgs e)
{
int r;
button5.Text = "o";
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button5.Text = "o";
}
else
{
button5.Text = "x";
}
button5.Enabled = false;
judge();
}

private void button6_Click(object sender, EventArgs e)
{
int r;
button6.Text = "o";
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button6.Text = "o";
}
else
{
button6.Text = "x";
}
button6.Enabled = false;
judge();
}

private void button7_Click(object sender, EventArgs e)
{
int r;
button7.Text = "o";
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button7.Text = "o";
}
else
{
button7.Text = "x";
}
button7.Enabled = false;
judge();
}

private void button8_Click(object sender, EventArgs e)
{
int r;
button8.Text = "o";
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button8.Text = "o";
}
else
{
button8.Text = "x";
}
button8.Enabled = false;
judge();
}

private void button9_Click(object sender, EventArgs e)
{
int r;
button9.Text = "o";
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
button9.Text = "o";
}
else
{
button9.Text = "x";
}
button9.Enabled = false;
judge();
}

public void judge()

{
if (button1.Text == "x" && button2.Text == "x" && button3.Text == "x")
MessageBox.Show("x贏了");
else if (button4.Text == "x" && button5.Text == "x" && button6.Text == "x")
MessageBox.Show("x贏了");
else if(button7.Text == "x" && button8.Text == "x" && button9.Text == "x")
MessageBox.Show("x贏了");
else if(button1.Text == "x" && button4.Text == "x" && button7.Text == "x")
MessageBox.Show("x贏了");
else if (button2.Text == "x" && button5.Text == "x" && button8.Text == "x")
MessageBox.Show("x贏了");
else if (button3.Text == "x" && button6.Text == "x" && button9.Text == "x")
MessageBox.Show("x贏了");
else if (button1.Text == "x" && button5.Text == "x" && button9.Text == "x")
MessageBox.Show("x贏了");
else if (button3.Text == "x" && button5.Text == "x" && button7.Text == "x")
MessageBox.Show("x贏了");
else if (button1.Text == "o" && button2.Text == "o" && button3.Text == "o")
MessageBox.Show("o贏了");
else if (button4.Text == "o" && button5.Text == "o" && button6.Text == "o")
MessageBox.Show("o贏了");
else if (button7.Text == "o" && button8.Text == "o" && button9.Text == "o")
MessageBox.Show("o贏了");
else if (button1.Text == "o" && button4.Text == "o" && button7.Text == "o")
MessageBox.Show("o贏了");
else if (button2.Text == "o" && button5.Text == "o" && button8.Text == "o")
MessageBox.Show("o贏了");
else if (button3.Text == "o" && button6.Text == "o" && button9.Text == "o")
MessageBox.Show("o贏了");
else if (button1.Text == "o" && button5.Text == "o" && button9.Text == "o")
MessageBox.Show("o贏了");
else if (button3.Text == "o" && button5.Text == "o" && button7.Text == "o")
MessageBox.Show("o贏了");

}
}
}

arrow
arrow
    全站熱搜

    mgboy03517 發表在 痞客邦 留言(0) 人氣()