c语言五子棋卡死,C语言五子棋

代码新手,不足之处请多多指教

1.[代码][C/C++]代码

#define _CRT_SECURE_NO_WARNING

#include

#include

#include

#include

void startmap(wchar_t a[22][22]);

void mapout(wchar_t a[22][22]);

void downW(wchar_t a[22][22]);

void downB(wchar_t a[22][22]);

int judgeW(wchar_t a[22][22]);

int judgeB(wchar_t a[22][22]);

void main()

{

char ans;

/*int num = 1;

char tit[100] = { 0 };

char tth[50] = "五子棋,第";

char tte[50] = "局";*/

setlocale(LC_ALL, "chs");

RE: /*sprintf_s(tit, "%s%d%s",tth, num,tte);*/

system("title 五子棋");

wchar_t a[22][22];

int res = 1;

startmap(a);

do

{

mapout(a);

downW(a);

mapout(a);

res = judgeW(a);

if (res == 0)

break;

downB(a);

mapout(a);

res = judgeB(a);

if (res == 0)

break;

}

while (res);

printf("%p", &ans);

puts("是否重新开始?(Y/N)");

//scanf_s("%c", &ans);

fflush(stdin);

ans = getchar();

fflush(stdin);

if (ans == 'Y'||ans=='y')

{

goto RE;

//num++;

}

system("pause");

}

void startmap(wchar_t a[22][22])

{

a[0][0] = L'┌';

a[21][0] = L'└';

a[0][21] = L'┐';

a[21][21] = L'┘';

for (int j = 1; j < 21; j++)

{

a[0][j] = L'┬';

}

for (int j = 1; j < 21; j++)

{

a[j][0] = L'├';

}

for (int j = 1; j < 21; j++)

{

a[j][21] = L'┤';

}

for (int j = 1; j < 21; j++)

{

a[21][j] = L'┴';

}

for (int i = 1; i < 21; i++)

{

for (int j = 1; j < 21; j ++)

{

a[i][j] = L'┼';

}

}

}

void mapout(wchar_t a[22][22])

{

printf(" ");

for (int i = 0; i < 22; i++)

printf("%2d", i);

printf("\n");

for (int i = 0; i < 22; i++)

{

printf("%2d", i);

for (int j = 0; j < 22; j ++)

{

wprintf(L"%wc", a[i][j]);

}

printf("\n");

}

}

void downB(wchar_t a[22][22])

{

int x, y;

DOWNB:puts("黑x=");

scanf_s("%d",&x);

puts("黑y=");

scanf_s("%d", &y);

if (a[x][y] == L'○' || a[x][y] == L'●' || x<1 || x>20 || y<1 || y>20)

{

printf("下错地方了,智障,重来\n");

goto DOWNB;

}

a[x][y] = L'○';

}

void downW(wchar_t a[22][22])

{

int x, y;

DOWNW:puts("白x=");

scanf_s("%d", &x);

puts("白y=");

scanf_s("%d", &y);

if (a[x][y] == L'○' || a[x][y] == L'●' || x<1 || x>20 || y<1 || y>20)

{

printf("下错地方了,智障,重来\n");

goto DOWNW;

}

a[x][y] = L'●';

}

int judgeB(wchar_t a[22][22])

{

int count = 1;

wchar_t(*p)[22] = strchr(a, L'○');

//检查行

for (int i = 1; *(*p + i) == L'○'; i++)

count++;

if (count == 5)

{

puts("游戏结束,黑方胜!");

return 0;

}

else if (count > 5)

{

puts("禁手");

}

//检查列

count = 1;

for (int i = 1; *(*(p + i)) == L'○'; i++)

count++;

if (count == 5)

{

puts("游戏结束,黑方胜!");

return 0;

}

else if (count > 5)

{

puts("禁手");

}

//检查正斜边

count = 1;

for (int i = 1; *(*(p + i)+i) == L'○'; i++)

count++;

if (count == 5)

{

puts("游戏结束,黑方胜!");

return 0;

}

else if (count > 5)

{

puts("禁手");

}

//检查反斜边

count = 1;

for (int i = 1; *(*(p - i)-i) == L'○'; i++)

count++;

if (count == 5)

{

puts("游戏结束,黑方胜!");

return 0;

}

else if (count > 5)

{

puts("禁手");

}

return 1;

}

int judgeW(wchar_t a[22][22])

{

int count = 1;

wchar_t(*p)[22] = strchr(a, L'●');

//检查行

for (int i = 1; *(*p + i) == L'●'; i++)

count++;

if (count == 5)

{

puts("游戏结束,白方胜!");

return 0;

}

else if (count > 5)

{

puts("禁手");

}

//检查列

count = 1;

for (int i = 1; *(*(p + i)) == L'●'; i++)

count++;

if (count == 5)

{

puts("游戏结束,白方胜!");

return 0;

}

else if (count > 5)

{

puts("禁手");

}

//检查正斜边

count = 1;

for (int i = 1; *(*(p + i) + i) == L'●'; i++)

count++;

if (count == 5)

{

puts("游戏结束,白方胜!");

return 0;

}

else if (count > 5)

{

puts("禁手");

}

//检查反斜边

count = 1;

for (int i = 1; *(*(p - i) - i) == L'●'; i++)

count++;

if (count == 5)

{

puts("游戏结束,白方胜!");

return 0;

}

else if (count > 5)

{

puts("禁手");

}

return 1;

}

2.[图片] QQ图片20160524103607.png

24103641_WCPq.png

3.[图片] QQ图片20160524103611.png

24103641_RwVO.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值