该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
nFirstPlayer++;
break;
}
else if(achBoard[2][0]=='O'&&achBoard[2][1]=='O'&&achBoard[2][2]=='O')
{
printf("O Player wins the game\n");
nFirstPlayer++;
break;
}
else if(nSpotsOnBoard==9)
{
printf("Draw!\n");
nDraws++;
break;
}
PromptTurnX_f(&nX,&nY);
IfError_f(&nX,&nY);
achBoard[nX-1][nY-1]='X';
nSpotsOnBoard++;
PrintBoard_f();
if(achBoard[0][0]=='X'&&achBoard[1][1]=='X'&&achBoard[0][2]=='X')
{
printf("X Player wins the game\n");
nSecondPlayer++;
break;
}
else if(achBoard[2][0]=='X'&&achBoard[1][1]=='X'&&achBoard[0][2]=='X')
{
printf("X Player wins the game\n");
nSecondPlayer++;
break;
}
else if(achBoard[0][0]=='X'&&achBoard[1][0]=='X'&&achBoard[2][0]=='X')
{
printf("X Player wins the game\n");
nSecondPlayer++;
break;
}
else if(achBoard[0][1]=='X'&&achBoard[1][1]=='X'&&achBoard[2][1]=='X')
{
printf("X Player wins the game\n");
nSecondPlayer++;
break;
}
else if(achBoard[0][2]=='X'&&achBoard[1][2]=='X'&&achBoard[2][2]=='X')
{
printf("X Player wins the game\n");
nSecondPlayer++;
break;
}
else if(achBoard[0][0]=='X'&&achBoard[0][1]=='X'&&achBoard[0][2]=='X')
{
printf("X Player wins the game\n");
nSecondPlayer++;
break;
}
else if(achBoard[1][0]=='X'&&achBoard[1][1]=='X'&&achBoard[1][2]=='X')
{
printf("X Player wins the game\n");
nSecondPlayer++;
break;
}
else if(achBoard[2][0]=='X'&&achBoard[2][1]=='X'&&achBoard[2][2]=='X')
{
printf("X Player wins the game\n");
nSecondPlayer++;
break;
}
}
ChoiceOfChar_f(&chChoice);
}
PrintResult_f(nFirstPlayer,nSecondPlayer,nDraws);
system("PAUSE");
return 0;
}
void PrintBoard_f()
{
printf("\n");
printf(" 1 2 3\n");
printf(" %c |%c |%c\n",achBoard[0][0],achBoard[0][1],achBoard[0][2]);
printf("1--|--|--\n");
printf(" %c |%c |%c\n",achBoard[1][0],achBoard[1][1],achBoard[1][2]);
printf("2--|--|--\n");
printf(" %c |%c |%c\n",achBoard[2][0],achBoard[2][1],achBoard[2][2]);
printf("3\n");
printf("\n");
printf("\n");
}
void PrintInfo_f()
{
printf("First player is represented by O,second by X.\n");
printf("Enter the coordinates for Rows and Columns\n");
printf("Strike enter when Done.\n");
printf("\n");
}
void PrintResult_f(int nFirstPlayer ,int nSecondPlayer ,int nDraws)
{
printf("the O player have won %d times\n",nFirstPlayer);
printf("the X player have won %d times\n",nSecondPlayer);
printf("there was %d draws\n",nDraws);
printf("thanks for using my program\n");
}
void IfError_f(int *ptX,int *ptY)
{
while(*ptX>3||*ptX<1||*ptY>3||*ptY<1||('O'==achBoard[*ptX-1][*ptY-1]||'X'==achBoard[*ptX-1][*ptY-1]))
{
printf("this coordinate is not allowed ,try again\n");
printf("Row:");
scanf("%d",ptX);
printf("Column:");
scanf("%d",ptY);
}
}
void ChoiceOfChar_f(char *ptChoice)
{
printf("\n");
printf("press capital Y if you want to play again.\n");
printf("otherwise ,press any other key to exit the loop.\n");
scanf("%c",ptChoice);
}
void PromptTurnO_f(int *ptX,int *ptY)
{
printf("turn of the first player (O),enter the coordinates\n");
printf("Row:");
scanf("%d",ptX);
printf("Column:");
scanf("%d",ptY);
}
void PromptTurnX_f(int *ptX,int *ptY)
{
printf("turn of the second player(X),enter the coordinates\n");
printf("Row:");
scanf("%d",ptX);
printf("Column:");
scanf("%d",ptY);
}