好了所有要求都有了
#include
#include
usingnamespacestd;
constintMAX_MOVES=9;
voidprintBoard(charboard[3][3]);
voidgetNextMove(charboard[3][3]);
voidwin(charboard[3][3]);
voidwhowin(charkey);
intfoot=0;
intmain()
{
inti;
intn=0;
charboard[3][3]={'7','8','9','4','5','6','1','2','3'};
printBoard(board);
for(i=0;i<MAX_MOVES;i++)
{
getNextMove(board);
win(board);
n++;
}
if(n=MAX_MOVES)
cout<<gameover;
system(PAUSE);
return0;
}
voidwin(chara[3][3])
{
inti,j,k;
charkey;
if((a[0][0]==a[1][1]&&a[1][1]==a[2][2]&&a[2][2]==a[0][0])||(a[2][0]==a[1][1]&&a[1][1]==a[0][2]&&a[2][0]==a[0][2]))
{
key=a[0][0];
whowin(key);
}
else
{
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(a[i][j]==15||a[i][j]=='X')
{
key=a[i][j];
for(k=0;k<3;k++)
{
if(a[i][k]!=key)
break;
}
if(k==3)
whowin(key);
for(k=0;k<3;k++)
{
if(a[k][j]!=key)
break;
}
if(k==3)
whowin(key);
}
}
}
voidwhowin(charkey)
{
if(key==15)
cout<<P1Win!<<endl;
else
cout<<P2Win!<<endl;
exit(0);
}
voidprintBoard(charboard[3][3])
{
cout<<board[0][0]<<|<<board[0][1]<<|<<board[0][2]<<endl;
cout<<--+---+--<<endl;
cout<<board[1][0]<<|<<board[1][1]<<|<<board[1][2]<<endl;
cout<<--+---+--<<endl;
cout<<board[2][0]<<|<<board[2][1]<<|<<board[2][2]<<endl;
}
voidgetNextMove(charboard[3][3])
{
inti,j,s,t;
charm;
while(1)
{
s=-1;
t=-1;
cout<<Makeyourmove:;
cin>>m;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(board[i][j]==m)
{
s=i;
t=j;
}
if(s==-1&&t==-1)
cout<<thatpointalreadyhasapawn!<<endl;
else
break;
}
if(foot%2==0)
board[s][t]=15;
else
board[s][t]='X';
foot++;
system(cls);
printBoard(board);
}