## cocos2d中平行的for循环问题

zhuceliyang 发布于 2013/03/07 18:57

for (x1=(i+1);i<=x1<=7;x1++)

{
if (chess[x1][j]==1)
{
a=(x1-i)/abs(x1-i);
for (d=1;d<abs(x1-i);d++)

{
if (chess[i+a*d][j]!=2)
{
h=2;
break;
}
}

if (h==0)
{
for (d=1;d<=abs(x1-i);d++)

{
chess[i+a*d][j]=1;
}
ondraw();
break;
}
else
{
MessageBoxA(
NULL,
"不可走棋!",
"游戏提示！",
MB_OKCANCEL);
chess[i][j]=0;
c--;
break;
}
}

}

//////-----------------------------------------------------------------------
for (x1=(i-1);0<=x1<=i;x1--)

{
if (chess[x1][j]==1)
{
a=(x1-i)/abs(x1-i);
for (d=1;d<abs(x1-i);d++)

{
if (chess[i+a*d][j]!=2)
{
h1=2;
break;
}
}

if (h1==0)
{
for (d=1;d<=abs(x1-i);d++)

{
chess[i+a*d][j]=1;
}
ondraw();
break;
}
else
{
MessageBoxA(
NULL,
"不可走棋!",
"游戏提示！",
MB_OKCANCEL);
chess[i][j]=0;
c--;
break;
}
}

}

/////------------------------------------------------------------------------
for (y1=(j+1);j<=y1<=7;y1++)

{
if (chess[i][y1]==1)
{
a=(y1-j)/abs(y1-j);
for (d=1;d<abs(y1-j);d++)

{
if (chess[i][j+a*d]!=2)
{
h2=2;
break;
}
}

if (h2==0)
{
for (d=1;d<=abs(y1-j);d++)

{
chess[i][j+a*d]=1;
}
ondraw();
break;
}
else
{
MessageBoxA(
NULL,
"不可走棋!",
"游戏提示！",
MB_OKCANCEL);
chess[i][j]=0;
c--;
break;
}
}

}

/////---------------------------------------------------------------------------
for (y1=(j-1);0<=y1<=j;y1--)

{
if (chess[i][y1]==1)
{
a=(y1-j)/abs(y1-j);
for (d=1;d<abs(y1-j);d++)

{
if (chess[i][j+a*d]!=2)
{
h3=2;
break;
}
}

if (h3==0)
{
for (d=1;d<=abs(y1-j);d++)

{
chess[i][j+a*d]=1;
}
ondraw();
break;
}
else
{
MessageBoxA(
NULL,
"不可走棋!",
"游戏提示！",
MB_OKCANCEL);
chess[i][j]=0;
c--;
break;
}
}