Professional Documents
Culture Documents
public void reset()
{
button1.Text = button2.Text =
button3.Text = button4.Text =
button5.Text = button6.Text =
button7.Text = button8.Text =
button9.Text = "";
i = 0;
}
When we click on any button program first check the 2 conditions first the
text of button is null and the how many times buttons are clicked.
Then check the value of (i) if the value of (i) is even then button text
change into (X) else (O) and increase the value of (i).
if (i % 2 == 0)
button1.Text = "X";
else
button1.Text = "O";
i++;
Then check the text of buttons in row, column or diagonal if the text of row,
column or diagonal match then the text of team won the game and call the
reset function.
If the value of i=9 and text of any row, column or diagonal is not same then
program display the message no one won the game.
else if (i == 9)
{
MessageBox.Show("No one Won the Game");
reset();
}
Like this we code for all 9 buttons and enjoy the game.
Screen Shot