Assig
Assig
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int fnum;
int snum;
char op;
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += '1';
}
}
}
}
namespace Tic_Tac
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string symbol;
int count = 0;
}
count++;
check();
}
}
else
{
button2.Text = symbol;
button2.BackColor = Color.Coral;
symbol = "X";
}
count++;
check();
}
}
else
{
button3.Text = symbol;
button3.BackColor = Color.Coral;
symbol = "X";
}
count++;
check();
}
}
else
{
button6.Text = symbol;
button6.BackColor = Color.Coral;
symbol = "X";
}
count++;
check();
}
}
else
{
button5.Text = symbol;
button5.BackColor = Color.Coral;
symbol = "X";
}
count++;
check();
}
private void button4_Click(object sender, EventArgs e)
{
if (symbol == "X")
{
button4.Text = symbol;
button4.BackColor = Color.PaleGoldenrod;
symbol = "O";
}
else
{
button4.Text = symbol;
button4.BackColor = Color.Coral;
symbol = "X";
}
count++;
check();
}
}
else
{
button9.Text = symbol;
button9.BackColor = Color.Coral;
symbol = "X";
}
count++;
check();
}
}
else
{
button8.Text = symbol;
button8.BackColor = Color.Coral;
symbol = "X";
}
count++;
check();
}
}
else
{
button7.Text = symbol;
button7.BackColor = Color.Coral;
symbol = "X";
}
count++;
check();
}
void check()
{
if (count >= 5)
{
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"&&
button6.Text=="X"&&button9.Text=="X")||
(button2.Text == "X" && button5.Text == "X"
&& button8.Text == "X")||
(button3.Text == "X" && button4.Text == "X"
&& button7.Text == "X")||
(button1.Text == "X" && button5.Text == "X"
&& button7.Text == "X")||
(button3.Text == "X" && button5.Text == "X"
&& button9.Text == "X"))
{
MessageBox.Show("X Won");
}
else 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" && button6.Text ==
"O" && button9.Text == "O") ||
(button2.Text == "O" && button5.Text == "O"
&& button8.Text == "O") ||
(button3.Text == "O" && button4.Text == "O"
&& button7.Text == "O")||
(button1.Text == "O" && button5.Text == "O"
&& button7.Text == "O")||
(button3.Text == "O" && button5.Text == "O"
&& button9.Text == "O"))
{
MessageBox.Show("O Won");
}
}
else
{
if (count == 9)
{
MessageBox.Show("Draw");
}
}
}
}
private void button12_Click(object sender, EventArgs e)
{
button1.Text = "";
button1.BackColor = Color.Gray;
button2.Text = "";
button2.BackColor = Color.Gray;
button3.Text = "";
button3.BackColor = Color.Gray;
button4.Text = "";
button4.BackColor = Color.Gray;
button5.Text = "";
button5.BackColor = Color.Gray;
button6.Text = "";
button6.BackColor = Color.Gray;
button7.Text = "";
button7.BackColor = Color.Gray;
button8.Text = "";
button8.BackColor = Color.Gray;
button9.Text = "";
button9.BackColor = Color.Gray;
count = 0;
}
}
}
}