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

📄 bomb.c

📁 minigui 1.6.10 游戏例子 能对编程有很大启发
💻 C
📖 第 1 页 / 共 3 页
字号:
                    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);             }             else {                    hdc = GetClientDC(hWnd);                    SearchGround (hdc, adrx, adry);                    ReleaseDC(hdc);             }                          if (itime == (sg_boxnumx*sg_boxnumy - bombnum))                Finished(hWnd);                     break;        case MSG_RBUTTONDOWN:           //  SetCapture (hWnd);             oldx = LOWORD (lParam);             oldy = HIWORD (lParam);             adrx = (oldx-offsetx)/WIDTH_BOX;             adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;              if (!PtInRect (&bombregion, oldx, oldy))                break;            if (flag_bombout)                break;            if (flag_finished)                break;                            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| WS_DLGFRAME;    pCreateInfo->dwExStyle = WS_EX_NONE;    pCreateInfo->spCaption=pmessagebox[1];    pCreateInfo->hMenu = createmenu1();    pCreateInfo->hCursor = GetSystemCursor(0);    pCreateInfo->hIcon = 0;    pCreateInfo->MainWindowProc = TestMyWinProc;    pCreateInfo->lx = 512 -WIDTH_LARGEWIN/2;    pCreateInfo->ty = 384 -HEIGHT_LARGEWIN/2;    pCreateInfo->rx =pCreateInfo->lx+ WIDTH_LARGEWIN;    pCreateInfo->by =pCreateInfo->ty+ 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;    for (i = 1; i < args; i++) {        if (strcmp (arg[i], "-layer") == 0) {            layer = arg[i + 1];            //break;        }        else if( strcmp( arg[i], "-lang") == 0)             lang = arg[i+1];    }    //GetLayerInfo (layer, NULL, NULL, NULL);    if (JoinLayer (layer, arg[0], 0, 0) == INV_LAYER_HANDLE) {        printf ("JoinLayer: invalid layer handle.\n");        exit (1);    }#endif    if(strcasecmp(lang,"zh_cn")==0){        printf("\nlanguage=%s",lang);        pmain_menu =main_menu_cn;        pstart_menu =start_menu_cn;        pabout_menu =about_menu_cn;        plevel_menu =level_menu_cn;        pmessagebox =messagebox_cn;        printf("\n2language=%s",lang);    }    else if(strcasecmp(lang,"zh_tw")==0){        pmain_menu =main_menu_tw;        pstart_menu =start_menu_tw;        pabout_menu =about_menu_tw;        plevel_menu =level_menu_tw;        pmessagebox =messagebox_tw;    }    else if(strcasecmp(lang,"en")==0){        pmain_menu =main_menu_en;        pstart_menu =start_menu_en;        pabout_menu =about_menu_en;        plevel_menu =level_menu_en;        pmessagebox =messagebox_en;    }    init_minesweeper();    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);    }    release_minesweeper();    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, pmessagebox[2]);             TextOut (hdc, 10, 55,                 pmessagebox[3]);            TextOut (hdc, 10, 75,                 pmessagebox[4]);            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 = pmessagebox[5] ;    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",                        pmessagebox[6],                        WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,                        IDC_RESET,                        100, 145, 60, 26, hWnd, 0);                                    hOK    = CreateWindow ("button",                        pmessagebox[7],                        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);            SelectFont(hdc,utf8_font);            TextOut(hdc, 130, 15, pmessagebox[8]);            TextOut(hdc, 15, 45, pmessagebox[9] );            TextOut(hdc, 15, 75, pmessagebox[10] );            TextOut(hdc, 15, 105,pmessagebox[11] );            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 = pmessagebox[12];    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",                          pmessagebox[13],                          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",                          pmessagebox[7],                          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_KEYDOWN:        //Finished(hWnd);        break;    case MSG_SIZECHANGING:    {        const RECT* rc = (const RECT*)wParam;        RECT* rrc = (RECT*)lParam;        rrc->left = rc->left;        rrc->top = rc->top;        rrc->right = rc->left + 205;        rrc->bottom = rc->top + 140;    }        return 0;        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 =  pmessagebox[14];    pCreateInfo->hMenu = 0;    pCreateInfo->hCursor   = GetSystemCursor(0);    pCreateInfo->hIcon = 0;    pCreateInfo->MainWindowProc = CongratulationWinProc;    pCreateInfo->lx = 250;     pCreateInfo->ty = 260;    pCreateInfo->rx = 455;    pCreateInfo->by = 400;    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 + -