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

📄 escape.cpp

📁 WindowsCE上一个搬砖块的小游戏代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			}
		}
    DeleteDC(hdcMem);
	
    Fill_rect(30,80,180,195);
	DrawText(hDC,TEXT("Level:"),-1,&rect,DT_LEFT);
   
    Fill_rect(80,130,180,195);
    _ltow(level,string,10);
    DrawText(hDC,string,-1,&rect,DT_CENTER);

	Fill_rect(150,200,180,195);
	DrawText(hDC,TEXT("Step:"),-1,&rect,DT_LEFT);

	Fill_rect(200,250,180,195);
	_ltow(step,string,10);
	DrawText(hDC,string,-1,&rect,DT_CENTER);
}
  														   




/********************************************************************
	Draw1(): draw the square positions
********************************************************************/
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);
}




/********************************************************************
	Command(): deal with the buttom 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_NEW:
			Init_level(hwnd);
			step=0;
			InvalidateRect(hwnd,NULL,TRUE);
			UpdateWindow(hwnd);
			break;

		case IDM_SELECT:
			DialogBox(hInst,MAKEINTRESOURCE(IDD_SELECT),hwnd,(DLGPROC)Select);
            break;

		case IDM_PASS:
			if(!Pass(hwnd))
				MessageBox(hwnd, TEXT("You can not pass this level!"), TEXT("Warning"), MB_OK);
			break;

		case IDM_PREV:
			Prev(hwnd);
			break;

		case IDM_NEXT:
			Next(hwnd);
			break;

	    case IDM_HOW:
		    DialogBox(hInst,MAKEINTRESOURCE(IDD_HOW),hwnd,(DLGPROC)About);
            break;

		case IDM_ABOUT:
			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:
		EndDialog(hwnd,TRUE);
		return TRUE;
		break;
	}
	return(lResult);
}



/********************************************************************
	Select(): deal with the Select dialog message
********************************************************************/
LRESULT CALLBACK Select(HWND hwnd,UINT msg, WPARAM wp,LPARAM lp)
{
	LRESULT lResult=FALSE;
	BOOL K;
	switch(msg)
	{
	case WM_INITDIALOG:
		K=SetDlgItemInt(hwnd,IDC_SELECT,1,FALSE);
		return FALSE;
	
    
	case WM_COMMAND:
		switch(wp)
		{
		case IDOK:
			level=GetDlgItemInt(hwnd,IDC_SELECT,NULL,FALSE);
			Init_level(hwnd);
			step=0;
			InvalidateRect(hwndMain,NULL,TRUE);
			UpdateWindow(hwndMain);	  
			SetFocus(hwndMain);
			EndDialog(hwnd,TRUE);
			return TRUE;
			break;

		case IDCANCEL:
			EndDialog(hwnd,TRUE);
			return TRUE;
			break;
		}
        break;

	case WM_CLOSE:
        EndDialog(hwnd,TRUE);
		return TRUE;
		break; 
	}
	return(lResult);
}




/********************************************************************
	Init_level(): initialize the array about the different level
********************************************************************/
void Init_level(HWND hwnd)
{
	switch(level)
	{
		case 1:
			Copy_level(hwnd,Gate_1);
			break;

		case 2:
			Copy_level(hwnd,Gate_2);
			break;

		case 3:
			Copy_level(hwnd,Gate_3);
			break;

		case 4:
			Copy_level(hwnd,Gate_4);
			break;

		case 5:
			Copy_level(hwnd,Gate_5);
			break;

		case 6:
			Copy_level(hwnd,Gate_6);
			break;

		case 7:
			Copy_level(hwnd,Gate_7);
			break;

		case 8:
			Copy_level(hwnd,Gate_8);
			break;

		case 9:
			Copy_level(hwnd,Gate_9);
			break;

		case 10:
			Copy_level(hwnd,Gate_10);
			break;

		case 11:
			Copy_level(hwnd,Gate_11);
			break;

		case 12:
			Copy_level(hwnd,Gate_12);
			break;

		case 13:
			Copy_level(hwnd,Gate_13);
			break;
	}
}



/********************************************************************
	Copy_level(): copy the initialization data to temp array
********************************************************************/
void Copy_level(HWND hwnd,  BUT copy[6][9])
{
	int i,j;
	for(i=0;i<6;i++)
		for(j=0;j<9;j++)
			temp[i][j]=copy[i][j];
}



