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

📄 bomb.c

📁 MINI GUI1.6X源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    hmnu = CreateMenu();    memset (&mii, 0, sizeof(MENUITEMINFO));    mii.type        = MFT_STRING;    mii.id          = 100;    mii.typedata    = (DWORD)"Start";    mii.hsubmenu    = createpmenustart();    InsertMenuItem(hmnu, 0, TRUE, &mii);    mii.type        = MFT_STRING;    mii.id          = 110;    mii.typedata    = (DWORD)"Level";    mii.hsubmenu    = createpmenulevel();    InsertMenuItem(hmnu, 1, TRUE, &mii);        mii.type        = MFT_STRING;    mii.id          = 120;    mii.typedata    = (DWORD)"About";    mii.hsubmenu    = createpmenuabout();    InsertMenuItem(hmnu, 2, TRUE, &mii);                       return hmnu;}void BothButtonDownProc(HWND hWnd,int adrx,int adry)      {    int test_open = 0;     int i = 1;    int adrx1 = 0, adry1 = 0;    int flag_opened = 1;    if (!bom[adrx][adry].test)    return;    if (!bom[adrx][adry].value)    return;    if (bom[adrx][adry].hit)    return;    while (i <= 8)    {       switch (i)       {        case 1:           adrx1 = adrx-1;           adry1 = adry;        break;                                case 2:           adrx1 = adrx-1;           adry1 = adry-1;        break;        case 3:           adrx1 = adrx-1;           adry1 = adry+1;        break;                case 4:           adrx1 = adrx;           adry1 = adry-1;        break;                case 5:            adrx1 = adrx;            adry1 = adry+1;        break;                case 6:            adrx1 = adrx+1;            adry1 = adry;         break;                 case 7:            adrx1 = adrx+1;            adry1 = adry+1;        break;                 case 8:            adrx1 = adrx+1;            adry1 = adry-1;        break;       }              if (adrx1>=0 && adry1>=0 && adrx1<sg_boxnumx && adry1<sg_boxnumy                            && bom[adrx1][adry1].hit)           test_open++;       else            if(adrx>=0 && adry1>=0 && adrx1<sg_boxnumx && adry1<sg_boxnumy                            && !bom[adrx1][adry1].test)                flag_opened = 0;                   i++;    }    if ((test_open == bom[adrx][adry].value) && !flag_opened)    {        if (!Open (hWnd, adrx, adry))            BombOut (hWnd);        if (itime == (sg_boxnumx*sg_boxnumy-bombnum))            Finished(hWnd);                 }            }void DrawDigit(HDC hdc, char* buffer, int CLOCK){    int x;    PBITMAP bmp;        if (CLOCK)        x = x_clock;    else        x = x_bomnum;            while(*buffer){        bmp = sg_bmpDigit + (*buffer - '0');        FillBoxWithBitmap(hdc, x, 0, 0, 0, bmp);        x += WIDTH_DIGIT;        buffer++;    }    }static int myLoadBitmap (BITMAP* bm, const char* filename){	char full_path [MAX_PATH + 1];	strcpy (full_path, "res/");    strcat (full_path, filename);	return LoadBitmap (HDC_SCREEN, bm, full_path);}static char* get_record_file (void){	static char record_file [MAX_PATH + 1] = {'\0'};	if (record_file [0] != '\0')		return record_file;	strcpy (record_file, getpwuid (getuid ()) ->pw_dir);	if (record_file [strlen (record_file) - 1] != '/')		strcat (record_file, "/");	strcat (record_file, ".highscore.bomb");		return record_file;}int TestMyWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    HDC hdc;    char  bomn[30], seconds[30];    char  buffer[256];    int i, j;    int ran1, ran2;    static RECT bombregion, face, onerect, bombnumber, clock;     static RECT winposition;    MAINWINCREATE  CreateInfo;    FILE* pHighscore;    switch (message) {              case MSG_CREATE:            if( myLoadBitmap(&bmpbom,"lei.bmp")<0)                fprintf(stderr,"bitmap error\n");            else                fValidbom = TRUE;              if( myLoadBitmap(&bmpface,"face1.bmp")<0)                fprintf(stderr,"bitmap error\n");            else                fValidface = TRUE;                            if( myLoadBitmap(&bitmap1,"face.bmp")<0)                fprintf(stderr,"bitmap error\n");            else                fValid1 = TRUE;                            if( myLoadBitmap(&bmpflag,"flag.bmp")<0)                fprintf(stderr,"bitmap error\n");            else                fValidflag = TRUE;                               if( myLoadBitmap(&bmpfinalface,"finished.bmp")<0)                fprintf(stderr,"bitmap error\n");            else                fValidfinalface = TRUE;                               if( myLoadBitmap(&bmphitfalse,"hitfalse.bmp")<0)                fprintf(stderr,"bitmap error\n");            else                fValidhitfalse = TRUE;                               for (i = 0; i < 10; i++){                sprintf(buffer, "%d.bmp", i);                myLoadBitmap(sg_bmpDigit + i, buffer);            }            if ((pHighscore = fopen(get_record_file(),"r"))){                for (i = 0; i < 3; i++)                    fscanf(pHighscore, "%d, %s",                            &score[i].highscore, score[i].name);                fclose(pHighscore);            }            else                for (i = 0; i < 3; i++){                    score[i].highscore = 999;                    strcpy(score[i].name, "unknown");                }                #ifdef _TIMER_UNIT_10MS            SetTimer(hWnd, ID_CLOCK, 1000/FREQ_CLOCK);#else            SetTimer(hWnd, ID_CLOCK, FREQ_CLOCK);#endif                        PostMessage(hWnd,MSG_COMMAND,ID_NEW,0);        break;        case MSG_COMMAND:            if (LOWORD(wParam) == ID_ABOUT)            {               InitAbHostedCreateInfo(hWnd,&CreateInfo);               CreateMainWindow(&CreateInfo);              }                        if (LOWORD(wParam) == ID_CLOSE)            {                PostMessage(hWnd, MSG_CLOSE, 0, 0);            }                        if (LOWORD(wParam) == ID_HIGHSCORE)            {               InitHighScoreCreateInfo(hWnd,&CreateInfo);               hHighscore =  CreateMainWindow(&CreateInfo);                 ShowWindow(hHighscore,SW_SHOW);             }                        if (LOWORD(wParam) == ID_LARGE)            {                bombnum = 99;                sg_boxnumx = 30;                sg_boxnumy = 16;                winwidth = WIDTH_LARGEWIN;                flag_size = 2;                GetWindowRect(hWnd, &winposition);                MoveWindow(hWnd, winposition.left, winposition.top,                            WIDTH_LARGEWIN, HEIGHT_LARGEWIN, FALSE);                PostMessage(hWnd, MSG_COMMAND, ID_NEW, 0);            }                if (LOWORD(wParam) == ID_MIDDLE)            {                bombnum = 40;                sg_boxnumx = 16;                sg_boxnumy = 16;                winwidth = WIDTH_MIDDLEWIN;                flag_size = 1;                GetWindowRect(hWnd, &winposition);                MoveWindow(hWnd, winposition.left, winposition.top,                            WIDTH_MIDDLEWIN, HEIGHT_MIDDLEWIN, FALSE);                PostMessage(hWnd, MSG_COMMAND, ID_NEW, 0);            }                        if (LOWORD(wParam) == ID_SMALL)            {                bombnum = 10;                sg_boxnumx = 8;                sg_boxnumy = 8;                winwidth = WIDTH_SMALLWIN;                flag_size = 0;                GetWindowRect(hWnd, &winposition);                MoveWindow(hWnd, winposition.left, winposition.top,                            WIDTH_SMALLWIN, HEIGHT_SMALLWIN, FALSE);                PostMessage(hWnd, MSG_COMMAND, ID_NEW, 0);            }                                if (LOWORD(wParam) == ID_NEW)            {                bTimer = FALSE;                second = 0;                itime = 0;                leftbombnum = bombnum;                flag_bombout = 0;                flag_finished = 0;                x_bomnum = winwidth / 6;                x_face = (winwidth*2) / 5;                x_clock = (winwidth*3) / 5;                offsetx = (winwidth - WIDTH_BOX*sg_boxnumx)/2-2;                SetRect (&clock, x_clock, 0,                             x_clock + WIDTH_CLOCK, HEIGHT_CLOCK);                                            SetRect (&face, x_face, 0,                            x_face + WIDTH_FACE, HEIGHT_FACE);                                            SetRect (&bombregion, offsetx, HEIGHT_FACE,                           WIDTH_BOX*sg_boxnumx+offsetx,                           HEIGHT_BOX*sg_boxnumy+HEIGHT_FACE);                                     SetRect (&bombnumber, x_bomnum, 0,                     x_bomnum + WIDTH_BOMNUM, HEIGHT_BOMNUM);                                    //**************initial bom value**************                             for (i = 0; i < sg_boxnumx; i++)                for (j = 0; j < sg_boxnumy; j++)                { bom[i][j].flag  = 0;                  bom[i][j].hit   = FALSE;                  bom[i][j].value = 0;                  bom[i][j].test  = FALSE;                  bom[i][j].bombout = FALSE;                  bom[i][j].error = FALSE;                 };               for (i = 0; i < (sg_boxnumx*sg_boxnumy); i++)                  NoAdr[i].NY = FALSE;                                  srandom( time(NULL));              i = 0;              while( i < bombnum )               {                  ran1 = random()%sg_boxnumx;                  ran2 = random()%sg_boxnumy;                  if(!bom[ran1][ran2].flag)                     {                         bom[ran1][ran2].flag = 1;                        i++;                     }                 } ;                     for (i = 0; i < sg_boxnumx; i++)                           for (j = 0; j < sg_boxnumy; j++)                    {                if (!bom[i][j].flag) {                if(i-1>=0&&j-1>=0&&bom[i-1][j-1].flag)                        bom[i][j].value++;                                        if(i-1>=0&&bom[i-1][j].flag)                        bom[i][j].value++;                                        if(i-1>=0&&j+1<sg_boxnumy&&bom[i-1][j+1].flag)                        bom[i][j].value++;                                        if(j-1>=0&&bom[i][j-1].flag)                        bom[i][j].value++;                                        if(j+1<sg_boxnumy&&bom[i][j+1].flag)                        bom[i][j].value++;                                        if(i+1<sg_boxnumx&&j+1<sg_boxnumy&&bom[i+1][j+1].flag)                        bom[i][j].value++;                                         if(i+1<sg_boxnumx&&bom[i+1][j].flag)                         bom[i][j].value++;                                        if(i+1<sg_boxnumx&&j-1>=0&&bom[i+1][j-1].flag)                        bom[i][j].value++;                }                      }                   InvalidateRect (hWnd, NULL, TRUE);               }        break;                case MSG_TIMER:            if (wParam == ID_CLOCK)                if (bTimer){                    if (second < 1000){                        second++;                        InvalidateRect(hWnd, &clock, FALSE);                    }                }        break;                case MSG_LBUTTONDOWN:            oldx = LOWORD (lParam);            oldy = HIWORD (lParam);            adrx = (oldx-offsetx)/WIDTH_BOX;            adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;                        if (hCongratuate | hHighscore)                break;                            if (!PtInRect (&bombregion, oldx, oldy)) {                if (PtInRect (&face, oldx, oldy)){                    PostMessage (hWnd, MSG_COMMAND, ID_NEW, 0);                    break;                }                    else                    break;            }            if (flag_bombout)                break;            if (flag_finished)                break;            if (!bTimer)                bTimer = TRUE;                            if (bom[adrx][adry].hit)                break;            if (wParam & KS_RIGHTBUTTON) {                BothButtonDownProc(hWnd,adrx,adry);                break;            }                                        if (bom[adrx][adry].test)                break;                            if (bom[adrx][adry].flag) {                BombOut(hWnd);                   break;            }                if (bom[adrx][adry].value != 0)            {                    NoAdr[itime].x  = adrx;                    NoAdr[itime].y  = adry;                    NoAdr[itime].NY = TRUE;                    itime++;                    bom[adrx][adry].test = TRUE;                                        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;                

⌨️ 快捷键说明

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