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

📄 pipe.cpp

📁 一个windows ce 上接管道的小游戏, EVC的
💻 CPP
📖 第 1 页 / 共 3 页
字号:
						rect.left=big_x+bmp_size*y1+10;
					    rect.top=big_y+bmp_size*x1+count7_1;
						rect.right=big_x+bmp_size*y1+15;
						rect.bottom=rect.top+1;
						count7_1--;	
						hDC=GetDC(hwnd);
						Draw1(hwnd,hDC,11);
						ReleaseDC(hwnd,hDC);
					}
				break;

		    case 8: 
				B[x1][y1].select=FALSE;
				if((x1==(x2+1))&&(y1==y2))
					if(count8_1>24)
					{												   
						B[x1][y1].correct=FALSE;
						if((x1+1)>6) out=TRUE;
						else
						{
						    if((B[x1+1][y1].sign==3)||
								(B[x1+1][y1].sign==4)||
								(B[x1+1][y1].sign==5)||
								(B[x1+1][y1].sign==8))											   
								B[x1+1][y1].correct=TRUE;
							x2=x1;
							y2=y1;
							x1=x2+1;
							y1=y2;
						}
						count8_1=0;
						sum=sum+6;
					}
					else
					{
					    rect.left=big_x+bmp_size*y1+10;
						rect.top=big_y+bmp_size*x1+count8_1;
						rect.right=big_x+bmp_size*y1+15;
						rect.bottom=rect.top+1;
						count8_1++;
						hDC=GetDC(hwnd);
						Draw1(hwnd,hDC,11);
						ReleaseDC(hwnd,hDC);
					}
				if((x1==(x2-1))&&(y1==y2))
					if(count8_2<0)
					{													  
						B[x1][y1].select=FALSE;
						B[x1][y1].correct=FALSE;
						if((x1-1)<0) out=TRUE;
						else
						{
							if((B[x1-1][y1].sign==3)||
								(B[x1-1][y1].sign==6)||
								(B[x1-1][y1].sign==7)||
								(B[x1-1][y1].sign==8))											   
							  B[x1-1][y1].correct=TRUE;
							x2=x1;
							y2=y1;
							x1=x2-1;
							y1=y2;
						}
						count8_2=24;
						sum=sum+6;
					}
					else
					{
						rect.left=big_x+bmp_size*y1+10;
						rect.top=big_y+bmp_size*x1+count8_2;
						rect.right=big_x+bmp_size*y1+15;
					    rect.bottom=rect.top+1;
						count8_2--;
						hDC=GetDC(hwnd);
						Draw1(hwnd,hDC,11);
						ReleaseDC(hwnd,hDC);
					}
				break;
			}
			rect.left=65;
			rect.top=255;
			rect.right=145;
			rect.bottom=270;
			hDC=GetDC(hwnd);
			Draw1(hwnd,hDC,14);
			_ltow(sum,string,10);
			DrawText(hDC,string,-1,&rect,DT_CENTER);
			ReleaseDC(hwnd,hDC);
		}
	    else 
			if((B[x1][y1].sign==10)||(!B[x1][y1].select)||
				(!B[x1][y1].correct))
			{
			    KillTimer(hwnd,IDT_TIMER2);
				KillTimer(hwnd,IDT_TIMER3);
				if((level==1)&&(sum>100))
					DialogBox(hInst,MAKEINTRESOURCE(IDD_LEVEL),
					          hwnd,(DLGPROC)Level_dlg);
				else
		        if((level==2)&&(sum>150))
					DialogBox(hInst,MAKEINTRESOURCE(IDD_LEVEL),
					          hwnd,(DLGPROC)Level_dlg);
				else
				if((level==3)&&(sum>190))
					DialogBox(hInst,MAKEINTRESOURCE(IDD_LEVEL),
					          hwnd,(DLGPROC)Level_dlg);
				else 
				if((level==4)&&(sum>210))
					DialogBox(hInst,MAKEINTRESOURCE(IDD_LEVEL),
					          hwnd,(DLGPROC)Level_dlg);
				else
				if((level==5)&&(sum>230))
					DialogBox(hInst,MAKEINTRESOURCE(IDD_LEVEL),
					          hwnd,(DLGPROC)Level_dlg);
				else
					DialogBox(hInst,MAKEINTRESOURCE(IDD_LOST),
					          hwnd,(DLGPROC)Lost_dlg);
				ReleaseDC(hwnd,hDC);								
			}
}





