📄 wndplay2.h
字号:
/****************************************************************************/
//
// ~~~~~~~~~~~~~~~~ Window Play's Functions II ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// WndPlay2.h
//
//***************************************************************************/
//////////////////////////////////////////////////////////////////////////////
// Check for find winner -- Return all point + block
int CheckPoint(int xCheck, int yCheck, int iPlayer, int *iPoint, int *iBlock)
{
int x, y, iSign, iP, iB, i, xDirec, yDirec;
POINT pSWin={0,0}, pEWin={0,0};
int iAll=0;
*iPoint = 0;
*iBlock = 0;
for(i=0 ; i<4 ; i++ )
{
switch(i)
{
case 0: xDirec = 0; yDirec = 1; break;
case 1: xDirec = 1; yDirec = 0; break;
case 2: xDirec = 1; yDirec = 1; break;
case 3: xDirec = 1; yDirec = -1;break;
}
iP = 1;
iB = 1;
y = 0;
// Check top-left > down-right
for(iSign=-1; iSign<2; iSign+=2)
for(x=1; x<=10; x++)
{
y++;
iP = pBlock( xCheck + xDirec*iSign*x, yCheck + yDirec*iSign*y) == iPlayer ? iP + 1 : pBlock( xCheck + xDirec*iSign*x, yCheck + yDirec*iSign*y ) == -1 || pBlock( xCheck + xDirec*iSign*x, yCheck + yDirec*iSign*y ) >= MAX_PLAYER ? iP : iP -1;
iB = pBlock( xCheck + xDirec*iSign*x, yCheck + yDirec*iSign*y) == iPlayer ? iB + 1 : iB;
if( pBlock( xCheck + xDirec*iSign*x, yCheck + yDirec*iSign*y) != iPlayer )
{
if (iSign == -1 )
{
pSWin.x = ( xCheck + xDirec*iSign*(x -1) ) * XBLOCK + XBLOCK /2 - xDirec*XBLOCK /2;
pSWin.y = ( yCheck + yDirec*iSign*(y -1) ) * XBLOCK + XBLOCK /2 - yDirec*XBLOCK /2;
}
if (iSign == 1 )
{
pEWin.x = ( xCheck + xDirec*iSign*(x -1) ) * XBLOCK + XBLOCK /2 + xDirec*XBLOCK /2;
pEWin.y = ( yCheck + yDirec*iSign*(y -1) ) * XBLOCK + XBLOCK /2 + yDirec*XBLOCK /2;
}
y = 0;
break;
} // endif ( pBlock .... )
} // endfor ( iSign =-1 .....)
// Set WinLine
if ( IsWin( iP, iB ) )
{
play.pSWin[i].x = pSWin.x;
play.pSWin[i].y = pSWin.y;
play.pEWin[i].x = pEWin.x;
play.pEWin[i].y = pEWin.y;
}
else
{
play.pSWin[i].x = -1;
play.pSWin[i].y = -1;
play.pEWin[i].x = -1;
play.pEWin[i].y = -1;
}
*iPoint = max( *iPoint, iP);
*iBlock = max( *iBlock, iB);
iAll = iAll + iP + iB;
} // end for ( i = 0; ... )
return iAll;
}
//////////////////////////////////////////////////////////////////////////////
// Check for All ( iMode : 1 = Warning Only / 2 = Both )
void CheckAll(char iMode)
{
int xCheck, yCheck, iPlayer, iWar = 0, iAll;
int iP, iB, iPCom, iBCom, iPRiv, iBRiv, iComAll=0, iRivAll=0;
int iSumCom, iSumRiv;
POINT pCom, pRiv;
int iRand;
HDC hDC;
hDC = GetDC(WndPlay.hWnd);
for(yCheck = 0; yCheck < setting.iBlock ; yCheck ++ )
for(xCheck = 0; xCheck < setting.iBlock ; xCheck ++ )
// If this block is blank
if(pBlock(xCheck, yCheck) == -1 || pBlock(xCheck, yCheck) >=MAX_PLAYER)
// Check with all player
for(iPlayer = 0; iPlayer < ( MAX_PLAYER ) ; iPlayer++ )
{
// Check for win
iAll = CheckPoint(xCheck, yCheck, iPlayer, &iP, &iB);
//////////////////////////////////////////////////////////
// Computer Think
if ( iMode == 2 && player[play.iTurn].fPlay == COMPLAY )
{
iRand = rand() % 2;
if( play.iTurn == iPlayer && iSumCom <= iP + iB )
{
///////////////////////////////////
// Easy and Normal
if ( player[play.iTurn].iDiff <= 1 )
{
pCom.x = (iSumCom == iP + iB) ? iRand ? pCom.x : xCheck: xCheck;
pCom.y = (iSumCom == iP + iB) ? iRand ? pCom.y : yCheck: yCheck;
iSumCom = iP + iB;
iPCom = iP;
iBCom = iB;
} // end if ( Easy & Normal )
///////////////////////////////////
// Hard
if ( player[play.iTurn].iDiff == 2 )
{
if ( iSumCom < iP + iB)
{
iSumCom = iP + iB;
iComAll = iAll;
pCom.x = xCheck;
pCom.y = yCheck;
iPCom = iP;
iBCom = iB;
}
if ( iSumCom == iP + iB && iComAll <= iAll)
{
iSumCom = iP + iB;
pCom.x = (iComAll == iAll) ? iRand ? pCom.x : xCheck : xCheck;
pCom.y = (iComAll == iAll) ? iRand ? pCom.y : yCheck : yCheck;
iPCom = (iComAll == iAll) ? iRand ? iPCom : iP : iP;
iBCom = (iComAll == iAll) ? iRand ? iBCom : iB : iB;
iComAll = iAll;
}
} // end if ( Hard )
} // end if ( play.iTurn == iPlayer
if( play.iTurn != iPlayer && iSumRiv <= iP + iB )
{
///////////////////////////////////
// Easy and Normal
if ( player[play.iTurn].iDiff <= 1 )
{
pRiv.x = (iSumRiv == iP + iB) ? iRand ? pRiv.x : xCheck: xCheck;
pRiv.y = (iSumRiv == iP + iB) ? iRand ? pRiv.y : yCheck: yCheck;
iSumRiv = iP + iB;
iPRiv= iP;
iBRiv = iB;
} // end if ( Easy & Normal
///////////////////////////////////
// Hard
if ( player[play.iTurn].iDiff == 2 )
{
if ( iSumRiv < iP + iB )
{
iSumRiv = iP + iB;
iRivAll = iAll;
pRiv.x = xCheck;
pRiv.y = yCheck;
iPRiv = iP;
iBRiv = iB;
}
if ( iSumRiv == iP + iB && iRivAll <= iAll)
{
iSumRiv = iP + iB;
pRiv.x = (iRivAll == iAll) ? iRand ? pRiv.x : xCheck : xCheck;
pRiv.y = (iRivAll == iAll) ? iRand ? pRiv.y : yCheck : yCheck;
iPRiv = (iRivAll == iAll) ? iRand ? iPRiv : iP : iP;
iBRiv = (iRivAll == iAll) ? iRand ? iBRiv : iB : iB;
iRivAll = iAll;
}
} // end if ( Hard )
} // end if ( play.iTurn != iPlayer .. )
} // endif ( iMode ==2.. )
/////////////////////////////////////////////////////////////
// W A R N I N G
if(IsWin(iP, iB))
{
iWar++;
posBlock(xCheck, yCheck) = MAX_PLAYER + iPlayer;
DrawBlock(xCheck * XBLOCK , yCheck * XBLOCK , MAX_PLAYER + iPlayer, 0 );
} // end if ( IsWin... )
else
{
if( pBlock(xCheck, yCheck) - MAX_PLAYER == iPlayer )
{
MyRectangle(hDC,xCheck*XBLOCK,yCheck*XBLOCK,(xCheck + 1)*XBLOCK+1,(yCheck + 1)*XBLOCK+1, skin.crBlockBorder,skin.crBlock);
posBlock(xCheck, yCheck) = -1;
} // end else ( pBlock .. && IsWin... )
} // end else ( IsWin(....)
} //endfor( yCheck =..)
/////////////////////////////////////////////////////////////
// C O M P U T E R P L A Y
if ( iMode >= 2 && player[play.iTurn].fPlay == 1)
{
MyRectangle(hDC, (ec.pMouse.x)*XBLOCK, (ec.pMouse.y)*XBLOCK, (ec.pMouse.x+ 1)*XBLOCK+1, (ec.pMouse.y + 1)*XBLOCK+1, skin.crBlockBorder, skin.crBlock);
DrawBlock((ec.pMouse.x)*XBLOCK, (ec.pMouse.y)*XBLOCK, pBlock( ec.pMouse.x , ec.pMouse.y ), skin.crPColor[ pBlock( ec.pMouse.x , ec.pMouse.y )] );
play.fComPlay = TRUE;
if ( player[play.iTurn].iDiff == 0 ) // Easy
{
play.pComPlay.x = IsWin(iPCom , iBCom ) ? pCom.x : IsWin(iPRiv , iBRiv ) && iRand ? pRiv.x : iSumCom > 2 ? pCom.x : pRiv.x;
play.pComPlay.y = IsWin(iPCom , iBCom ) ? pCom.y : IsWin(iPRiv , iBRiv ) && iRand ? pRiv.y : iSumCom > 2 ? pCom.y : pRiv.y;
} // end if Easy
if ( player[play.iTurn].iDiff == 1 ) // Normal
{
play.pComPlay.x = IsWin(iPCom , iBCom ) ? pCom.x : IsWin(iPRiv , iBRiv ) ? pRiv.x : iSumCom > (iSumRiv)? pCom.x : pRiv.x;
play.pComPlay.y = IsWin(iPCom , iBCom ) ? pCom.y : IsWin(iPRiv , iBRiv ) ? pRiv.y : iSumCom > (iSumRiv)? pCom.y : pRiv.y;
} // end if Normal
if ( player[play.iTurn].iDiff == 2 ) // Hard
{
play.pComPlay.x = IsWin(iPCom , iBCom ) ? pCom.x : IsWin(iPRiv , iBRiv ) ? pRiv.x : iSumCom >= iSumRiv ? pCom.x : pRiv.x;
play.pComPlay.y = IsWin(iPCom , iBCom ) ? pCom.y : IsWin(iPRiv , iBRiv ) ? pRiv.y : iSumCom >= iSumRiv ? pCom.y : pRiv.y;
} // end if Hard
} // endif ( iMode >=2 ... )
if(setting.fWarning && play.fWarning != bool(iWar?1:0) )
{
ReDrawBanner();
play.fWarning = bool(iWar?1:0) ;
}
ReleaseDC(WndPlay.hWnd, hDC );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -