X & 0 game

Hey guys, i just made this game in C++ for my school project, turned out pretty well. Just want to know if any possible changes can make this better.

#include<iostream.h>
#include<conio.h>
int a[3][3],b[3][3],x=0,y=0,m=0,n=0;

void grid()
{
int i,j=7; // j=7
for(i=36;i<44;i=i+4) //for the grid line1
{
gotoxy(i,j);
cout<<'|';
}
j=j+1; //j=8
for(i=33;i<44;i++) //for the grid line2
{
if(i==36||i==40)
{
gotoxy(i,j);
cout<<'|';
}
else
gotoxy(i,j);
cout<<'-';
}
j=j+1; //j=9;
for(i=36;i<44;i=i+4) //for the grid line3
{
gotoxy(i,j);
cout<<'|';
}
j=j+1; //j=10
for(i=33;i<44;i++) //for the grid line4
{
if(i==36||i==40)
{
gotoxy(i,j);
cout<<'|';
}
else
gotoxy(i,j);
cout<<'-';
}
j=j+1; //j=11
for(i=36;i<44;i=i+4) //for the grid line5
{
gotoxy(i,j);
cout<<'|';
}
}
void guide() //for indicated waypoints
{
int g=0,c,d;
for(d=7;d<12;d=d+2)
for(c=34;c<43;c=c+4)
{
g=g+1;
gotoxy(c,d);
cout<<g;
}
}
void in1()
{
int o;
gotoxy(1,1);
cout<<" Pl.1 enter the pos. of X ranging from 1-9 --> ";
cin>>o;
gotoxy(48,1);
cout<<' ';

if(o>0&&o<4)
{
a[0][o-1]=0;
gotoxy(30+4*o,7);
cout<<'X';
gotoxy(2*o,6);
cout<<'0';
}
else if(o>3&&o<7)
{
a[1][o-4]=0;
gotoxy(30+4*(o-3),9);
cout<<'X';
gotoxy(2*(o-3),7);
cout<<'0';
}
else if(o>6&&o<10)
{
a[2][o-7]=0;
gotoxy(30+4*(o-6),11);
cout<<'X';
gotoxy(2*(o-6),8);
cout<<'0';
}
}
void in2()
{
int o;
gotoxy(1,2);
cout<<" Pl.2 enter the pos. of O ranging from 1-9 --> ";
cin>>o;
gotoxy(48,2);
cout<<' ';

if(o>0&&o<4)
{
b[0][o-1]=0;
gotoxy(30+4*o,7);
cout<<'0';
gotoxy(2*o,11);
cout<<'0';
}
else if(o>3&&o<7)
{
b[1][o-4]=0;
gotoxy(30+4*(o-3),9);
cout<<'0';
gotoxy(2*(o-3),12);
cout<<'0';
}
else if(o>6&&o<10)
{
b[2][o-7]=0;
gotoxy(30+4*(o-6),11);
cout<<'0';
gotoxy(2*(o-6),13);
cout<<'0';
}

}
void main()
{
int i,j,f=0,t=0;
clrscr();
a[0][0]=0;
b[0][0]=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
f=f+1;
a[i][j]=a[i][j]+f;
b[i][j]=b[i][j]+f;
}
gotoxy(1,4);
cout<<" Debug screen";
gotoxy(1,5);
cout<<" a[3][3]"<<endl;
for(i=0;i<3;i++)
{
cout<<' ';
for(j=0;j<3;j++)
cout<<a[i][j]<<' ';
cout<<endl;
}
gotoxy(1,10);
cout<<" b[3][3]"<<endl;
for(i=0;i<3;i++)
{
cout<<' ';
for(j=0;j<3;j++)
cout<<b[i][j]<<' ';
cout<<endl;
}
grid();
guide();
for(i=0;i<10;i++)
{
in1();
t=t+1;
if(t>=9)
break;
x=x+1;
if(x>=3)
{
if(a[0][0]==a[0][1]&&a[0][1]==a[0][2])
{
m=m+1;
break;
}
else if(a[0][0]==a[1][0]&&a[1][0]==a[2][0])
{
m=m+1;
break;
}
else if(a[0][0]==a[1][1]&&a[1][1]==a[2][2])
{
m=m+1;
break;
}
else if(a[0][1]==a[1][1]&&a[1][1]==a[2][1])
{
m=m+1;
break;
}
else if(a[0][2]==a[1][2]&&a[1][2]==a[2][2])
{
m=m+1;
break;
}
else if(a[0][2]==a[1][1]&&a[1][1]==a[2][0])
{
m=m+1;
break;
}
else if(a[1][0]==a[1][1]&&a[1][1]==a[1][2])
{
m=m+1;
break;
}
else if(a[2][0]==a[2][1]&&a[2][1]==a[2][2])
{
m=m+1;
break;
}
}
in2();
t=t+1;
if(t>=9)
break;
y=y+1;
if(y>=3)
{
if(b[0][0]==b[0][1]&&b[0][1]==b[0][2])
{
n=n+1;
break;
}
else if(b[0][0]==b[1][0]&&b[1][0]==b[2][0])
{
n=n+1;
break;
}
else if(b[0][0]==b[1][1]&&b[1][1]==b[2][2])
{
n=n+1;
break;
}
else if(b[0][1]==b[1][1]&&b[1][1]==b[2][1])
{
n=n+1;
break;
}
else if(b[0][2]==b[1][2]&&b[1][2]==b[2][2])
{
n=n+1;
break;
}
else if(b[0][2]==b[1][1]&&b[1][1]==b[2][0])
{
n=n+1;
break;
}
else if(b[1][0]==b[1][1]&&b[1][1]==b[1][2])
{
n=n+1;
break;
}
else if(b[2][0]==b[2][1]&&b[2][1]==b[2][2])
{
n=n+1;
break;
}
}
}
if(m>0)
{
gotoxy(10,7);
cout<<" Player 1 wins";
}
if(n>0)
{
gotoxy(10,7);
cout<<" Player 2 wins";
}
if(m==0&&n==0)
{
gotoxy(10,7);
cout<<" It's a tie";
}
getch();
}
Topic archived. No new replies allowed.