0% found this document useful (0 votes)
58 views3 pages

How To Make Simple Tic Tac Toe Game in C

This document describes how to create a simple Tic Tac Toe game in C# Windows Forms. The game uses 10 buttons - 9 for the game board and 1 reset button. It alternates displaying "X" and "O" on clicked buttons. After each turn, it checks if any row, column or diagonal matches to determine a winner. If no match after 9 turns, it says no one won. The reset button clears the board and resets the turn counter to start a new game.

Uploaded by

Tom L
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views3 pages

How To Make Simple Tic Tac Toe Game in C

This document describes how to create a simple Tic Tac Toe game in C# Windows Forms. The game uses 10 buttons - 9 for the game board and 1 reset button. It alternates displaying "X" and "O" on clicked buttons. After each turn, it checks if any row, column or diagonal matches to determine a winner. If no match after 9 turns, it says no one won. The reset button clears the board and resets the turn counter to start a new game.

Uploaded by

Tom L
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

How to make Simple Tic Tac Toe Game in C# windows application

This is simple Tic Tac Toe game in C# windows application in which we


use 10 buttons, 9 buttons for game the text of these buttons by default null,
and 1 for Reset.

The code of reset function is:

 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.

  if (i < 9 && button1.Text == "")

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 (button2.Text == text && button3.Text == text)


                {
                    MessageBox.Show("Team " + text + " Won
the Game");
                    reset();
                }
                else if (button4.Text == text &&
button7.Text == text)
                {
                    MessageBox.Show("Team " + text + " Won
the Game");
                    reset();
                }

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

You might also like