⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addition2.cpp

📁 caro program is written by VC++ and AI
💻 CPP
字号:
/****************************************************************************/
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Some other Functions II ~~~~~~~~~~~~~~~~~~~~~~~
//									addition2.cpp
//
//***************************************************************************/



// Include
#include "ExCaro.h"

int CheckPoint(int xCheck, int yCheck, int iPlayer, int *iPoint, int *iBlock);

void MoveHiLight(int xPoint, int yPoint)
{
HDC hDC;
TCHAR szBuffer[50];

	ec.pMouse.x = xPoint;
	ec.pMouse.y = yPoint;

		if (ec.pOld.x !=ec.pMouse.x || ec.pOld.y != ec.pMouse.y )
		{
			hDC = GetDC(WndPlay.hWnd );

			MyRectangle(hDC, (ec.pOld.x)*XBLOCK, (ec.pOld.y)*XBLOCK, (ec.pOld.x+ 1)*XBLOCK+1, (ec.pOld.y + 1)*XBLOCK+1, skin.crBlockBorder, skin.crBlock);
	
			if( pBlock(ec.pOld.x, ec.pOld.y) >=0 )
			{
				DrawBlock((ec.pOld.x)*XBLOCK, (ec.pOld.y)*XBLOCK, pBlock( ec.pOld.x , ec.pOld.y ), skin.crPColor[ pBlock( ec.pOld.x , ec.pOld.y )] );
			}

			ec.pOld.x =ec.pMouse.x ;
			ec.pOld.y =ec.pMouse.y;
		
			MyRectangle(hDC, (ec.pOld.x )*XBLOCK, (ec.pOld.y )*XBLOCK, (ec.pOld.x + 1)*XBLOCK+1, (ec.pOld.y + 1)*XBLOCK+1, skin.crBlock, skin.crMouse);
		
			if( pBlock(ec.pMouse.x, ec.pMouse.y) >=0 &&  pBlock(ec.pMouse.x, ec.pMouse.y) < MAX_PLAYER )
				DrawBlock((ec.pMouse.x)*XBLOCK, (ec.pMouse.y)*XBLOCK, pBlock(ec.pMouse.x , ec.pMouse.y ), skin.crBlock );
			else
				DrawBlock((ec.pMouse.x)*XBLOCK, (ec.pMouse.y)*XBLOCK, play.iTurn ,
					RGB ( 
					min( 255, ( GetRValue(skin.crPColor[play.iTurn] ) + GetRValue(skin.crMouse ) )/2 ),
					min( 255, ( GetGValue(skin.crPColor[play.iTurn] ) + GetGValue(skin.crMouse ) )/2 ),
					min( 255, ( GetBValue(skin.crPColor[play.iTurn] ) + GetBValue(skin.crMouse ) )/2 )
					) 
					);

			// Set status
			wsprintf(szBuffer,"%2d x %2d",ec.pMouse.x +1, ec.pMouse.y +1);
  			ShowStatus(szBuffer);
	
			ReleaseDC(WndPlay.hWnd , hDC);
		} //endif ( ec.pOld.x !=... )
}

void ClickBlock(int xBlock, int yBlock )
{
HDC hDC;
int iPoint=0, iBlock=0, i;

	

	if(!play.fWin && !play.fComPlay)
	{
		// Get Mouse Position
		ec.pMouse.x = xBlock;
		ec.pMouse.y = yBlock;
	}

	// If click on a blank block
	if ( !play.fWin && play.fComPlay == FALSE && ( pBlock( ec.pMouse.x , ec.pMouse.y ) == -1 || pBlock( ec.pMouse.x , ec.pMouse.y ) >= MAX_PLAYER) ) 
	{
		if(player[play.iTurn].fPlay == HUMPLAY )
			PlaySound("start.wav", 0, SND_FILENAME | SND_ASYNC);

		// Check in new block
		posBlock( ec.pMouse.x , ec.pMouse.y ) = play.iTurn;

		play.iChecked++;

		// Set for Undo
		play.iUndo++;
		if ( play.iUndo == MAX_UNDO )
		{
			for( i=0 ; i <= MAX_UNDO - 2 ; i++ )
			{
				play.pUndo[i].x = play.pUndo[i + 1].x ;
				play.pUndo[i].y = play.pUndo[i + 1].y ; 

			}

			play.iUndo = MAX_UNDO - 1;

		}

		play.pUndo[play.iUndo].x = ec.pMouse.x;
		play.pUndo[play.iUndo].y = ec.pMouse.y;
		play.iMaxUndo = play.iUndo;

		// Check for win
		CheckPoint(ec.pMouse.x, ec.pMouse.y, play.iTurn, &iPoint, &iBlock);

		if(IsWin(iPoint, iBlock))
		{
			PlaySound("tada.wav", 0, SND_FILENAME | SND_ASYNC);

			play.fWin = TRUE;
			play.iWinner = play.iTurn ;
			SendMessage(WndPlay.hWnd, WM_MOUSELEAVE, 0, 0);

			InvalidateRect(WndPlay.hWnd, NULL, FALSE );
			ReDrawBanner();
			
		} // end if ( IsWin... )
		else
		{
			// Show player icon
			play.iTurn = play.iTurn + 1 >= ( MAX_PLAYER )  ? 0 : play.iTurn + 1;
			play.iTimeLimit = setting.iTime * CTIME - 1;

			hDC = GetDC(WndPlay.hWnd);
			MyRectangle(hDC, (ec.pMouse.x)*XBLOCK, (ec.pMouse.y)*XBLOCK, (ec.pMouse.x+ 1)*XBLOCK+1, (ec.pMouse.y + 1)*XBLOCK+1, skin.crBlock, skin.crMouse);

			if( pBlock(ec.pMouse.x, ec.pMouse.y) >=0 )
			{
				DrawBlock((ec.pMouse.x)*XBLOCK, (ec.pMouse.y)*XBLOCK, pBlock(ec.pMouse.x , ec.pMouse.y ), skin.crBlock );
			}
			ReleaseDC(WndPlay.hWnd, hDC );

			if( play.iChecked >= unsigned int(setting.iBlock * setting.iBlock) )
			{
				play.fWin = 2;
				SendMessage(WndPlay.hWnd, WM_MOUSELEAVE, 0, 0);
				InvalidateRect(WndPlay.hWnd, NULL, FALSE );
				ReDrawBanner();
			}
			

			if( setting.fWarning || player[play.iTurn].fPlay == COMPLAY)
			{
				CheckAll(2);
			} // endif ( setting.fWarning )

		} // else if ( IsWin.... )

		ReDrawPlayerBar();
	}
	else
		MessageBeep(0);
}

