-
Notifications
You must be signed in to change notification settings - Fork 0
/
tictactoegameinstructions.txt
144 lines (98 loc) · 4.59 KB
/
tictactoegameinstructions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
1. Take tablelaoutpanel window form toolbox
2. Take 9 buttons and set in lable layout panel
3. Change the text of button and leave it blank.Change button name b1,b2 upto button 9;
4. Now by pressing control button select all the nine buttons and double click on button 1;
>>Now rename b1 to button_Click
5. Now goto form design window and go to event block and you will see there is a "Click Event"...
>> Now click on it and select the renamed name that is("button_Click");
---------------- The Main Part Is Start Now ----------------
6. Now go in coding part/button_click class....
>> Now create the object for those 9 buttons as following........
// But before that declaring variable is necessary
// So in coding part you can see there is following class is already available
public partial class tictac : form
{
//declare the varibles here....
String a = "O";
int m = 0;
public tictac()
{
InitializeComponent();
}
private void button_Click(object sender, EventArgs e)
{
Button bt = sender as Button
OR
Buttton bt = (Button)sender; // bt is object name
bt.Enbled = false;
bt.BackColor = Color.Green; //Here event is created so while player click on any button it will turn into green color
if(a == "O")
{
bt.Text = "O";
//Now creating possible combinations of tic tac toe game
// such as 123, 456, 789, 147, 258, 369, 159, 357
// These conditions are for "O"
if ((b1.Text == b2.Text && b2.Text == b3.Text && b3.Text != "") ||
(b4.Text == b5.Text && b5.Text == b6.Text && b6.Text != "") ||
(b7.Text == b8.Text && b8.Text == b9.Text && b9.Text != "") ||
(b1.Text == b4.Text && b4.Text == b7.Text && b7.Text != "") ||
(b2.Text == b5.Text && b5.Text == b8.Text && b8.Text != "") ||
(b3.Text == b6.Text && b6.Text == b9.Text && b9.Text != "") ||
(b1.Text == b5.Text && b5.Text == b9.Text && b9.Text != "") ||
(b3.Text == b5.Text && b5.Text == b7.Text && b7.Text != ""))
{
{
Message.Show(("The Winner Is: " + a.ToString()));
}
//Now Making the draw condition incase if all the box were filled
else if(m == 8)
{
Message.Show("Draw!!");
}
a = "X";
//Now Making the same conditons for the "X";
else if(a == "X")
{
bt.Text = "X";
//Making all the possible condtions for the winning of X
if ((b1.Text == b2.Text && b2.Text == b3.Text && b3.Text != "") ||
(b4.Text == b5.Text && b5.Text == b6.Text && b6.Text != "") ||
(b7.Text == b8.Text && b8.Text == b9.Text && b9.Text != "") ||
(b1.Text == b4.Text && b4.Text == b7.Text && b7.Text != "") ||
(b2.Text == b5.Text && b5.Text == b8.Text && b8.Text != "") ||
(b3.Text == b6.Text && b6.Text == b9.Text && b9.Text != "") ||
(b1.Text == b5.Text && b5.Text == b9.Text && b9.Text != "") ||
(b3.Text == b5.Text && b5.Text == b7.Text && b7.Text != ""))
{
MessageBox.Show(("The Winner Is: " + a.ToString()));
}
else if(a == 8)
{
MessageBox.Show("Draw!!");
}
a = "O";
}
m++;
}
// Now Coding for NewGame/(Reset)........
// For These Create a button to reset or new game
// Here the occurance of event is something like this.....
>> if we click on newgame the box must be turn into white box
>> & the box will become blank.. Right....!!
//Double Click on new game/ reset button...
//Change the text of button to new button / reset
{
a = "O";
m = 0;
b1.Text = ""; b1.BackColor = Color.White;
b2.Text = ""; b2.BackColor = Color.White;
b3.Text = ""; b3.BackColor = Color.White;
b4.Text = ""; b4.BackColor = Color.White;
b5.Text = ""; b5.BackColor = Color.White;
b6.Text = ""; b6.BackColor = Color.White;
b7.Text = ""; b7.BackColor = Color.White;
b8.Text = ""; b8.BackColor = Color.White;
b9.Text = ""; b9.BackColor = Color.White;
}
https://github.com/digen21/Tasks.git
https://github.com/digen21/Tasks/blob/a9f3a4d336c2a3f3785f658d6f1f4c0242a24ab8/README.mdno