c语言char choice,菜鸟求各位大侠指点

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值