////////////////////////////////////////////////////////////////////
// Save Game
void SaveGame(TCHAR szFileName[])
{
HANDLE hFile;
DWORD dwBW;
TCHAR szFileType[40]="Anitsoft ExCaro 4.1 Save File";

	// Create new setting file	
	if(INVALID_HANDLE_VALUE!=(hFile=CreateFile(szFileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL)))
	{
		// Write Header Data
		WriteFile( hFile, &szFileType, sizeof(TCHAR) * 40, &dwBW ,NULL);

		WriteFile(hFile,&setting.iBlock ,sizeof(int),&dwBW,NULL);

		WriteFile(hFile,&setting.iRule ,sizeof(char),&dwBW,NULL);

		WriteFile(hFile,&(play),sizeof(play),&dwBW,NULL);

		WriteFile(hFile,&*pMatrix,sizeof(char) * setting.iBlock * setting.iBlock,&dwBW,NULL);
	}
	else
		// Error
		MessageBox(WndMain.hWnd,"Can't save setting.\nMaybe disk full or protected.",APPNAME,MB_OK|MB_ICONERROR);

	CloseHandle(hFile);
}

////////////////////////////////////////////////////////////////////
// Load game
void LoadGame(TCHAR szFileName[])
{
HANDLE hFile;
DWORD dwBR;
TCHAR szBuffer[MAX_PATH]="";
TCHAR szFileType[40];
HMENU hMenu;

	// Open setting file
    if(INVALID_HANDLE_VALUE!=(hFile = CreateFile (szFileName, GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, 0, NULL)))
	{
		// Read Header Data
		ReadFile (hFile, &szFileType, sizeof(TCHAR) * 40, &dwBR, NULL);

		// If this file is oldder version setting file or setting file corrupted
		if(strcmp(szFileType,"Anitsoft ExCaro 4.1 Save File"))
		{
			MessageBox(WndMain.hWnd,"Can't load game from this file.\nMay be it corrupted or created by other version",APPNAME,MB_OK | MB_ICONERROR );
		} // endif( )

		// OK ! Loading now
		else
		{
			hMenu = GetMenu(WndMain.hWnd);

			ReadFile(hFile,&setting.iBlock ,sizeof(int),&dwBR,NULL);
			
			CheckMenuItem(hMenu,IDM_SETTINGS_RULE_VIETNAM1 + setting.iRule , MF_UNCHECKED);
			ReadFile(hFile,&setting.iRule ,sizeof(char),&dwBR,NULL);
			CheckMenuItem(hMenu,IDM_SETTINGS_RULE_VIETNAM1 + setting.iRule , MF_CHECKED);

			ReadFile (hFile, &(play), sizeof(play), &dwBR, NULL);

			MoveWindow(WndPlay.hWnd, - play.siHPlay * XBLOCK , - play.siVPlay * XBLOCK ,(setting.iBlock)* XBLOCK +1, (setting.iBlock)* XBLOCK +1, TRUE );

			ReadFile(hFile,&*pMatrix,sizeof(char) * setting.iBlock * setting.iBlock,&dwBR,NULL);

			ec.pMouse.x = -1;
			ec.pMouse.y = -1;
			ec.pOld.x = -1;
			ec.pOld.y = -1;

			SendMessage(WndChild.hWnd, WM_SIZE, 0, 0 );
			InvalidateRect(WndPlay.hWnd, NULL, FALSE );
			UpdateWindow(WndPlay.hWnd);
			ReDrawBanner();
		}//end else

	} //endif(INVALID.....
	else
	{
		MessageBox(WndMain.hWnd,"Can't load game from this file.\nMay be it is not exist",APPNAME,MB_OK | MB_ICONERROR );
	}

	CloseHandle(hFile);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -