close

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 WindowsFormsApplication5
{
public partial class Form1 : Form
{

int c = 0;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{
button1.Text = "O";
button1.BackColor = Color.Green;
}
else
{
button1.Text = "X";
button1.BackColor = Color.Red;
}
button1.Enabled = false; winorlose();
}

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 button2_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{
button2.Text = "O";
button2.BackColor = Color.Green;
}
else
{
button2.Text = "X";
button2.BackColor = Color.Red;
}
button2.Enabled = false; winorlose();

}

private void button3_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{
button3.Text = "O";
button3.BackColor = Color.Green;
}
else
{
button3.Text = "X";
button3.BackColor = Color.Red;
}
button3.Enabled = false; winorlose();
}

private void button4_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{
button4.Text = "O";
button4.BackColor = Color.Green;
}
else
{
button4.Text = "X";
button4.BackColor = Color.Red;
}
button4.Enabled = false; winorlose();
}

private void button5_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{
button5.Text = "O";
button5.BackColor = Color.Green;
}
else
{
button5.Text = "X";
button5.BackColor = Color.Red;
}
button5.Enabled = false; winorlose();
}

private void button6_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{
button6.Text = "O";
button6.BackColor = Color.Green;
}
else
{
button6.Text = "X";
button6.BackColor = Color.Red;
}
button6.Enabled = false; winorlose();
}

private void button7_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{
button7.Text = "O";
button7.BackColor = Color.Green;
}
else
{
button7.Text = "X";
button7.BackColor = Color.Red;
}
button7.Enabled = false; winorlose();
}

private void button8_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{
button8.Text = "O";
button8.BackColor = Color.Green;
}
else
{
button8.Text = "X";
button8.BackColor = Color.Red;
}
button8.Enabled = false; winorlose();
}

private void button9_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{
button9.Text = "O";

button9.BackColor = Color.Green;
}
else
{
button9.Text = "X";
button9.BackColor = Color.Red;
}
button9.Enabled = false; winorlose();
}

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 = "";
button1.BackColor = button10.BackColor;
button2.BackColor = button10.BackColor;
button3.BackColor = button10.BackColor;
button4.BackColor = button10.BackColor;
button5.BackColor = button10.BackColor;
button6.BackColor = button10.BackColor;
button7.BackColor = button10.BackColor;
button8.BackColor = button10.BackColor;
button9.BackColor = button10.BackColor;
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
button6.Enabled = true;
button7.Enabled = true;
button8.Enabled = true;
button9.Enabled = true;
}

public void winorlose()
{
if ((button1.Text == "O" && button2.Text == "O" && button3.Text == "O" ||
(button4.Text == "O" && button5.Text == "O" && button6.Text == "O") ||
(button7.Text == "O" && button8.Text == "O" && button9.Text == "O") ||
(button1.Text == "O" && button4.Text == "O" && button7.Text == "O") ||
(button2.Text == "O" && button5.Text == "O" && button8.Text == "O") ||
(button3.Text == "O" && button6.Text == "O" && button9.Text == "O") ||
(button1.Text == "O" && button5.Text == "O" && button9.Text == "O") ||
(button3.Text == "O" && button5.Text == "O" && button7.Text == "O")))
{
MessageBox.Show("user O win!!");
}
else if ((button1.Text == "X" && button2.Text == "X" && button3.Text == "X") ||
(button4.Text == "X" && button5.Text == "X" && button6.Text == "X") ||
(button7.Text == "X" && button8.Text == "X" && button9.Text == "X") ||
(button1.Text == "X" && button4.Text == "X" && button7.Text == "X") ||
(button2.Text == "X" && button5.Text == "X" && button8.Text == "X") ||
(button3.Text == "X" && button6.Text == "X" && button9.Text == "X") ||
(button1.Text == "X" && button5.Text == "X" && button9.Text == "X") ||
(button3.Text == "X" && button5.Text == "X" && button7.Text == "X"))
{
MessageBox.Show("user X win!!");
}
}

}

}未命名  

arrow
arrow
    全站熱搜

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