📄 bomb.c
字号:
if (!bTimer) bTimer = TRUE; /*****RBUTTONDOWN & LBUTTONDOWN******/ if (wParam & KS_LEFTBUTTON){ BothButtonDownProc(hWnd,adrx,adry); break; } /******* only rbuttondown *******/ if (bom[adrx][adry].test) break; if (!bom[adrx][adry].hit ) { bom[adrx][adry].hit = TRUE; leftbombnum--; } else { bom[adrx][adry].hit = FALSE; leftbombnum++; } SetRect (&onerect, adrx*WIDTH_BOX+offsetx, adry*HEIGHT_BOX+HEIGHT_FACE, (adrx+1)*WIDTH_BOX+offsetx, (adry+1)*HEIGHT_BOX+HEIGHT_FACE); InvalidateRect (hWnd, &onerect, FALSE); InvalidateRect (hWnd, &bombnumber, FALSE); break; case MSG_RBUTTONUP: break; case MSG_LBUTTONUP: break; case MSG_PAINT: hdc = BeginPaint (hWnd); sprintf(seconds, "%03d", second); DrawDigit(hdc, seconds, TRUE); if (leftbombnum >= 0){ sprintf(bomn,"%02d",leftbombnum); DrawDigit(hdc, bomn, FALSE); } if (flag_finished) DrawMyBitmap (hdc, fValidfinalface?&bmpfinalface:NULL, x_face+1, 1, 0, 0); else if (flag_bombout) DrawMyBitmap (hdc, fValidface?&bmpface:NULL, x_face, 0, 0, 0); else DrawMyBitmap(hdc, fValid1?&bitmap1:NULL, x_face, 0, 0, 0); for (i = 0; i < sg_boxnumx; i++) for (j = 0; j < sg_boxnumy; j++) { if (!bom[i][j].test && !bom[i][j].bombout){ SetPenColor (hdc,COLOR_darkgray); Rectangle(hdc, i*WIDTH_BOX+offsetx, j*HEIGHT_BOX+HEIGHT_FACE, (i+1)*WIDTH_BOX+offsetx, (j+1)*HEIGHT_BOX+HEIGHT_FACE); Draw3DUpThickFrame (hdc, i*WIDTH_BOX+1+offsetx, j*HEIGHT_BOX+1+HEIGHT_FACE, (i+1)*WIDTH_BOX+offsetx, (j+1)*HEIGHT_BOX+HEIGHT_FACE, COLOR_lightgray); } if ( bom[i][j].hit) DrawMyBitmap(hdc, fValidflag?&bmpflag:NULL, i*WIDTH_BOX+offsetx+3, j*HEIGHT_BOX+3+HEIGHT_FACE, WIDTH_BOX - 5, HEIGHT_BOX - 5); if (bom[i][j].error) { Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx, j*HEIGHT_BOX+HEIGHT_FACE, WIDTH_BOX,HEIGHT_BOX); DrawMyBitmap(hdc, fValidhitfalse?&bmphitfalse:NULL, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE, 0, 0); } if (bom[i][j].bombout) { Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx, j*HEIGHT_BOX+HEIGHT_FACE, WIDTH_BOX,HEIGHT_BOX); DrawMyBitmap(hdc, fValidbom?&bmpbom:NULL, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE, 0, 0); } } for ( i = 0; i < itime; i++ ) { Cancel3DFrame(hdc,(NoAdr[i].x)*WIDTH_BOX+offsetx, (NoAdr[i].y)*HEIGHT_BOX+HEIGHT_FACE, WIDTH_BOX, HEIGHT_BOX); if(NoAdr[i].NY) TextValue(hdc,(NoAdr[i].x)*WIDTH_BOX+offsetx, (NoAdr[i].y)*HEIGHT_BOX+HEIGHT_FACE, bom[NoAdr[i].x][NoAdr[i].y].value); } EndPaint (hWnd, hdc); return 0; case MSG_CLOSE: UnloadBitmap(&bmpbom); UnloadBitmap(&bmpface); UnloadBitmap(&bitmap1); UnloadBitmap(&bmpfinalface); UnloadBitmap(&bmphitfalse); UnloadBitmap(&bmpflag); KillTimer(hWnd, ID_CLOCK); for (i = 0; i < 10; i++) UnloadBitmap(sg_bmpDigit + i); DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_VISIBLE; pCreateInfo->dwExStyle = WS_EX_NONE; pCreateInfo->spCaption="Bomb Game "; pCreateInfo->hMenu = createmenu1(); pCreateInfo->hCursor = GetSystemCursor(0); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = TestMyWinProc; pCreateInfo->lx = 0; pCreateInfo->ty = 0; pCreateInfo->rx = WIDTH_LARGEWIN; pCreateInfo->by = HEIGHT_LARGEWIN; pCreateInfo->iBkColor = COLOR_lightgray; pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = HWND_DESKTOP;}#ifdef _LITE_VERSIONint MiniGUIMain(int args, const char* arg[])#elsevoid* TestMyWindow(void* data) #endif{ MSG Msg; MAINWINCREATE CreateInfo; HWND hMainWnd;#if defined(_LITE_VERSION) && !(_STAND_ALONE) int i; const char* layer = NULL; RECT max_rect = {0, 0, 0, 0}; for (i = 1; i < args; i++) { if (strcmp (arg[i], "-layer") == 0) { layer = arg[i + 1]; break; } } GetLayerInfo (layer, &max_rect, NULL, NULL, NULL); if (JoinLayer (layer, arg[0], max_rect.left, max_rect.top, max_rect.left + 1024, max_rect.top + 768) == INV_LAYER_HANDLE) { printf ("JoinLayer: invalid layer handle.\n"); exit (1); }#endif InitMyWinCreateInfo(&CreateInfo); hMainWnd = CreateMainWindow(&CreateInfo); if (hMainWnd == HWND_INVALID)#ifdef _LITE_VERSION return 0;#else return NULL;#endif ShowWindow(hMainWnd,SW_SHOWNORMAL); while( GetMessage(&Msg, hMainWnd) ) { TranslateMessage (&Msg); DispatchMessage(&Msg); } MainWindowThreadCleanup(hMainWnd);#ifdef _LITE_VERSION return 0;#else return NULL;#endif}#ifndef _LITE_VERSIONint MiniGUIMain(int args, const char* arg[]){#ifdef _IME_GB2312 GBIMEWindow (HWND_DESKTOP);#endif TestMyWindow (NULL); return 0;}#endif/********** create a hosted about window****/int AbHostedWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ switch (message) { case MSG_CREATE: break; case MSG_PAINT: { HDC hdc; hdc = BeginPaint (hWnd); SetBkColor(hdc,COLOR_lightgray); TextOut (hdc, 10, 25, "Bomb Game Ver 1.0 (2000/04/11)"); TextOut (hdc, 10, 55, "Author: Mis. Zheng Xiang (xiang_zi@263.net)."); TextOut (hdc, 10, 75, " Mis. Glory (glory@263.net)."); EndPaint (hWnd, hdc); } return 0; case MSG_CLOSE: DestroyMainWindow (hWnd); return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}void InitAbHostedCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION | WS_VISIBLE; pCreateInfo->dwExStyle = WS_EX_NONE; pCreateInfo->spCaption = "The about window" ; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = GetSystemCursor(0); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = AbHostedWinProc; pCreateInfo->lx = 100; pCreateInfo->ty = 200; pCreateInfo->rx = 540; pCreateInfo->by = 390; pCreateInfo->iBkColor = COLOR_lightgray; pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = hHosting;}/*************************** High Scores Window ******************************/#define IDC_RESET 110int HighScoreWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ static HWND hRESET, hOK; switch (message) { case MSG_CREATE: hRESET = CreateWindow ("button", "Reset", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, IDC_RESET, 100, 145, 60, 26, hWnd, 0); hOK = CreateWindow ("button", "Ok", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, IDOK, 220, 145, 60, 26, hWnd, 0); break; case MSG_COMMAND: { int id = LOWORD(wParam); FILE* pHighscore; int i; if (id == IDC_RESET && HIWORD(wParam) == BN_CLICKED) { for (i = 0; i < 3; i++){ score[i].highscore = 999; strcpy(score[i].name, "unknown"); } if ((pHighscore = fopen(get_record_file(), "w+"))){ for (i = 0; i < 3; i++) fprintf(pHighscore, "%d, %s\n", score[i].highscore,score[i].name); fclose(pHighscore); } InvalidateRect(hWnd, NULL, TRUE); } if (id == IDOK && HIWORD(wParam) == BN_CLICKED) PostMessage(hWnd, MSG_CLOSE, 0, 0); } break; case MSG_PAINT: { HDC hdc; char buffer[50]; int i; hdc = BeginPaint (hWnd); SetBkColor(hdc,COLOR_lightgray); TextOut(hdc, 130, 15, "Heroes"); TextOut(hdc, 15, 45, "SMALL" ); TextOut(hdc, 15, 75, "MIDDLE" ); TextOut(hdc, 15, 105, "LARGE" ); for (i = 0; i < 3; i++){ sprintf(buffer, "%3d %s", score[i].highscore, score[i].name); TextOut(hdc, 150, 45+i*30, buffer); } EndPaint (hWnd, hdc); } return 0; case MSG_CLOSE: DestroyWindow (hRESET); DestroyWindow (hOK); DestroyMainWindow (hWnd); hHighscore = HWND_NULL; return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}void InitHighScoreCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION; pCreateInfo->dwExStyle = WS_EX_NONE; pCreateInfo->spCaption = "High Score" ; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = GetSystemCursor(0); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = HighScoreWinProc; pCreateInfo->lx = 100; pCreateInfo->ty = 200; pCreateInfo->rx = 470; pCreateInfo->by = 410; pCreateInfo->iBkColor = COLOR_lightgray; pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = hHosting;}/************************* Congratulation Window *****************************/#define IDC_CTRL_NAME 100int CongratulationWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ static HWND hPrompt, hName, hOK; switch (message) { case MSG_CREATE: hPrompt = CreateWindow ("static", "Please input your name:", SS_SIMPLE | WS_VISIBLE, IDC_STATIC, 10, 10, 185, 24, hWnd, 0); hName = CreateWindow ("edit", getlogin(), WS_CHILD | WS_VISIBLE | WS_BORDER, IDC_CTRL_NAME, 10, 40, 175, 26, hWnd, 0); hOK = CreateWindow ("button", "Ok", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, IDOK, 110, 75, 75, 26, hWnd, 0); break; case MSG_COMMAND: { int id = LOWORD(wParam); FILE* pHighscore; int i; if (id == IDOK && HIWORD(wParam) == BN_CLICKED) { score[flag_size].highscore = second; SendMessage (hName, MSG_GETTEXT, 19, (LPARAM)score[flag_size].name); if ((pHighscore = fopen(get_record_file(), "w+"))){ for (i = 0; i < 3; i++) fprintf(pHighscore, "%d, %s\n", score[i].highscore,score[i].name); fclose(pHighscore); } PostMessage (hWnd, MSG_CLOSE, 0, 0); } } break; case MSG_CLOSE: DestroyWindow (hPrompt); DestroyWindow (hName); DestroyWindow (hOK); DestroyMainWindow (hWnd); hCongratuate = HWND_NULL; return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam);}void InitCongratulationCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo){ pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION | WS_VISIBLE; pCreateInfo->dwExStyle = WS_EX_IMECOMPOSE; pCreateInfo->spCaption = "Congratulation" ; pCreateInfo->hMenu = 0; pCreateInfo->hCursor = GetSystemCursor(0); pCreateInfo->hIcon = 0; pCreateInfo->MainWindowProc = CongratulationWinProc; pCreateInfo->lx = 50; pCreateInfo->ty = 60; pCreateInfo->rx = 255; pCreateInfo->by = 200; pCreateInfo->iBkColor = COLOR_lightgray; pCreateInfo->dwAddData = 0; pCreateInfo->hHosting = hHosting;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -