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

📄 box1.cpp

📁 非常经典的小游戏代码, 推球的,for WindowsCE
💻 CPP
📖 第 1 页 / 共 3 页
字号:
									{0,0,0,0,0,0,0,3,0,3,2,0,4,4,0,3},
									{0,0,0,0,0,0,0,3,0,0,0,5,4,3,0,3},
									{0,0,0,0,0,0,0,3,3,0,2,3,4,5,0,3,3},
									{0,0,0,0,0,0,0,0,3,0,0,2,0,0,2,0,3},
									{0,0,0,0,0,0,0,0,3,1,0,3,3,0,0,0,3},
									{0,0,0,0,0,0,0,0,3,3,3,3,3,3,3,3,3}};
*/
unsigned char  Graph_buf16[10][25] ={{0},
									{0,3,3,3,3,3},
									{0,3,0,0,0,3,3,3,3,3},
									{0,3,0,3,2,0,4,4,0,3},
									{0,3,0,0,0,5,4,3,0,3},
									{0,3,3,0,2,3,4,5,0,3,3},
									{0,0,3,0,0,2,0,0,2,0,3},
									{0,0,3,1,0,3,3,0,0,0,3},
									{0,0,3,3,3,3,3,3,3,3,3}};
/*
unsigned char  Graph_buf18[10][25] ={{0},
									{0,0,0,0,0,3,3,3,3,3,3,3,0,3,3,3,3,3},
									{0,0,0,0,0,3,0,0,3,0,0,3,3,3,0,0,0,3},
									{0,0,0,0,0,3,0,1,0,2,0,0,0,0,0,2,0,3},
									{0,0,0,0,0,3,0,0,3,3,4,3,3,2,3,0,3,3},
									{0,0,0,0,0,3,0,2,0,4,5,4,4,4,0,0,3,3},
									{0,0,0,0,0,3,0,3,0,3,4,3,0,3,2,3,3,3},
									{0,0,0,0,0,3,0,0,0,2,0,0,0,0,0,3},
									{0,0,0,0,0,3,3,3,3,3,3,3,3,0,0,3},
									{0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3}};
*/
unsigned char  Graph_buf17[10][25] ={{0},
									{3,3,3,3,3,3,3,0,3,3,3,3,3},
									{3,0,0,3,0,0,3,3,3,0,0,0,3},
									{3,0,1,0,2,0,0,0,0,0,2,0,3},
									{3,0,0,3,3,4,3,3,2,3,0,3,3},
									{3,0,2,0,4,5,4,4,4,0,0,3,3},
									{3,0,3,0,3,4,3,0,3,2,3,3,3},
									{3,0,0,0,2,0,0,0,0,0,3},
									{3,3,3,3,3,3,3,3,0,0,3},
									{0,0,0,0,0,0,0,3,3,3,3}};

static TBBUTTON tbButton[] = {
	{0, 0,         TBSTATE_ENABLED, TBSTYLE_SEP,    0,0,0,0},
	{0, IDC_START, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0,0,0},
	{1, IDC_PRV,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0,0,1},
	{2, IDC_NEXT,  TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0,0,2},
	{3, IDC_UNDO,  TBSTATE_ENABLED, TBSTYLE_BUTTON, 0,0,0,3},
};


CARR  carrier;
/********************************************************
     typedef struct {
     unsigned char x;           //coordinates of the carr in one page;
     unsigned char y;
     unsigned char last_x;
     unsigned char last_y;
     unsigned char direction;
     unsigned char action_num_U;
     unsigned char action_num_D;
     unsigned char action_num_L;
     unsigned char action_num_R;
     unsigned char undo_flag;
  } CARR;
*********************************************************/


int WINAPI WinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance, 
				   LPWSTR    lpCmdLine,
			       int       nCmdShow)
