#include #include #include #define col 3 #define row 3 int color(int c) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c); return 0; } int store[][3]={'_','_','_','_','_','_','_','_','_'},i,j,k,flag=1; void map() { char boundary='|'; system("cls"); for(i=0;i score[maxRow][maxCol]) { maxRow = i; maxCol = j; } } store[maxRow][maxCol]='O'; map(); maxRow=mend(maxRow+1); printf("电脑走的棋格行号和列号是:%d %d\n",maxRow,maxCol+1); } void scan() { int x,y; printf("请输入要走的棋格行号和列号:"); scanf("%d%d",&x,&y); printf("%d,%d",x,y) ; x=mend(x); while(x>3||x<=0||y>3||y<=0||store[x-1][y-1]!='_') { if(x>3||x<=0||y>3||y<=0) printf("非法输入,输入数的范围为1到3!请重新输入\n"); else if (store[x-1][y-1]!='_') printf("该棋格已被占有,请重新输入\n"); getchar(); scanf("%d%d",&x,&y); x=mend(x); } store[x-1][y-1]='X'; map(); } int main() { int count=0,i; char ch; color(10); printf("\t这是一个井字棋游戏!\n在游戏之前请先阅读以下注意事项:\n"); printf("1.你可以选择下棋的先后顺序\n"); printf("2.您输入的第一个数是竖直方向,第二个是水平方向,输入的正确形式为:一个数y空一个数x\n"); printf("3.本程序还有许多不足,请多多包涵!\n") ; printf("按回车即可进入游戏-_- =_= +_+\n"); getchar(); system("cls"); color(12); printf("是否先下(y/n)"); scanf("%c",&ch); map(); if(ch=='N'||ch=='n') goto lp; for(count=0;count<10;count++) { i=judge(); if(judge()) break; if(count==9) { color(0); i=0; break; } color(14); printf("游戏状态:UNLEND\n"); color(3); scan(); lp: Computer(); count+=1; } color(4); final(i); return 0; }