borland c++ :-tic tac toe game

hi tried to make tic tac toe
check this out


BORLAND C++ not other

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
#include<process.h>
#include<iostream.h>
#include<conio.h>

char box[3][3]={{'1','2','3'},{'4','5','6'},{'7','8','9'}};
int i=0,j=0,p,r,win=0,bno;
void interface()
{
 clrscr();
  cout<<"\n\n\t\t\t TIC TAC TOE [CROSS N\' KNOTS]";
  cout<<"\n\t\t\t-----------------------------";
 cout<<"\n\n\t\t\tPLAYER 1 [O]        PLAYER 2 [X]\n\n";

 cout<<"\t\t\t            |      |    "<<endl;
 cout<<"\t\t\t        "<<box[0][0]<<"   |  "<<box[0][1]<<"   |  "<<box[0][2]<<"  "<<endl;
 cout<<"\t\t\t      ______|______|______"<<endl;
 cout<<"\t\t\t            |      |    "<<endl;
 cout<<"\t\t\t        "<<box[1][0]<<"   |  "<<box[1][1]<<"   |  "<<box[1][2]<<"  "<<endl;
 cout<<"\t\t\t      ______|______|______"<<endl;
 cout<<"\t\t\t            |      |"<<endl;
 cout<<"\t\t\t        "<<box[2][0]<<"   |  "<<box[2][1]<<"   |  "<<box[2][2]<<"  "<<endl;
 cout<<"\t\t\t            |      |"<<endl;
}

main()
{
begin:
win=0;
for(p=0;p<9;p++)
{bno=0;i=0;j=0;
 interface();
 if(p%2==0)
 cout<<"\n\n\nPLAYER 1  [O]\n";
 else
 cout<<"\n\n\nPLAYER 2  [X]\n";
 cout<<"\nEnter a box number : ";
 input:
 cin>>bno;

switch(bno)
{
 case 1:i=0;j=0;break;
 case 2:i=0;j=1;break;
 case 3:i=0;j=2;break;
 case 4:i=1;j=0;break;
 case 5:i=1;j=1;break;
 case 6:i=1;j=2;break;
 case 7:i=2;j=0;break;
 case 8:i=2;j=1;break;
 case 9:i=2;j=2;break;
 default:cout<<"\nINVALID MOVE !\n\nEnter a box number : ";
			goto input;
}
if(box[i][j]=='X'||box[i][j]=='O')
{
 cout<<"\nINVALID MOVE !\n\nEnter a box number : ";
 goto input;
}
else
{
 if(p%2==0)
 box[i][j]='O';

 else
 box[i][j]='X';
}
//********|*************************************|*****************************
//        |              CHECK POSITION         |
//********|*************************************|*****************************

switch(bno)
{
 case 1:     if(box[0][0]==box[0][1]&&box[0][1]==box[0][2])
				 win=5;
			if(box[0][0]==box[1][1]&&box[1][1]==box[2][2])
				 win=5;
			  if(box[0][0]==box[1][0]&&box[1][0]==box[2][0])
				 win=5;break;
 case 2:     if(box[0][1]==box[1][1]&&box[1][1]==box[2][1])
				 win=5;
			  if(box[0][0]==box[0][1]&&box[0][1]==box[0][2])
				 win=5;break;
 case 3:     if(box[0][2]==box[1][2]&&box[1][2]==box[2][2])
				 win=5;
			if(box[0][2]==box[1][1]&&box[1][1]==box[2][0])
				 win=5;
			  if(box[0][0]==box[0][1]&&box[0][1]==box[0][2])
				 win=5;break;
 case 4:     if(box[0][0]==box[1][0]&&box[1][0]==box[2][0])
				 win=5;
			  if(box[1][0]==box[1][1]&&box[1][1]==box[1][2])
				 win=5;break;
 case 5:     if(box[1][0]==box[1][1]&&box[1][1]==box[1][2])
					win=5;
			if(box[0][1]==box[1][1]&&box[1][1]==box[2][1])
					win=5;
			if(box[0][2]==box[1][1]&&box[1][1]==box[2][0])
					win=5;
			  if(box[0][0]==box[1][1]&&box[1][1]==box[2][2])
					win=5; break;
 case 6:     if(box[1][2]==box[1][1]&&box[1][1]==box[1][0])
				 win=5;
			  if(box[0][2]==box[1][2]&&box[1][2]==box[2][2])
				 win=5;break;
 case 7:     if(box[0][0]==box[1][0]&&box[1][0]==box[2][0])
				 win=5;
			if(box[2][0]==box[2][1]&&box[2][1]==box[2][2])
				 win=5;
			  if(box[2][0]==box[1][1]&&box[1][1]==box[0][2])
				 win=5;break;
 case 8:     if(box[0][1]==box[1][1]&&box[1][1]==box[2][1])
				 win=5;
			  if(box[2][0]==box[2][1]&&box[2][1]==box[2][2])
				 win=5;break;
 case 9:     if(box[2][0]==box[2][1]&&box[2][1]==box[2][2])
				 win=5;
			if(box[0][0]==box[1][1]&&box[1][1]==box[2][2])
				 win=5;
				if(box[0][2]==box[1][2]&&box[1][2]==box[2][2])
				 win=5;break;
				 }
if(win==5)
{if(p%2==0)
 {r=1;goto end;}
 else
 {r=2;goto end;}}}
end:
/***********************************************************************
									RESULT : GAME
***********************************************************************/
 interface();

 if(r==1)
 cout<<"\n\nPLAYER 1 [O] WON THE GAME";

 else if(r==2)
  {cout<<"\n\nPLAYER 2 [X] WON THE GAME";}

 else
 {cout<<"\n\nGAME TIED ";}
 return 0;}
Topic archived. No new replies allowed.