Posted by MindBreaker at 8:59 AM
Read our previous post
//Tic Tac Toe GAME
//Submitted By CodingTalks
//Password : password
#
include
#
include
#
include
#
include
char square[
10
] = {
'o'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
};
int
checkwin();
//FUNTION FOR RESULT//
void
board();
//FUNCTION TO DRAW THE BOARD//
void
guide();
//FUNCTION FOR USER GUIDE//
main()
{
clrscr();
if
(-
999
)
{
char ch[
20
],sank;
int
j=
0
,o=
0
;
char a,c,b,d;
cout< sam:
ch[j]=getch();
cout<<
"*"
;
j++;
if
(j<
8
)
{goto sam;}
else
{}
if
(ch[
0
]==
'p'
&&ch[
1
]==
'a'
&&ch[
2
]==
's'
&&ch[
3
]==
's'
&&ch[
4
]==
'w'
&&ch[
5
]==
'o'
&&ch[
6
]==
'r'
&&ch[
7
]==
'd'
)
{
cout<
}
else
{
cout< o++;
j=
0
;
if
(o=
4
)
{cout<
return
-
999
;
}
}
int
player =
1
,i,choice,option;
char mark,choice1;
clrscr();
do
{ clrscr();
cout<>option;
switch
(option)
{
case
1
:
do
{
board();
player=(player%
2
)?
1
:
2
;
cout <<
"Player "
<< player <<
", enter a number: "
; cin >> choice;
mark=(player ==
1
) ?
'X'
:
'O'
;
if
(choice ==
1
&& square[
1
] ==
'1'
)
square[
1
] = mark;
else
if
(choice ==
2
&& square[
2
] ==
'2'
)
square[
2
] = mark;
else
if
(choice ==
3
&& square[
3
] ==
'3'
)
square[
3
] = mark;
else
if
(choice ==
4
&& square[
4
] ==
'4'
)
square[
4
] = mark;
else
if
(choice ==
5
&& square[
5
] ==
'5'
)
square[
5
] = mark;
else
if
(choice ==
6
&& square[
6
] ==
'6'
)
square[
6
] = mark;
else
if
(choice ==
7
&& square[
7
] ==
'7'
)
square[
7
] = mark;
else
if
(choice ==
8
&& square[
8
] ==
'8'
)
square[
8
] = mark;
else
if
(choice ==
9
&& square[
9
] ==
'9'
)
square[
9
] = mark;
else
{
cout< player--;
getch();
}
i=checkwin();
player++;
}
while
(i==-
1
);
board();
if
(i==
1
)
cout<aPlayer "<<--player<
else
cout<aGame draw";
break
;
case
2
:guide();
break
;
case
3
:exit(
0
);
break
;
default
:cout< }
cout<>choice1;
}
while
(choice1==
'y'
||choice1==
'Y'
);
getch();
return
0
;
}
int
checkwin()
{
if
(square[
1
] == square[
2
] && square[
2
] == square[
3
])
return
1
;
else
if
(square[
4
] == square[
5
] && square[
5
] == square[
6
])
return
1
;
else
if
(square[
7
] == square[
8
] && square[
8
] == square[
9
])
return
1
;
else
if
(square[
1
] == square[
4
] && square[
4
] == square[
7
])
return
1
;
else
if
(square[
2
] == square[
5
] && square[
5
] == square[
8
])
return
1
;
else
if
(square[
3
] == square[
6
] && square[
6
] == square[
9
])
return
1
;
else
if
(square[
1
] == square[
5
] && square[
5
] == square[
9
])
return
1
;
else
if
(square[
3
] == square[
5
] && square[
5
] == square[
7
])
return
1
;
else
if
(square[
1
] !=
'1'
&& square[
2
] !=
'2'
&& square[
3
] !=
'3'
&& square[
4
] !=
'4'
&& square[
5
] !=
'5'
&& square[
6
] !=
'6'
&& square[
7
] !=
'7'
&& square[
8
] !=
'8'
&& square[
9
] !=
'9'
)
return
0
;
else
return
-
1
;
}
void
board()
{
clrscr();
cout <<
"nntTic Tac Toenn"
;
cout <<
"Player 1 (X) - Player 2 (O)"
<< endl << endl;
cout << endl;
cout <<
"tt | | "
<< endl;
cout <<
"tt "
<< square[
1
] <<
" | "
<< square[
2
] <<
" | "
<< square[
3
] << endl;
cout <<
"tt_____|_____|_____"
<< endl;
cout <<
"tt | | "
<< endl;
cout <<
"tt "
<< square[
4
] <<
" | "
<< square[
5
] <<
" | "
<< square[
6
] << endl;
cout <<
"tt_____|_____|_____"
<< endl;
cout <<
"tt | | "
<< endl;
cout <<
"tt "
<< square[
7
] <<
" | "
<< square[
8
] <<
" | "
<< square[
9
] << endl;
cout <<
"tt | | "
<< endl << endl;
}
void
guide()
{
clrscr();
cout<
"_|_|_ "
<<endl<cout<cout<cout<
"ttttttttt -|-|-"
<<
"ttttttttt _|_|_"
<<
"ttttttttt | | "
;
cout<<endl<<endl<
"ttttttt -|x|_ "
<<
"tttttttt -|-|x"
;
cout<<endl<<endl<
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.