/*---------------------------------------------------------------------------*\
 * 
\*---------------------------------------------------------------------------*/
{
	MSG msg;

	InitCommonControls();  //common dll load

	if (!hPrevInstance) {
        if (!InitApplication(hInstance)) {
            return FALSE;
        }
    }

    if (!InitInstance(hInstance, nCmdShow)) {
        return FALSE;
    }

	while (GetMessage(&msg, NULL, 0, 0)) {
		if (!IsCommandBarMessage(hwndCB, &msg)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	
	return msg.wParam;

} /* WinMain()
   */


BOOL InitApplication(HINSTANCE hInstance)
/*---------------------------------------------------------------------------*\
 * 
\*---------------------------------------------------------------------------*/
{
	WNDCLASS wc;

    LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
    LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
	wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
    wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
    wc.cbClsExtra    = 0;                       // No per-class extra data.
    wc.cbWndExtra    = 0;                       // No per-window extra data.
    wc.hInstance     = hInstance;               // Owner of this class
	wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
	wc.hCursor       = NULL;
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName  = NULL;					// Menu name from .RC
    wc.lpszClassName = szAppName;               // Name to register as

	return RegisterClass(&wc);

} /* InitApplication()
   */


BOOL CreateCommandBar(HWND hwnd)
/*---------------------------------------------------------------------------*\
 * 
\*---------------------------------------------------------------------------*/
{
	HICON		hIcon;
	HWND		hwndCB;

	// register the 16x16 icon for displaying on the taskbar.	
	hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1),
							 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	SendMessage(hwnd, WM_SETICON, FALSE, (WPARAM)hIcon);

	// create the command bar firstly.
	if (hwndCB = CommandBar_Create(hInst, hwnd, 1)) 
	{
		// Now add some strings to be displayed on the buttons	
		SendMessage(hwndCB, TB_ADDSTRING, (WPARAM)hInst,
					MAKELONG(IDS_NEW,  0));
	    SendMessage(hwndCB, TB_ADDSTRING, (WPARAM)hInst,
					MAKELONG(IDS_PREV, 0));
		SendMessage(hwndCB, TB_ADDSTRING, (WPARAM)hInst,
					MAKELONG(IDS_NEXT, 0));
		SendMessage(hwndCB, TB_ADDSTRING, (WPARAM)hInst,
					MAKELONG(IDS_UNDO, 0));

		// Add the bitmaps we want to use.
	    CommandBar_AddBitmap(hwndCB, hInst, IDB_NEW,
		                     1, 16, 16);
		CommandBar_AddBitmap(hwndCB, hInst, IDB_PREV,
		                     1, 16, 16);
		CommandBar_AddBitmap(hwndCB, hInst, IDB_NEXT,
		                     1, 16, 16);
		CommandBar_AddBitmap(hwndCB, hInst, IDB_UNDO,
		                     1, 16, 16);

		CommandBar_InsertMenubar(hwndCB, hInst, IDM_MAIN_MENU, 0);

		// Add the command buttons
		CommandBar_AddButtons(hwndCB, sizeof(tbButton)/sizeof(TBBUTTON),
							  tbButton);
		
		// Finally add the exit and help button adornments
		CommandBar_AddAdornments(hwndCB, /*STD_HELP*/0, IDM_EXIT);
	}
	
	return (hwndCB != NULL);

} /* CreateCommandBar()
   */


BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
/*---------------------------------------------------------------------------*\
 * 
\*---------------------------------------------------------------------------*/
{
	hInst = hInstance;
#ifdef _WIN32_WCE_EMULATION
	hwndMain = CreateWindow(szAppName, szTitle, 
		                    WS_POPUP,
	                     	0, 0,
							CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
							hInstance, NULL);
#else
	hwndMain = CreateWindow(szAppName, szTitle, 
		                    WS_VISIBLE,
	                     	0, 0,
							CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
							hInstance, NULL);
#endif

	if (!hwndMain) {
        return FALSE;
	}

    ShowWindow(hwndMain, nCmdShow);
	UpdateWindow(hwndMain);	
	
	return TRUE;
	
} /* InitInstance()
   */


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
/*---------------------------------------------------------------------------*\
 * 
\*---------------------------------------------------------------------------*/
{
	PAINTSTRUCT ps;
	HDC			hdc;
	HBITMAP		hTDesktop;
  
	int i;
	int undo_x,undo_y;

	switch (msg) {

		case WM_CREATE:
			 CreateCommandBar(hwnd);
			 hdc=GetDC(hwnd);
		     hTDesktop=CreateCompatibleBitmap(hdc,480,200);
			 idb_temp = IDB_SPACE; 
             for(i=0;i<=12;i++)
             {
			     element[i]=LoadBitmap(hInst,MAKEINTRESOURCE(idb_temp+i));
			 }
			 ReleaseDC(hwnd,hdc);
			 break;

        case WM_HELP:
		     break;
			 
		case WM_PAINT:
			 hdc = BeginPaint(hwnd, &ps);
		     if(init_flag == 0)
			 {
				GraphInit(hdc);
				CarrInit(hdc);
			 }
			 if(init_flag == 1)
				GraphUpdate(hdc);
		     EndPaint(hwnd, &ps);
			 break;

        case WM_KEYDOWN:
			 undo_num = 0;
			 init_flag = 1;
			 hdc=GetDC(hwnd);
			 switch(wp)
			 {
			  case VK_UP:
		  		   MoveBox(hdc,carrier.x,carrier.y,carrier.x,carrier.y-1);
				   break;
			  case VK_DOWN:
				   MoveBox(hdc,carrier.x,carrier.y,carrier.x,carrier.y+1);
				   break;
			  case VK_LEFT:
				   MoveBox(hdc,carrier.x,carrier.y,carrier.x-1,carrier.y);
				   break;
			  case VK_RIGHT:
				   MoveBox(hdc,carrier.x,carrier.y,carrier.x+1,carrier.y);
				   break;
			  case VK_SPACE:
				   if((undo_num==0)&&(carrier.undo_flag!=0))
				  {
					hdc=GetDC(hwnd);
					if(carrier.direction==Up)
						 undo_x = 0; undo_y = 1;
					if(carrier.direction==Dn)
						 undo_x = 0; undo_y = -1;
					if(carrier.direction==Lt)
						 undo_x = 1; undo_y = 0;
					if(carrier.direction==Rt)
						 undo_x = -1;undo_y = 0;

				    MoveUndo(hdc,undo_x,undo_y);
				    ReleaseDC(hwnd,hdc);
					SetFocus(hwnd);			 //Add for menu bug.
				  }
				   break; 
			  default:
				   break;
			}
			 ReleaseDC(hwnd,hdc);
             break;

		case WM_LBUTTONDOWN:
			 break;
       
		case WM_MOUSEMOVE:
			 break;
  
		case WM_LBUTTONUP:
			 break;

		case WM_COMMAND:
			 switch (GET_WM_COMMAND_ID(wp,lp))
			{ 
			 case IDC_ABOUT:
		     	  DialogBox (hInst, MAKEINTRESOURCE(IDD_ABOUT), hwndMain,(DLGPROC)AboutCleaner);
				  break;
             case IDC_PLAY: 
                  DialogBox (hInst, MAKEINTRESOURCE(IDD_PLAY), hwndMain, (DLGPROC)HowPlay); 
				  break;
			 case IDC_SELECT:
				  pass_flag=0;
    			  hdc=GetDC(hwnd);
				  bGO=TRUE;
				  DialogBox (hInst, MAKEINTRESOURCE(IDD_SELECT), hwndMain,(DLGPROC)SelectRoom);
				  PatBlt(hdc,0,MENUTOP,480,200,WHITENESS); 
				  if(init_flag == 0)
				  {
					GraphInit(hdc);
					CarrInit(hdc);
				  }
				  if(init_flag == 1)
					 GraphUpdate(hdc);
				  ReleaseDC(hwnd,hdc);
				  SetFocus(hwnd);
				  break; 
			 case IDC_UNDO:
//				  SendMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
				  if((undo_num==0)&&(carrier.undo_flag!=0))
				  {
					hdc=GetDC(hwnd);
					if(carrier.direction==Up)
						 undo_x = 0; undo_y = 1;
					if(carrier.direction==Dn)
						 undo_x = 0; undo_y = -1;
					if(carrier.direction==Lt)
						 undo_x = 1; undo_y = 0;
					if(carrier.direction==Rt)
						 undo_x = -1;undo_y = 0;

				    MoveUndo(hdc,undo_x,undo_y);
				    ReleaseDC(hwnd,hdc);
				  }
				  SetFocus(hwnd);			 //Add for menu bug.
		 		  break;
	
    		 case IDC_START:
				  pass_flag=0; 
			      hdc=GetDC(hwnd);
				  bGO=TRUE;
				  PatBlt(hdc,0,MENUTOP,480,200,WHITENESS);
		          GraphInit(hdc);
                  CarrInit(hdc);
				  ReleaseDC(hwnd,hdc);
				  SetFocus(hwnd);
				  init_flag = 0;
				  break;
             case IDC_PRV:
				  pass_flag=0;
				  nRoom --;
				  if(nRoom == 0)
					 nRoom = 1;
				  hdc=GetDC(hwnd);
				  bGO=TRUE;
				  PatBlt(hdc,0,MENUTOP,480,200,WHITENESS);
		          GraphInit(hdc);
                  CarrInit(hdc);
				  ReleaseDC(hwnd,hdc);

⌨️ 快捷键说明

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