/********************************************************************
	Draw1(): draw the part of the liquid
********************************************************************/
void Draw1(HWND hwnd,HDC hDC, int num)
{
	hdcMem=CreateCompatibleDC(hDC);
	hbk=LoadBitmap(hInst,MAKEINTRESOURCE(num));	 
	SelectObject(hdcMem,hbk);
	GetObject(hbk,sizeof(BITMAP),(LPSTR)&bm);
	StretchBlt(hDC,rect.left,rect.top,bm.bmWidth,bm.bmHeight,
		       hdcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
	DeleteObject(hbk);
	DeleteDC(hdcMem);
}



/********************************************************************
	Draw(): draw the random pipe beside the main square
********************************************************************/
void Draw(HWND hwnd)
{
	if(B[x][y].select)
	{
	    if(B[x][y].sign!=10)
			sum=sum-2;
	    B[x][y].sign=r[0];
		rect.left=big_x+bmp_size*y;
		rect.top=big_y+bmp_size*x;
		rect.right=big_x+bmp_size*y+bmp_size;
		rect.bottom=big_y+bmp_size*x+bmp_size;
		hDC=GetDC(hwnd);
		Draw1(hwnd,hDC,r[0]);
		ReleaseDC(hwnd,hDC);
	    for(i=0;i<5;i++)
		{
		    r[i]=r[i+1];
			rect.left=small_x+bmp_size*4-i*bmp_size;
		    rect.top=small_y;
		    rect.right=small_x+24;
			rect.bottom=small_y+bmp_size*4-i*bmp_size+bmp_size;
			hDC=GetDC(hwnd);
			Draw1(hwnd,hDC,r[i]);
			ReleaseDC(hwnd,hDC);
		}

		r[4]=Random()%8+1;
        if(r[4]==1) 
			r[4]=2;
		rect.left=small_x;
		rect.top=small_y;
		rect.right=small_x+bmp_size;
		rect.bottom=small_y+bmp_size;
		hDC=GetDC(hwnd);
		Draw1(hwnd,hDC,r[4]);
		ReleaseDC(hwnd,hDC);
	}
	
	rect.left=65;
	rect.top=255;
	rect.right=145;
	rect.bottom=270;
	Draw1(hwnd,hDC,14);
	_ltow(sum,string,10);
	DrawText(hDC,string,-1,&rect,DT_CENTER);
	ReleaseDC(hwnd,hDC);
}



/********************************************************************
	Command(): deal with the buttom or menu message
********************************************************************/
void Command(HWND hwnd,UINT msg1,WPARAM wp1,LPARAM	lp1)
{
	switch(GET_WM_COMMAND_ID(wp1,lp1))
	{  
	case IDM_EXIT:
		SendMessage(hwnd,WM_CLOSE,0,0);
		break;

	case IDM_FAST:
		KillTimer(hwnd,IDT_TIMER2);
		SetTimer(hwnd,IDT_TIMER3,5,NULL);
		break;

	case IDM_NEW: 
		KillTimer(hwnd,IDT_TIMER2);
		KillTimer(hwnd,IDT_TIMER3);
	    start_new(hwnd);
		if(menuview==Level1)
		{
			start=15000;
			internal=150;
			level=1;
		}
		else
		if(menuview==Level2)
		{
			start=13000;
			internal=130;
			level=2;
		}
		else
	    if(menuview==Level3)
		{
			start=11000;
			internal=110;
			level=3;
		}
		else
		if(menuview==Level4)
		{
			start=9000;
			internal=90;
			level=4;
		}
		else
		{
			start=7000;
			internal=70;
			level=5;
		}
		SetTimer(hwnd,IDT_TIMER1,start,NULL);
		InvalidateRect(hwnd,NULL,TRUE);
		UpdateWindow(hwnd);						
		break;
	
	case IDM_LEVEL1:
	    KillTimer(hwnd,IDT_TIMER2); 
		KillTimer(hwnd,IDT_TIMER3);
		if(menuview!=Level1)
		{
			menuview=Level1;
			hMenu=CommandBar_GetMenu(hwndCB,0);
			CheckMenuItem(hMenu,Premenu,MF_UNCHECKED);
			CheckMenuItem(hMenu,IDM_LEVEL1,MF_CHECKED);
		    Premenu=IDM_LEVEL1;
		}
		start_new(hwnd);
		level=1;
		start=15000;
		internal=150;
		SetTimer(hwnd,IDT_TIMER1,start,NULL);
		InvalidateRect(hwnd,NULL,TRUE);
		UpdateWindow(hwnd);
		break;
						   
	case IDM_LEVEL2:
		KillTimer(hwnd,IDT_TIMER2); 
		KillTimer(hwnd,IDT_TIMER3);
        if(menuview!=Level2)
		{
			menuview=Level2;
			hMenu=CommandBar_GetMenu(hwndCB,0);
			CheckMenuItem(hMenu,Premenu,MF_UNCHECKED);
			CheckMenuItem(hMenu,IDM_LEVEL2,MF_CHECKED);
			Premenu=IDM_LEVEL2;	
		}
		start_new(hwnd);
		level=2;
		start=13000;
		internal=130;
		SetTimer(hwnd,IDT_TIMER1,start,NULL);
		InvalidateRect(hwnd,NULL,TRUE);
	    UpdateWindow(hwnd);
		break;

	case IDM_LEVEL3:	 
		KillTimer(hwnd,IDT_TIMER2);
		KillTimer(hwnd,IDT_TIMER3);
		if(menuview!=Level3)
		{
			menuview=Level3;
			hMenu=CommandBar_GetMenu(hwndCB,0);
			CheckMenuItem(hMenu,Premenu,MF_UNCHECKED);
			CheckMenuItem(hMenu,IDM_LEVEL3,MF_CHECKED);
			Premenu=IDM_LEVEL3;								 
		}
		start_new(hwnd);
        start=11000;		
		level=3;
		internal=110;
		SetTimer(hwnd,IDT_TIMER1,start,NULL);
		InvalidateRect(hwnd,NULL,TRUE);
		UpdateWindow(hwnd);
		break;

	case IDM_LEVEL4:
		KillTimer(hwnd,IDT_TIMER2);
		KillTimer(hwnd,IDT_TIMER3);
	    if(menuview!=Level4)
		{
			menuview=Level4;
			hMenu=CommandBar_GetMenu(hwndCB,0);
			CheckMenuItem(hMenu,Premenu,MF_UNCHECKED);
			CheckMenuItem(hMenu,IDM_LEVEL4,MF_CHECKED);
			Premenu=IDM_LEVEL4;								 
		}
		start_new(hwnd);
        start=9000;		
		level=4;
		internal=90;
		SetTimer(hwnd,IDT_TIMER1,start,NULL);
		InvalidateRect(hwnd,NULL,TRUE);
		UpdateWindow(hwnd);
		break;

	case IDM_LEVEL5:
		KillTimer(hwnd,IDT_TIMER2);
		KillTimer(hwnd,IDT_TIMER3);
	    if(menuview!=Level5)
		{
			menuview=Level5;
			hMenu=CommandBar_GetMenu(hwndCB,0);
			CheckMenuItem(hMenu,Premenu,MF_UNCHECKED);
			CheckMenuItem(hMenu,IDM_LEVEL5,MF_CHECKED);
			Premenu=IDM_LEVEL5;								 
		}
		start_new(hwnd);
        start=7000;		
		level=5;
		internal=70;
		SetTimer(hwnd,IDT_TIMER1,start,NULL);
		InvalidateRect(hwnd,NULL,TRUE);
	    UpdateWindow(hwnd);
		break;

	case IDM_HOW:
	    if(time)
			KillTimer(hwnd,IDT_TIMER1);
		else 
			KillTimer(hwnd,IDT_TIMER2);
		DialogBox(hInst,MAKEINTRESOURCE(IDD_HOW),hwnd,(DLGPROC)About);
        break;

	case IDM_ABOUT:
		if(time)
			KillTimer(hwnd,IDT_TIMER1);
		else 
			KillTimer(hwnd,IDT_TIMER2);
		DialogBox(hInst,MAKEINTRESOURCE(IDD_ABOUT),hwnd,(DLGPROC)About);
		break;
	} 
}




/********************************************************************
	About(): deal with the About dialog message
********************************************************************/
LRESULT CALLBACK About(HWND hwnd,UINT msg, WPARAM wp,LPARAM lp)
{
	LRESULT		lResult=FALSE;

	switch(msg)
	{
	case WM_COMMAND:
		if(time)
			SetTimer(hwnd,IDT_TIMER1,start,NULL);
		else
			SetTimer(hwnd,IDT_TIMER2,internal,NULL);
		EndDialog(hwnd,TRUE);
		return TRUE;
		break;
	}
	return(lResult);
}



/********************************************************************
	start_new(): start a new game, initialize all the variables
********************************************************************/
void start_new(HWND hwnd)
{
	for(i=0;i<7;i++)
		for(j=0;j<9;j++)
		{ 
			B[i][j].sign=10;
	   		B[i][j].select=TRUE;
			B[i][j].correct=FALSE;
		}
		
	i=Random()%7;
    // j=Random()%15;
	j=Random()%9;
    if(i==0) i=1;
    startx=i;
    starty=j;
    B[i][j].sign=9;
	B[i][j].select=FALSE;
    B[i][j].correct=TRUE;
    for(i=0;i<5;i++)
	{
		r[i]=Random()%8+1;
	  	if(r[i]==1) r[i]=2;
	}
	
	time=TRUE;
	out=FALSE;
	sum=50;
}



/********************************************************************
	Level_dlg(): deal with the Level dialog message
********************************************************************/
LRESULT CALLBACK Level_dlg(HWND hwnd,UINT msg, WPARAM wp,LPARAM lp)
{
	LRESULT		lResult=FALSE;

	switch(msg)
	{
	case WM_COMMAND:
		switch(wp)
		{
		case  IDCANCEL:
			EndDialog(hwnd,TRUE);
			SendMessage(hwndMain,WM_CLOSE,0,0);
			return TRUE;
			break;

		case  IDOK:
			EndDialog(hwnd,TRUE);
			start_new(hwndMain);
			if(level<5)
			{
				level++;
			    start=start-20;
			    internal=internal-20;
			}
			else
			{
				level=1;
			    start=15000;
				internal=150;
			}
			SetTimer(hwndMain,IDT_TIMER1,start,NULL);
			InvalidateRect(hwndMain,NULL,TRUE);
		    UpdateWindow(hwndMain);
			return TRUE;
		break;
		}
		break;
	}
	return(lResult);
}



/********************************************************************
	Lost_dlg(): deal with the Lost dialog message
********************************************************************/
LRESULT CALLBACK Lost_dlg(HWND hwnd,UINT msg, WPARAM wp,LPARAM lp)
{
	LRESULT		lResult=FALSE;

	switch(msg)
	{
	case WM_COMMAND:
		switch(wp)
		{
		case  IDCANCEL:
			EndDialog(hwnd,TRUE);
			SendMessage(hwndMain,WM_CLOSE,0,0);
			return TRUE;
            break;

		case  IDOK:
			EndDialog(hwnd,TRUE);
			start_new(hwndMain);
			level=1;
			start=15000;
			internal=150;
			SetTimer(hwndMain,IDT_TIMER1,start,NULL);
			InvalidateRect(hwndMain,NULL,TRUE);
		    UpdateWindow(hwndMain);
            return TRUE;
		break;
		}
		break;
	}
	return(lResult)	;
}


⌨️ 快捷键说明

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