/********************************************************************
	Move(): deal with the moving about the square
********************************************************************/
void Move(HWND hwnd)
{
	int move_flag=0;
	if(can_move)
		switch(temp[x][y].sign_1)
		{
		case 4:
			if(section==left)
				if(temp[x][y-1].sign_1==0)
				{
					temp[x][y-1].sign=4;
					temp[x][y-1].sign_1=4;
					temp[x][y-1].station=0;
					temp[x][y].sign=6;
					temp[x][y].sign_1=0;
					temp[x][y].station=0;
					ChangDraw(hwnd,y,y+1,x,x+1,6,y-1,y,x,x+1,4);
					move_flag=1;	
				}
            if(section==right)
			    if(temp[x][y+1].sign_1==0)
				{
					temp[x][y+1].sign=4;
					temp[x][y+1].sign_1=4;
					temp[x][y+1].station=0;
					temp[x][y].sign=6;
					temp[x][y].sign_1=0;
					temp[x][y].station=0;
					ChangDraw(hwnd,y,y+1,x,x+1,6,y+1,y+2,x,x+1,4);
					move_flag=1;
				}
		    if(section==up)
			    if(temp[x-1][y].sign_1==0)
				{
					temp[x-1][y].sign=4;
					temp[x-1][y].sign_1=4;
					temp[x-1][y].station=0;
					temp[x][y].sign=6;
					temp[x][y].sign_1=0;
					temp[x][y].station=0;
					ChangDraw(hwnd,y,y+1,x,x+1,6,y,y+1,x-1,x,4);
					move_flag=1;
				}
		    if(section==down)
				if(temp[x+1][y].sign_1==0)
				{
					temp[x+1][y].sign=4;
					temp[x+1][y].sign_1=4;
					temp[x+1][y].station=0;
					temp[x][y].sign=6;
					temp[x][y].sign_1=0;
					temp[x][y].station=0;
					ChangDraw(hwnd,y,y+1,x,x+1,6,y,y+1,x+1,x+2,4);
					move_flag=1;
				}
				break;

		case 2:
			if(section==left)
			{
				if(temp[x][y].station==1)
					if((temp[x][y-1].sign_1==0)&&(temp[x+1][y-1].sign_1==0))
					{
						temp[x][y-1].sign=2;
						temp[x][y-1].sign_1=2;
						temp[x][y-1].station=1;
						temp[x+1][y-1].sign=0;
						temp[x+1][y-1].sign_1=2;
						temp[x+1][y-1].station=2;
						temp[x][y].sign=6;
						temp[x][y].sign_1=0;
						temp[x][y].station=0;
						temp[x+1][y].sign=6;
						temp[x+1][y].sign_1=0;
						temp[x+1][y].station=0;
						ChangDraw(hwnd,y,y+1,x,x+2,8,y-1,y,x,x+2,2);
						move_flag=1;
					}
				if(temp[x][y].station==2)
					if((temp[x-1][y-1].sign_1==0)&&(temp[x][y-1].sign_1==0))
					{
						temp[x-1][y-1].sign=2;
						temp[x-1][y-1].sign_1=2;
						temp[x-1][y-1].station=1;
						temp[x][y-1].sign=0;
						temp[x][y-1].sign_1=2;
						temp[x][y-1].station=2;
						temp[x][y].sign=6;
						temp[x][y].sign_1=0;
						temp[x][y].station=0;
						temp[x-1][y].sign=6;
						temp[x-1][y].sign_1=0;
						temp[x-1][y].station=0;
						ChangDraw(hwnd,y,y+1,x-1,x+1,8,y-1,y,x-1,x+1,2);
						move_flag=1;
					}
			}
			if(section==right)
			{
				if(temp[x][y].station==1)
					if((temp[x][y+1].sign_1==0)&&(temp[x+1][y+1].sign_1==0))
					{
						temp[x][y+1].sign=2;
						temp[x][y+1].sign_1=2;
						temp[x][y+1].station=1;
						temp[x+1][y+1].sign=0;
						temp[x+1][y+1].sign_1=2;
						temp[x+1][y+1].station=2;
						temp[x][y].sign=6;
						temp[x][y].sign_1=0;
						temp[x][y].station=0;
						temp[x+1][y].sign=6;
						temp[x+1][y].sign_1=0;
						temp[x+1][y].station=0;
						ChangDraw(hwnd,y,y+1,x,x+2,8,y+1,y+2,x,x+2,2);
						move_flag=1;
					}
				if(temp[x][y].station==2)
					if((temp[x-1][y+1].sign_1==0)&&(temp[x][y+1].sign_1==0))
					{
						temp[x-1][y+1].sign=2;
						temp[x-1][y+1].sign_1=2;
						temp[x-1][y+1].station=1;
						temp[x][y+1].sign=0;
						temp[x][y+1].sign_1=2;
						temp[x][y+1].station=2;
						temp[x][y].sign=6;
						temp[x][y].sign_1=0;
						temp[x][y].station=0;
						temp[x-1][y].sign=6;
						temp[x-1][y].sign_1=0;
						temp[x-1][y].station=0;
						ChangDraw(hwnd,y,y+1,x-1,x+1,8,y+1,y+2,x-1,x+1,2);
						move_flag=1;
					}
			}
			if(section==up)
			{
				if(temp[x][y].station==1)
				{
					if(temp[x-1][y].sign_1==0)
					{
						temp[x-1][y].sign=2;
						temp[x-1][y].sign_1=2;
						temp[x-1][y].station=1;
						temp[x][y].sign=0;
						temp[x][y].sign_1=2;
						temp[x][y].station=2;
						temp[x+1][y].sign=6;
						temp[x+1][y].sign_1=0;
						temp[x+1][y].station=0;
						ChangDraw(hwnd,y,y+1,x+1,x+2,6,y,y+1,x-1,x+1,2);
						move_flag=1;
					}
				}
				else
					if(temp[x-2][y].sign_1==0)
					{
						temp[x-2][y].sign=2;
						temp[x-2][y].sign_1=2;
						temp[x-2][y].station=1;
						temp[x-1][y].sign=0;
						temp[x-1][y].sign_1=2;
						temp[x-1][y].station=2;
						temp[x][y].sign=6;
						temp[x][y].sign_1=0;
						temp[x][y].station=0;
						ChangDraw(hwnd,y,y+1,x,x+1,6,y,y+1,x-2,x,2);
						move_flag=1;
					}
			}
			if(section==down)
			{
				if(temp[x][y].station==1)
					if(temp[x+2][y].sign_1==0)
					{
						temp[x+2][y].sign=0;
						temp[x+2][y].sign_1=2;
						temp[x+2][y].station=2;
						temp[x+1][y].sign=2;
						temp[x+1][y].sign_1=2;
						temp[x+1][y].station=1;
						temp[x][y].sign=6;
						temp[x][y].sign_1=0;
						temp[x][y].station=0;
						ChangDraw(hwnd,y,y+1,x,x+1,6,y,y+1,x+1,x+3,2);
						move_flag=1;
					}
				if(temp[x][y].station==2)
					if(temp[x+1][y].sign_1==0)
					{
						temp[x+1][y].sign=0;
						temp[x+1][y].sign_1=2;
						temp[x+1][y].station=2;
						temp[x][y].sign=2;
						temp[x][y].sign_1=2;
						temp[x][y].station=1;
						temp[x-1][y].sign=6;
						temp[x-1][y].sign_1=0;
						temp[x-1][y].station=0;
						ChangDraw(hwnd,y,y+1,x-1,x,6,y,y+1,x,x+2,2);
						move_flag=1;
					}
			}
			break;

		case 3:
			if(section==left)
			{
				if(temp[x][y].station==1)
				{
					if(temp[x][y-1].sign_1==0)
					{
						temp[x][y-1].sign=3;
						temp[x][y-1].sign_1=3;
						temp[x][y-1].station=1;
						temp[x][y].sign=0;
						temp[x][y].sign_1=3;
						temp[x][y].station=2;
						temp[x][y+1].sign=6;
						temp[x][y+1].sign_1=0;
						temp[x][y+1].station=0;
						ChangDraw(hwnd,y+1,y+2,x,x+1,6,y-1,y+1,x,x+1,3);
						move_flag=1;
					}
				}
				else
					if(temp[x][y-2].sign_1==0)
					{
						temp[x][y-2].sign=3;
						temp[x][y-2].sign_1=3;
						temp[x][y-2].station=1;
						temp[x][y-1].sign=0;
						temp[x][y-1].sign_1=3;
						temp[x][y-1].station=2;
						temp[x][y].sign=6;
						temp[x][y].sign_1=0;
						temp[x][y].station=0;
						ChangDraw(hwnd,y,y+1,x,x+1,6,y-2,y,x,x+1,3);
						move_flag=1;
					}

⌨️ 快捷键说明

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