-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource_code.cpp
142 lines (133 loc) · 3.95 KB
/
source_code.cpp
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
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include "source_code.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
char currentPlayerSymbol = 'x';
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Label2->Text = currentPlayerSymbol;
}
//---------------------------------------------------------------------------
bool TForm1::winnerKaun()
{
if(!Button1->Text.IsEmpty() && Button1->Text == Button2->Text && Button1->Text == Button3->Text) return true;
if(!Button4->Text.IsEmpty() && Button4->Text == Button5->Text && Button4->Text == Button6->Text) return true;
if(!Button7->Text.IsEmpty() && Button7->Text == Button8->Text && Button7->Text == Button9->Text) return true;
if(!Button1->Text.IsEmpty() && Button1->Text == Button4->Text && Button1->Text == Button7->Text) return true;
if(!Button2->Text.IsEmpty() && Button2->Text == Button5->Text && Button2->Text == Button8->Text) return true;
if(!Button3->Text.IsEmpty() && Button3->Text == Button6->Text && Button3->Text == Button9->Text) return true;
if(!Button1->Text.IsEmpty() && Button1->Text == Button5->Text && Button1->Text == Button9->Text) return true;
if(!Button3->Text.IsEmpty() && Button3->Text == Button5->Text && Button3->Text == Button7->Text) return true;
return false;
}
void TForm1::changePlayerSymbol()
{
if(currentPlayerSymbol == 'x') currentPlayerSymbol = 'o';
else currentPlayerSymbol = 'x';
Label2->Text = currentPlayerSymbol;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Button1->Text=currentPlayerSymbol;
if(winnerKaun())
{
Label3->Text="You Won!!";
return;
}
changePlayerSymbol();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Button2->Text=currentPlayerSymbol;
if(winnerKaun())
{
Label3->Text="You Won!!";
return;
}
changePlayerSymbol();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Button3->Text=currentPlayerSymbol;
if(winnerKaun())
{
Label3->Text="You Won!!";
return;
}
changePlayerSymbol();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Button4->Text=currentPlayerSymbol;
if(winnerKaun())
{
Label3->Text="You Won!!";
return;
}
changePlayerSymbol();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
Button5->Text=currentPlayerSymbol;
if(winnerKaun())
{
Label3->Text="You Won!!";
return;
}
changePlayerSymbol();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
Button6->Text=currentPlayerSymbol;
if(winnerKaun())
{
Label3->Text="You Won!!";
return;
}
changePlayerSymbol();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
Button7->Text=currentPlayerSymbol;
if(winnerKaun())
{
Label3->Text="You Won!!";
return;
}
changePlayerSymbol();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button8Click(TObject *Sender)
{
Button8->Text=currentPlayerSymbol;
if(winnerKaun())
{
Label3->Text="You Won!!";
return;
}
changePlayerSymbol();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject *Sender)
{
Button9->Text=currentPlayerSymbol;
if(winnerKaun())
{
Label3->Text="You Won!!";
return;
}
changePlayerSymbol();
}
//---------------------------------------------------------------------------