Welcome to mydotnetwebapp.blogspot.in. In this session , I am gonna tell you about creating a simple Tic-Tac-Toe game using c# programming language .
|
Tic-Tac-Toe |
Click here to download [tic-tac-toe]
1) Basic Requirements :
1)Two panels
2)Three Labels :1 label for blinking purpose(Include).
3)Two Text boxes
4)10 Buttons : (9 simple , 1 play).
|
Requirements |
2) Logic And Coding :
1) take a counter(Initial value of counter = 1) that can increase after every button click.
2) We are developing the game for two players so , A) First player B) Second Player
3) For 'A' (First Player)
i) 'A' Starts the game So , When 'A'(first player) clicks on the button then the background color of that button is automatically changes to 'BLUE'.
ii) This is possible because : (if counter = 1 , 3 , 5 , 7 , 9 , then assign button's background to 'BLUE'.)
iii) At every turn blocks(Buttons) are turned into 'BLUE' .
iV) counter values will be 1 , 3 , 5 , 7 ,9 .
4) 3) For 'B' (Second Player)
i) 'B' Starts the game after "A's " turn So , When 'B'(Second player) clicks on the button then the background color of that button is automatically changes to 'RED'.
ii) This is possible because : (if counter = 2 , 4 , 6 , 8 then assign button's background to 'RED'.)
iii) At every turn blocks(Buttons) are turned into 'RED' .
iv) counter values will be 2 , 4 , 6 , 8 .
5) counter table
counter value turn
1 A (first player) ---- BLUE
2 B (Second player) --- RED
3 A (first player) ---- BLUE
4 B (Second player) --- RED
.
.
.
So on...
6) Checking the Condition ...
if the buttons which are in sequence ( 1 , 2 , 3) || ( 1 , 4 , 7) || ( 1 , 5 , 9) || ( 2 , 5 , 8) || ( 3 , 6 , 9) || ( 3 , 5 , 7) || ( 4 , 5 , 6) || ( 7 , 8 , 9)
are all 'BLUE' Or all 'RED' then Particular player will declare as a winner.
step 1 : Just Drag and Drop the Labels And Text-Boxes.
step 2 : Put 9 buttons in one panel (called Panel2) and arrange them in following way .
|
Buttons Arrangement |
step 3 : At the time of Form_load
private void Form1_Load_1(object sender, EventArgs e)
{
panel2.Visible = false;
/*panel2 is not visible until you specify the term, like panel2.visible = true */
}
step 4 : Write Code for each Event generated by button_click.
public string s1, s2, s3, s4, s5, s6, s7, s8, s9;
/*all these string variables store the name of button's Background color.*/
public int count = 1
private void button1_Click(object sender, EventArgs e)
{
/* if counter == 1 , means first click (1st player) , counter = 2 , means second click (second Player) ...*/
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9)
{
/* if counter = 1,3,5,7,9 means all the clicks done by first player */
button1.BackColor = Color.Blue;
/*Assign the " BLUE " color for First player */
s1 = button1.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Blue") && String.Equals(s2, "Blue") && String.Equals(s3, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s5, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s4, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s2, "Blue") && String.Equals(s5, "Blue") && String.Equals(s8, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s6, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s5, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s4, "Blue") && String.Equals(s5, "Blue") && String.Equals(s6, "Blue")) || (String.Equals(s7, "Blue") && String.Equals(s8, "Blue") && String.Equals(s9, "Blue")))
{
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee){}
}
if (count == 2 || count == 4 || count == 6 || count == 8)
{
/ *if counter = 2,4,6,8 means all the clicks done by Second Player */
/*Assign " Red " for second player */
button1.BackColor = Color.Red;
s1 = button1.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Red") && String.Equals(s2, "Red") && String.Equals(s3, "Red")) || (String.Equals(s1, "Red") && String.Equals(s5, "Red") && String.Equals(s9, "Red")) || (String.Equals(s1, "Red") && String.Equals(s4, "Red") && String.Equals(s7, "Red")) || (String.Equals(s2, "Red") && String.Equals(s5, "Red") && String.Equals(s8, "Red")) || (String.Equals(s3, "Red") && String.Equals(s6, "Red") && String.Equals(s9, "Red")) || (String.Equals(s3, "Red") && String.Equals(s5, "Red") && String.Equals(s7, "Red")) || (String.Equals(s4, "Red") && String.Equals(s5, "Red") && String.Equals(s6, "Red")) || (String.Equals(s7, "Red") && String.Equals(s8, "Red") && String.Equals(s9, "Red")))
{
/*label4 is present at the bottom of application layout (UI) */
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee){}
}
count++;
}
Do the same coding for Every Button_click.
private void button2_Click(object sender, EventArgs e)
{
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9)
{
button2.BackColor = Color.Blue;
s2 = button2.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Blue") && String.Equals(s2, "Blue") && String.Equals(s3, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s5, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s4, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s2, "Blue") && String.Equals(s5, "Blue") && String.Equals(s8, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s6, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s5, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s4, "Blue") && String.Equals(s5, "Blue") && String.Equals(s6, "Blue")) || (String.Equals(s7, "Blue") && String.Equals(s8, "Blue") && String.Equals(s9, "Blue")))
{
label4.Visible = true;
label4.Text = textBox1.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
if (count == 2 || count == 4 || count == 6 || count == 8)
{
button2.BackColor = Color.Red;
s2 = button2.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Red") && String.Equals(s2, "Red") && String.Equals(s3, "Red")) || (String.Equals(s1, "Red") && String.Equals(s5, "Red") && String.Equals(s9, "Red")) || (String.Equals(s1, "Red") && String.Equals(s4, "Red") && String.Equals(s7, "Red")) || (String.Equals(s2, "Red") && String.Equals(s5, "Red") && String.Equals(s8, "Red")) || (String.Equals(s3, "Red") && String.Equals(s6, "Red") && String.Equals(s9, "Red")) || (String.Equals(s3, "Red") && String.Equals(s5, "Red") && String.Equals(s7, "Red")) || (String.Equals(s4, "Red") && String.Equals(s5, "Red") && String.Equals(s6, "Red")) || (String.Equals(s7, "Red") && String.Equals(s8, "Red") && String.Equals(s9, "Red")))
{
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
count++;
}
private void button3_Click(object sender, EventArgs e)
{
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9)
{
button3.BackColor = Color.Blue;
s3 = button3.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Blue") && String.Equals(s2, "Blue") && String.Equals(s3, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s5, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s4, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s2, "Blue") && String.Equals(s5, "Blue") && String.Equals(s8, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s6, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s5, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s4, "Blue") && String.Equals(s5, "Blue") && String.Equals(s6, "Blue")) || (String.Equals(s7, "Blue") && String.Equals(s8, "Blue") && String.Equals(s9, "Blue")))
{
label4.Visible = true;
label4.Text = textBox1.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
if (count == 2 || count == 4 || count == 6 || count == 8)
{
button3.BackColor = Color.Red;
s3 = button3.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Red") && String.Equals(s2, "Red") && String.Equals(s3, "Red")) || (String.Equals(s1, "Red") && String.Equals(s5, "Red") && String.Equals(s9, "Red")) || (String.Equals(s1, "Red") && String.Equals(s4, "Red") && String.Equals(s7, "Red")) || (String.Equals(s2, "Red") && String.Equals(s5, "Red") && String.Equals(s8, "Red")) || (String.Equals(s3, "Red") && String.Equals(s6, "Red") && String.Equals(s9, "Red")) || (String.Equals(s3, "Red") && String.Equals(s5, "Red") && String.Equals(s7, "Red")) || (String.Equals(s4, "Red") && String.Equals(s5, "Red") && String.Equals(s6, "Red")) || (String.Equals(s7, "Red") && String.Equals(s8, "Red") && String.Equals(s9, "Red")))
{
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
count++;
}
private void button4_Click(object sender, EventArgs e)
{
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9)
{
button4.BackColor = Color.Blue;
s4 = button4.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Blue") && String.Equals(s2, "Blue") && String.Equals(s3, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s5, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s4, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s2, "Blue") && String.Equals(s5, "Blue") && String.Equals(s8, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s6, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s5, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s4, "Blue") && String.Equals(s5, "Blue") && String.Equals(s6, "Blue")) || (String.Equals(s7, "Blue") && String.Equals(s8, "Blue") && String.Equals(s9, "Blue")))
{
label4.Visible = true;
label4.Text = textBox1.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
if (count == 2 || count == 4 || count == 6 || count == 8)
{
button4.BackColor = Color.Red;
s4 = button4.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Red") && String.Equals(s2, "Red") && String.Equals(s3, "Red")) || (String.Equals(s1, "Red") && String.Equals(s5, "Red") && String.Equals(s9, "Red")) || (String.Equals(s1, "Red") && String.Equals(s4, "Red") && String.Equals(s7, "Red")) || (String.Equals(s2, "Red") && String.Equals(s5, "Red") && String.Equals(s8, "Red")) || (String.Equals(s3, "Red") && String.Equals(s6, "Red") && String.Equals(s9, "Red")) || (String.Equals(s3, "Red") && String.Equals(s5, "Red") && String.Equals(s7, "Red")) || (String.Equals(s4, "Red") && String.Equals(s5, "Red") && String.Equals(s6, "Red")) || (String.Equals(s7, "Red") && String.Equals(s8, "Red") && String.Equals(s9, "Red")))
{
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
count++;
}
private void button5_Click(object sender, EventArgs e)
{
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9)
{
button5.BackColor = Color.Blue;
s5 = button5.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Blue") && String.Equals(s2, "Blue") && String.Equals(s3, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s5, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s4, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s2, "Blue") && String.Equals(s5, "Blue") && String.Equals(s8, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s6, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s5, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s4, "Blue") && String.Equals(s5, "Blue") && String.Equals(s6, "Blue")) || (String.Equals(s7, "Blue") && String.Equals(s8, "Blue") && String.Equals(s9, "Blue")))
{
//if(s1 == "Blue")
label4.Visible = true;
label4.Text = textBox1.Text + " Won";
panel2.Enabled = false;
}
//else
// label3.Text = "No Result";
}
catch (Exception ee)
{
}
}
if (count == 2 || count == 4 || count == 6 || count == 8)
{
button5.BackColor = Color.Red;
s5 = button5.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Red") && String.Equals(s2, "Red") && String.Equals(s3, "Red")) || (String.Equals(s1, "Red") && String.Equals(s5, "Red") && String.Equals(s9, "Red")) || (String.Equals(s1, "Red") && String.Equals(s4, "Red") && String.Equals(s7, "Red")) || (String.Equals(s2, "Red") && String.Equals(s5, "Red") && String.Equals(s8, "Red")) || (String.Equals(s3, "Red") && String.Equals(s6, "Red") && String.Equals(s9, "Red")) || (String.Equals(s3, "Red") && String.Equals(s5, "Red") && String.Equals(s7, "Red")) || (String.Equals(s4, "Red") && String.Equals(s5, "Red") && String.Equals(s6, "Red")) || (String.Equals(s7, "Red") && String.Equals(s8, "Red") && String.Equals(s9, "Red")))
{
//if(s1 == "Blue")
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
//else
// label3.Text = "No Result";
}
catch (Exception ee)
{
}
}
count++;
}
private void button6_Click(object sender, EventArgs e)
{
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9)
{
button6.BackColor = Color.Blue;
s6 = button6.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Blue") && String.Equals(s2, "Blue") && String.Equals(s3, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s5, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s4, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s2, "Blue") && String.Equals(s5, "Blue") && String.Equals(s8, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s6, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s5, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s4, "Blue") && String.Equals(s5, "Blue") && String.Equals(s6, "Blue")) || (String.Equals(s7, "Blue") && String.Equals(s8, "Blue") && String.Equals(s9, "Blue")))
{
label4.Visible = true;
label4.Text = textBox1.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
if (count == 2 || count == 4 || count == 6 || count == 8)
{
button6.BackColor = Color.Red;
s6 = button6.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Red") && String.Equals(s2, "Red") && String.Equals(s3, "Red")) || (String.Equals(s1, "Red") && String.Equals(s5, "Red") && String.Equals(s9, "Red")) || (String.Equals(s1, "Red") && String.Equals(s4, "Red") && String.Equals(s7, "Red")) || (String.Equals(s2, "Red") && String.Equals(s5, "Red") && String.Equals(s8, "Red")) || (String.Equals(s3, "Red") && String.Equals(s6, "Red") && String.Equals(s9, "Red")) || (String.Equals(s3, "Red") && String.Equals(s5, "Red") && String.Equals(s7, "Red")) || (String.Equals(s4, "Red") && String.Equals(s5, "Red") && String.Equals(s6, "Red")) || (String.Equals(s7, "Red") && String.Equals(s8, "Red") && String.Equals(s9, "Red")))
{
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
count++;
}
private void button7_Click(object sender, EventArgs e)
{
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9)
{
button7.BackColor = Color.Blue;
s7 = button7.BackColor.Name.ToString();
try
{
if ((String.Equals(s1,"Blue") && String.Equals(s2,"Blue") && String.Equals(s3, "Blue")) || (String.Equals(s1,"Blue") && String.Equals(s5,"Blue") && String.Equals(s9, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s4, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s2, "Blue") && String.Equals(s5, "Blue") && String.Equals(s8, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s6, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s5, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s4, "Blue") && String.Equals(s5, "Blue") && String.Equals(s6, "Blue")) || (String.Equals(s7, "Blue") && String.Equals(s8, "Blue") && String.Equals(s9, "Blue")))
{
label4.Visible = true;
label4.Text = textBox1.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
if (count == 2 || count == 4 || count == 6 || count == 8)
{
button7.BackColor = Color.Red;
s7 = button7.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Red") && String.Equals(s2, "Red") && String.Equals(s3, "Red")) || (String.Equals(s1, "Red") && String.Equals(s5, "Red") && String.Equals(s9, "Red")) || (String.Equals(s1, "Red") && String.Equals(s4, "Red") && String.Equals(s7, "Red")) || (String.Equals(s2, "Red") && String.Equals(s5, "Red") && String.Equals(s8, "Red")) || (String.Equals(s3, "Red") && String.Equals(s6, "Red") && String.Equals(s9, "Red")) || (String.Equals(s3, "Red") && String.Equals(s5, "Red") && String.Equals(s7, "Red")) || (String.Equals(s4, "Red") && String.Equals(s5, "Red") && String.Equals(s6, "Red")) || (String.Equals(s7, "Red") && String.Equals(s8, "Red") && String.Equals(s9, "Red")))
{
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
count++;
}
private void button8_Click(object sender, EventArgs e)
{
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9)
{
button8.BackColor = Color.Blue;
s8 = button8.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Blue") && String.Equals(s2, "Blue") && String.Equals(s3, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s5, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s4, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s2, "Blue") && String.Equals(s5, "Blue") && String.Equals(s8, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s6, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s5, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s4, "Blue") && String.Equals(s5, "Blue") && String.Equals(s6, "Blue")) || (String.Equals(s7, "Blue") && String.Equals(s8, "Blue") && String.Equals(s9, "Blue")))
{
label4.Visible = true;
label4.Text = textBox1.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
if (count == 2 || count == 4 || count == 6 || count == 8)
{
button8.BackColor = Color.Red;
s8 = button8.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Red") && String.Equals(s2, "Red") && String.Equals(s3, "Red")) || (String.Equals(s1, "Red") && String.Equals(s5, "Red") && String.Equals(s9, "Red")) || (String.Equals(s1, "Red") && String.Equals(s4, "Red") && String.Equals(s7, "Red")) || (String.Equals(s2, "Red") && String.Equals(s5, "Red") && String.Equals(s8, "Red")) || (String.Equals(s3, "Red") && String.Equals(s6, "Red") && String.Equals(s9, "Red")) || (String.Equals(s3, "Red") && String.Equals(s5, "Red") && String.Equals(s7, "Red")) || (String.Equals(s4, "Red") && String.Equals(s5, "Red") && String.Equals(s6, "Red")) || (String.Equals(s7, "Red") && String.Equals(s8, "Red") && String.Equals(s9, "Red")))
{
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
count++;
}
private void button9_Click(object sender, EventArgs e)
{
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9)
{
button9.BackColor = Color.Blue;
s9 = button9.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Blue") && String.Equals(s2, "Blue") && String.Equals(s3, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s5, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s1, "Blue") && String.Equals(s4, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s2, "Blue") && String.Equals(s5, "Blue") && String.Equals(s8, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s6, "Blue") && String.Equals(s9, "Blue")) || (String.Equals(s3, "Blue") && String.Equals(s5, "Blue") && String.Equals(s7, "Blue")) || (String.Equals(s4, "Blue") && String.Equals(s5, "Blue") && String.Equals(s6, "Blue")) || (String.Equals(s7, "Blue") && String.Equals(s8, "Blue") && String.Equals(s9, "Blue")))
{
label4.Visible = true;
label4.Text = textBox1.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
if (count == 2 || count == 4 || count == 6 || count == 8)
{
button9.BackColor = Color.Red;
s9 = button9.BackColor.Name.ToString();
try
{
if ((String.Equals(s1, "Red") && String.Equals(s2, "Red") && String.Equals(s3, "Red")) || (String.Equals(s1, "Red") && String.Equals(s5, "Red") && String.Equals(s9, "Red")) || (String.Equals(s1, "Red") && String.Equals(s4, "Red") && String.Equals(s7, "Red")) || (String.Equals(s2, "Red") && String.Equals(s5, "Red") && String.Equals(s8, "Red")) || (String.Equals(s3, "Red") && String.Equals(s6, "Red") && String.Equals(s9, "Red")) || (String.Equals(s3, "Red") && String.Equals(s5, "Red") && String.Equals(s7, "Red")) || (String.Equals(s4, "Red") && String.Equals(s5, "Red") && String.Equals(s6, "Red")) || (String.Equals(s7, "Red") && String.Equals(s8, "Red") && String.Equals(s9, "Red")))
{
label4.Visible = true;
label4.Text = textBox2.Text + " Won";
panel2.Enabled = false;
}
}
catch (Exception ee)
{
}
}
count++;
}
step 5 :
|
Tic-Tac-Toe : Step 1 |
|
Tic-Tac-Toe : Step 2 |
|
Tic-Tac-Toe : Step 3 |
* Coding for the event generated by Button 10 Click
public int major = 0;
private void button10_Click(object sender, EventArgs e)
{
++major;
/*For first time button click : - it checks the condition whether the text boxes are empty or not. */
if (major == 1)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("Enter Player Name");
}
else
{
panel2.Visible = true;
}
}
else
{
/* but for second time its assume the request is as to start the game again. */
/* so , for second time - all the buttons will turn into white. */
panel2.Enabled = true;
count = 0;
label4.Visible = false;
button1.BackColor = Color.White;
button2.BackColor = Color.White;
button3.BackColor = Color.White;
button4.BackColor = Color.White;
button5.BackColor = Color.White;
button6.BackColor = Color.White;
button7.BackColor = Color.White;
button8.BackColor = Color.White;
button9.BackColor = Color.White;
s1 = "";
s2 = "";
s3 = "";
s4 = "";
s5 = "";
s6 = "";
s7 = "";
s8 = "";
s9 = "";
}