【五子棋胜负判定】我的代码有什么问题?

卢超群 2014-02-13 07:01:33
胜负判断基本思想为落一个子,判断一次,一次判断4个方向,代码哪里有问题,除了横着的,都判断不出来。
static void IfWin(int x,int y,int color)
{
TCHAR win[]=TEXT("Win!");
int a,b;
/*if(stone[x][y]==1)
strcpy(win, "黑棋赢!");
else
strcpy(win, "白棋赢!");*/
if(x>=4&&x<=14&&y>=4&&y<=14)
{
for(a=x-4;a<=x+4;a++)//判断横
if(stone[a][y]==color&&stone[a+1][y]==color&&stone[a+2][y]==color&&stone[a+3][y]==color&&stone[a+4][y]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(b=y-4;b<=y+4;b++)//判断竖
if(stone[x][b]==color&&stone[x][b+1]==color&&stone[x][b+2]==color&&stone[x][b+3]==color&&stone[x][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=x-4,b=y-4;a<=x+4;a++,b++)//判断右斜
if(stone[a][b]==color&&stone[a+1][b+1]==color&&stone[a+2][b+2]==color&&stone[a+3][b+3]==color&&stone[a+4][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=x-4,b=y+4;a<=x+4;a++,b--)//判断左斜
if(stone[a][b]==color&&stone[a+1][b-1]==color&&stone[a+2][b-2]==color&&stone[a+3][b-3]==color&&stone[a+4][b-4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
}
else if(x<4&&y>=4&&y<=14)
{
for(a=0;a<=x+4;a++)//判断横
if(stone[a][y]==color&&stone[a+1][y]==color&&stone[a+2][y]==color&&stone[a+3][y]==color&&stone[a+4][y]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(b=y-4;b<=y+4;b++)//判断竖
if(stone[x][b]==color&&stone[x][b+1]==color&&stone[x][b+2]==color&&stone[x][b+3]==color&&stone[x][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=0,b=y-4;a<=x+4;a++,b++)//判断右斜
if(stone[a][b]==color&&stone[a+1][b+1]==color&&stone[a+2][b+2]==color&&stone[a+3][b+3]==color&&stone[a+4][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=0,b=y+4;a<=x+4;a++,b++)//判断左斜
if(stone[a][b]==color&&stone[a+1][b-1]==color&&stone[a+2][b-2]==color&&stone[a+3][b-3]==color&&stone[a+4][b-4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
}
else if(x>=4&&x<=14&&y<4)
{
for(a=x-4;a<=x+4;a++)//判断横
if(stone[a][y]==color&&stone[a+1][y]==color&&stone[a+2][y]==color&&stone[a+3][y]==color&&stone[a+4][y]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(b=0;b<=y+4;b++)//判断竖
if(stone[x][b]==color&&stone[x][b+1]==color&&stone[x][b+2]==color&&stone[x][b+3]==color&&stone[x][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=x-y,b=0;a<=x+4;a++,b++)//判断右斜
if(stone[a][b]==color&&stone[a+1][b+1]==color&&stone[a+2][b+2]==color&&stone[a+3][b+3]==color&&stone[a+4][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=x-4,b=y+4;a<=x+y;a++,b++)//判断左斜
if(stone[a][b]==color&&stone[a+1][b-1]==color&&stone[a+2][b-2]==color&&stone[a+3][b-3]==color&&stone[a+4][b-4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
}
else if(x>14&&y>=4&&y<=14)
{
for(a=x-4;a<=18;a++)//判断横
if(stone[a][y]==color&&stone[a+1][y]==color&&stone[a+2][y]==color&&stone[a+3][y]==color&&stone[a+4][y]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(b=y-4;b<=y+4;b++)//判断竖
if(stone[x][b]==color&&stone[x][b+1]==color&&stone[x][b+2]==color&&stone[x][b+3]==color&&stone[x][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=0,b=y-4;a<=18;a++,b++)//判断右斜
if(stone[a][b]==color&&stone[a+1][b+1]==color&&stone[a+2][b+2]==color&&stone[a+3][b+3]==color&&stone[a+4][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=0,b=y+4;a<=18;a++,b++)//判断左斜
if(stone[a][b]==color&&stone[a+1][b-1]==color&&stone[a+2][b-2]==color&&stone[a+3][b-3]==color&&stone[a+4][b-4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
}
else if(x>=4&&x<=14&&y>14)
{
for(a=x-4;a<=x+4;a++)//判断横
if(stone[a][y]==color&&stone[a+1][y]==color&&stone[a+2][y]==color&&stone[a+3][y]==color&&stone[a+4][y]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(b=x-4;b<=18;b++)//判断竖
if(stone[x][b]==color&&stone[x][b+1]==color&&stone[x][b+2]==color&&stone[x][b+3]==color&&stone[x][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=x-4,b=y-4;a<=x+y;a++,b++)//判断右斜
if(stone[a][b]==color&&stone[a+1][b+1]==color&&stone[a+2][b+2]==color&&stone[a+3][b+3]==color&&stone[a+4][b+4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
for(a=x-4,b=0;a<=x+4;a++,b++)//判断左斜
if(stone[a][b]==color&&stone[a+1][b-1]==color&&stone[a+2][b-2]==color&&stone[a+3][b-3]==color&&stone[a+4][b-4]==color)
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
}
}
...全文
144 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
卢超群 2014-02-14
  • 打赏
  • 举报
回复
引用 1 楼 jiangcaiyang123 的回复:
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return; 这里要用括号括起来。
{
  MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
}
言之有理!竟然是如此小错误。我去试试,完后给分!
彩阳 2014-02-13
  • 打赏
  • 举报
回复
MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return; 这里要用括号括起来。
{
  MessageBoxW(Xqwl.hWnd,win,TEXT(""),MB_OK);return;
}

8,305

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