½üÀ´ºÍÅ®ÅóÓÑÈ¥´òµçÍæ·¢ÏÖÁËÒ»¸öºÜºÃÍæµÄÓÎÏ·¡£¹æ»®ÊÇÓõçÄÔ·¢¸øÄãµÄÅÆ·ÅÔÚÆÁÄ»µÄ¿Õ°×´¦¾¡Á¿Ê¹ËüÃǵĺÍΪ21ÿ¸ö¿Õ°×´¦¿ÉÈë5ÕÅÅÆ¡£ÓÉÓÚ½üÀ´ÔÚѧϰÓÎÏ·ÖÆ×÷£¬¸Ðµ½Õâ¸öÓÎÏ·ÈÝÒ×ʵÏÖ¡£»Ø¼ÒºóÓÃÓÐVC×÷ÁËÆð¡£ÓóÌÐòÀ´×÷ÆË¿ËÓÎÏ·µÄÄѵãÔÚÓÚÈçºÎÈ·¶¨Æ˿˵ÄÃæÖµºÍ»¨É«¡£ÔÚ±¾³ÌÐòÖÐÎÒÊÇ°Ñÿ¸öÆ˿˵ÄͼÏñ°´Ë³ÐòÅÅÁв¢¼ÓÒÔ±àºÅ£¬Æ˿˵Ļ¨É«Í¬ÑùÒ²¼ÓÒÔ±àºÅ¡£²¢ÓÃÒ»¸ö¹«Ê½¼ÆËã±àºÅ´óÓÚ13µÄÆË¿ËͼÏñµÄÃæÖµ¹«Ê½ÈçÏ£ºÆË¿ËͼÏñµÄ±àºÅ-13*ÆË¿Ë»¨É«µÄ±àºÅ¾Í¿ÉÒԵóö¸ÃÆË¿ËͼÏñ±àºÅµÄÆ˿˵ÄÃæÖµ¡£ÀýÈçÆË¿ËͼÏñ±àºÅΪ15£¬»¨É«µÄ±àºÅΪ1Óù«Ê½15-13*1µÃ³ö¸ÃÆË¿ËͼÏñ±àºÅµÄÆ˿˵ÄÃæÖµÊǺìÌÒ2¡£
ÏÖ½«ÊµÏÖ¹ý³Ìд³öÒÔ¡£
ÓÃVC½¨Á¢Ò»¸öWin32 Application¹¤³Ì¡£ÔÚ¹¤³ÌÖмÓÈëstdafx.hÎļþÔÚÆäÖмÓÈë#include<afxwin.h>ºÍ #include<math.h>¡£ÔÚ¹¤³Ì¼ÓÈë×ÊÔ´Îļþ¡£Ê¹ÓÃAlt+F7µ÷³öÉèÖöԻ°¿ò¡£ÔÚGeneralϵÄMicrosoft Foundation ClassesÑ¡Ôñuse MFX inaStatic Libarary¡£Îª¹¤³Ì½¨Á¢Ò»¸ö´°¿ÚÀà¡£ÔÚ´°¿ÚÀàµÄÍ·ÎļþÖаѹ¹Ô캯ÊýÉùÃ÷ÐÞ¸ÄΪpublic£¬ÀýÈ磺protected: cbruceFrame()¸ÄΪpublic:cbruceFrame()¡£ÔÚ´°¿ÚÀàµÄÍ·ÎļþÖж¨Òå±äÁ¿£º
CDC *mdc,*bgmdc; CBitmap *bitmap,*bgmap; RECT rect; CFont newf,*oldf; ×Ô¶¨ÒåÒ»¸öº¯Êý£º
void fp(); Ϊ¹¤³Ì¶¨ÒåÈ«¾ÖÊý×é±äÁ¿:
struct pk //ÆË¿Ë»ù±¾ÐÅÏ¢ { int pkbmp; int h; int f; }pkdata[52];
ÆäÖÐpkbmpÓÃÀ´´æ·ÅÆË¿ËͼÏñ±àºÅ£¬hÓÃÀ´±£´æÆ˿˵Ļ¨É«±àÂë¡¢fÓÃÀ´±£´æ´ËÆË¿ËÊÇ·ñÒ²·¢³ö¹ý¡£ ÆäÖÐÆË¿ËͼÏñ±àºÅ´Ó1--52£¬ÆË¿Ë»¨É«±àÂëºÚΪ0£»ºìÌÒΪ1£»Ã·»¨Îª2£»·½¿éΪ3¡£
struct pkno { int pkbmpo; int ho; }a[5],b[5],c[5],d[5]; Ϊ¹¤³Ì¶¨ÒåÈ«¾Ö±äÁ¿£º
int an=0,bn=0,cn=0,dn=0,ao=0,bo=0,co=0,ddo=0,j,m=3;
ÆäÖкó¼ÓnµÄΪ¸÷¿éµÄ¼ÆÊýÆ÷£¬ºó¼ÓoµÄΪ¸÷¿éµÄ¼Æ·ÖÊý£¬jΪÔÝ´æ±äÁ¿£¬mΪpassµÄ´ÎÊý¡£
¶¨ÒåÁ½¸ö×Ö·ûÊý×飺
f[255],cs[255];
ÔÚ¹¹Ô캯ÊýÖмÓÈëÏÂÃæ³ÌÐò´úÂ룺(cbruceFrame.cppÖÐ)
int i; Create(NULL,"ÆË¿ËÓÎÏ·"); CClientDC dc(this); int width=dc.GetDeviceCaps(HORZRES); //È¡µÃÆÁÄ»Çø¿í int height=dc.GetDeviceCaps(VERTRES); //È¡µÃÆÁÄ»Çø¸ß GetWindowRect(&rect); //È¡µÃ´°¿ÚÇø¾ØÐδóС width=(width-(rect.right-rect.left))/2; height=(height-(rect.bottom-rect.top))/2; MoveWindow(width,height,500,450,true); bgmdc=new CDC; mdc=new CDC; //½¨Á¢ÄÚ´æDC¶ÔÏó bgmap=new CBitmap; ffor(i=1;i<53;i++) { pkdata[i-1].pkbmp=i; if((i-1)<13) pkdata[i-1].h=0;//¸ù¾ÝÆË¿ËͼÏñ±àºÅÉèÖÃÆ˿˵Ļ¨É«±àÂë if((i-1)>=13&&(i-1)<26) pkdata[i-1].h=1; if((i-1)>=26&&(i-1)<39) pkdata[i-1].h=2; if((i-1)>=39&&(i-1)<52) pkdata[i-1].h=3; pkdata[i-1].f=0; }//½«±êÖ¾ÉèΪûÓз¢³ö
bgmdc->CreateCompatibleDC(&dc); mdc->CreateCompatibleDC(&dc); //ת»»³ÉÓëdcÏàÈݵÄDC bgmap->LoadBitmap(BG); bgmdc->SelectObject(bgmap); newf.CreateFont(20,10,0,0,0,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_MODERN,"¿¬Ìå"); /ÉèÖÃ×ÖÌå CPoint *p=new CPoint(50,35); ClientToScreen(p); ::SetCursorPos(p->x,p->y); //ÉèÖÃÊó±êµÄ·¶Î§ srand((unsigned)time(NULL)); ¡¡¡¡//·¢ÅÆ t=rand()%52; bitmap=new CBitmap; bitmap->LoadBitmap(pkdata[t].pkbmp); mdc->SelectObject(bitmap); dc.BitBlt(10,10,100,100,mdc,0,0,SRCCOPY); pkdata[t].f=1; j=(t+1); for(i=0;i<5;i++) { a[i].pkbmpo=c[i].pkbmpo=b[i].pkbmpo=d[i].pkbmpo=0; } ʹÓòåÈë---->н¨ÀཨÁ¢Ó¦ÓóÌÐòÀà,ÔÚClass type¶Ô»°¿òÖÐÑ¡ÔñGeneric ClassÔÚNameÖÐÊäÈëÀàÃû(cbruceApp)ÔÚBase class(es)ÖеÄDerived FromÖÐÊäÈëCWinApp¡£ÔÚcbruceApp.hÎļþÖмÓÈë³ÌÐò³õʼº¯ÊýµÄÉùÃ÷£º
public:BOOL Initinstance(); ÔÚcbruceApp.cppÎļþÖмÓÈëÈçÏ´úÂ룺
cbruceApp bruce; CBruceApp::InitInstance() { m_pMainWnd= new CBruceFrame; m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return true; } ÕâÑù¹¤³ÌµÄ¿ò¼Ü¾Í×齨Íê³ÉÁË¡£ÏÂÒ»²½¼ÓÈë¾ßÌå´úÂë¡£
Ϊ¹¤³Ì¼ÓÈëWM£ßPAINTÏûϢʵÏÖ»æͼ:
oldf=dc.SelectObject(&newf); //Ñ¡ÔñÐÂÐÂ×ÖÌå¡£ dc.SetTextColor(RGB(0,255,0)); //ÉèÖÃÎı¾ÑÕÉ« dc.SetBkColor(1); //ÉèÖñ³¾°ÑÕÉ« GetClientRect(&rect); dc.BitBlt(0,0,rect.right,rect.bottom,bgmdc,0,0,SRCCOPY);//ÔØÈë±³¾°Í¼ dc.BitBlt(10,10,100,100,mdc,0,0,SRCCOPY); //ÔØÈëÆË¿ËͼÏñ dc.BitBlt(10,190,110,190,bgmdc,0,0,WHITENESS); //»æÖÆ¿Õ°×´¦ dc.BitBlt(130,190,110,190,bgmdc,0,0,WHITENESS); dc.BitBlt(250,190,110,190,bgmdc,0,0,WHITENESS); dc.BitBlt(370,190,110,190,bgmdc,0,0,WHITENESS); if(an>0) { int i; for(i=0;i<=an;i++) { if(a[i].pkbmpo!=0) { bitmap=new CBitmap; bitmap->LoadBitmap(a[i].pkbmpo); mdc->SelectObject(bitmap); dc.BitBlt(15,195+i*20,100,100,mdc,0,0,SRCCOPY); } } if(ao==21) { dc.TextOut(5,150,"¹§Ï²ÄúÓ®ÁË!"); } if(ao>21) { dc.TextOut(5,150,"Òѳ¬³ö21·Ö!"); } if(ao<21) { sprintf(f,"Êý·ÖΪ£º%d",ao); dc.TextOut(5,150,f); } } if(bn>0) { int i; for(i=0;i<=bn;i++) { if(b[i].pkbmpo!=0) { bitmap=new CBitmap; bitmap->LoadBitmap(b[i].pkbmpo); mdc->SelectObject(bitmap); dc.BitBlt(135,195+i*20,100,100,mdc,0,0,SRCCOPY); } } if(bo==21) { dc.TextOut(135,150,"¹§Ï²ÄúÓ®ÁË!"); } if(bo>21) { dc.TextOut(135,150,"Òѳ¬³ö21·Ö!"); } if(bo<21) { sprintf(f,"Êý·ÖΪ£º%d",bo); dc.TextOut(135,150,f); } } if(cn>0) { int i; for(i=0;i<=cn;i++) { if(c[i].pkbmpo!=0) { bitmap=new CBitmap; bitmap->LoadBitmap(c[i].pkbmpo); mdc->SelectObject(bitmap); dc.BitBlt(255,195+i*20,100,100,mdc,0,0,SRCCOPY); } } if(co==21) { dc.TextOut(255,150,"¹§Ï²ÄúÓ®ÁË!"); } if(co>21) { dc.TextOut(255,150,"Òѳ¬³ö21·Ö!"); } if(co<21) { sprintf(f,"Êý·ÖΪ£º%d",co); dc.TextOut(255,150,f); } } if(dn>0) { int i; for(i=0;i<=dn;i++) { if(d[i].pkbmpo!=0) { bitmap=new CBitmap; bitmap->LoadBitmap(d[i].pkbmpo); mdc->SelectObject(bitmap); dc.BitBlt(375,195+i*20,100,100,mdc,0,0,SRCCOPY); } } if(ddo==21) { dc.TextOut(375,150,"¹§Ï²ÄúÓ®ÁË!"); } if(ddo>21) { dc.TextOut(375,150,"Òѳ¬³ö21·Ö!"); } if(ddo<21) { sprintf(f,"Êý·ÖΪ£º%d",ddo); dc.TextOut(375,150,f); } } dc.TextOut(150,50,"F2ÖØпªÊ¼ÓÎÏ·!"); sprintf(cs,"ÓÒ¼üPASSµ±Ç°ÅÆ£º%d",m); dc.TextOut(150,100,cs); dc.SelectObject(oldf); Ϊ¹¤³Ì¼ÓÈëWM_LBUTTONDOWNÏûÏ¢:
CClientDC dc(this); //½¨Á¢¿Í»§ÇøDC int zn; //ÓÃÀ´´æ·Å×ø±ê oldf=dc.SelectObject(&newf); dc.SetTextColor(RGB(0,255,0)); dc.SetBkColor(1); zn=(int)floor(point.x/10); //¼ÆËã×÷±êÖµ if(zn<=11) //ÔÚµÚÒ»¸ö¿Õ°×´¦ { if((ao<21)&&(an<5)) { bitmap=new CBitmap; //¼ÓÔØÆË¿ËͼÏñ bitmap->LoadBitmap(pkdata[t].pkbmp); dc.BitBlt(15,195+an*20,100,100,mdc,0,0,SRCCOPY); a[an].pkbmpo=j; //ÆË¿ËÃæÖµ ao=j-(13*pkdata[t].h))+ao; //¼ÆËã·ÖÊý if(ao==21) { dc.TextOut(5,150,"¹§Ï²ÄúÓ®ÁË!"); } if(ao>21) { dc.TextOut(5,150,"Òѳ¬³ö21·Ö!"); } if(ao<21) { sprintf(f,"Êý·ÖΪ£º%d",ao); dc.TextOut(5,150,f); an++; } fp(); } else { Beep(150,100);¡¡¡¡¡¡//´íÎ󱨾¯ } }
if(zn>11&&zn<=23) { if((bo<21)&&(bn<5)) { bitmap=new CBitmap; bitmap->LoadBitmap(pkdata[t].pkbmp); mdc->SelectObject(bitmap); dc.BitBlt(135,195+bn*20,100,100,mdc,0,0,SRCCOPY); b[bn].pkbmpo=j; bo=j-(13*pkdata[t].h))+bo; if(bo==21) { dc.TextOut(135,150,"¹§Ï²ÄúÓ®ÁË!"); } if(bo>21) { dc.TextOut(135,150,"Òѳ¬³ö21·Ö!"); } if(bo<21) { sprintf(f,"Êý·ÖΪ£º%d",bo); dc.TextOut(135,150,f); bn++; } fp(); } else { Beep(150,100); } }
if(zn>23&&zn<=35) { if((co<21)&&(cn<5)) { bitmap=new CBitmap; bitmap->LoadBitmap(pkdata[t].pkbmp); dc.BitBlt(255,195+cn*20,100,100,mdc,0,0,SRCCOPY); c[cn].pkbmpo=j; co=j-(13*pkdata[t].h))+co; if(co==21) { dc.TextOut(255,150,"¹§Ï²ÄúÓ®ÁË!"); } if(co>21) { dc.TextOut(255,150,"Òѳ¬³ö21·Ö!"); } if(co<21) { sprintf(f,"Êý·ÖΪ£º%d",co); dc.TextOut(255,150,f); cn++; } fp(); } else { Beep(150,100); }
}
if(zn>35&&zn<=47) { if((ddo<21)&&(dn<5)) { bitmap=new CBitmap; bitmap->LoadBitmap(pkdata[t].pkbmp); mdc->SelectObject(bitmap); dc.BitBlt(375,195+dn*20,100,100,mdc,0,0,SRCCOPY); d[dn].pkbmpo=j; ddo=j-(13*pkdata[t].h)+ddo; if(ddo==21) { dc.TextOut(375,150,"¹§Ï²ÄúÓ®ÁË!"); } if(ddo>21) { dc.TextOut(375,150,"Òѳ¬³ö21·Ö!"); } if(ddo<21) { sprintf(f,"Êý·ÖΪ£º%d",ddo); dc.TextOut(375,150,f); dn++; } fp(); } else { Beep(150,100); } } Ϊ¹¤³Ì¼ÓÈëWM_KEYDOWNÏûÏ¢:
CClientDC dc(this); int i; if(nChar==VK_F2) //µ±Íæ¼Ò°´ÏÂF2¼üʱ£¬ÖØпªÊ¼ÓÎÏ·¡£Ê¹Ö®¸´Î»¡£ { oldf=dc.SelectObject(&newf); dc.SetTextColor(RGB(0,255,0)); dc.SetBkColor(1); GetClientRect(&rect); dc.BitBlt(0,0,rect.right,rect.bottom,bgmdc,0,0,SRCCOPY); dc.BitBlt(10,10,100,100,mdc,0,0,SRCCOPY); dc.BitBlt(10,190,110,190,bgmdc,0,0,WHITENESS); dc.BitBlt(130,190,110,190,bgmdc,0,0,WHITENESS); dc.BitBlt(250,190,110,190,bgmdc,0,0,WHITENESS); dc.BitBlt(370,190,110,190,bgmdc,0,0,WHITENESS); an=bn=cn=dn=0; ao=bo=co=ddo=0; for(i=0;i<52;i++) { pkdata[i].f=0; } srand((unsigned)time(NULL)); //·¢ÅÆ t=rand()%52; bitmap=new CBitmap; bitmap->LoadBitmap(pkdata[t].pkbmp); mdc->SelectObject(bitmap); dc.BitBlt(10,10,100,100,mdc,0,0,SRCCOPY); pkdata[t].f=1; j=(t+1); m=3; dc.TextOut(150,50,"F2ÖØпªÊ¼ÓÎÏ·!"); sprintf(cs,"ÓÒ¼üPASSµ±Ç°ÅÆ£º%d",m); dc.TextOut(150,100,cs); for(i=0;i<5;i++) { a[i].pkbmpo=c[i].pkbmpo=b[i].pkbmpo=d[i].pkbmpo=0; } } dc.SelectObject(oldf); Ϊ¹¤³Ì¼ÓÈëWM_RBUTTONDOWNÏûÏ¢(PASSµ±Ç°ÅÆ):
CClientDC dc(this); oldf=dc.SelectObject(&newf); dc.SetTextColor(RGB(0,255,0)); dc.SetBkColor(1); if(m>0) { fp(); m--; sprintf(cs,"ÓÒ¼üPASSµ±Ç°ÅÆ£º%d",m); dc.TextOut(150,100,cs); } else { Beep(150,100); } dc.SelectObject(oldf); ±à¼fpº¯Êý(·¢ÅÆ):
CClientDC dc(this); srand((unsigned)time(NULL));
loop1: t=rand()%52; if(pkdata[t].f!=1) { bitmap=new CBitmap; bitmap->LoadBitmap(pkdata[t].pkbmp); mdc->SelectObject(bitmap); dc.BitBlt(10,10,100,100,mdc,0,0,SRCCOPY); pkdata[t].f=1; j=(t+1); } else { goto loop1; } ÕâÑùÒ»¸öСµÄÆË¿ËÓÎÏ·¾Í³ÉÍê¡£ÎÒ²»²¢²»ÊÇʲôÃûУ±ÏÒµµÄ¡£Ò²Ã»ÓÐÉϹý´óѧ¡£Ö»ÊÇ×Ô¼º·Ç³£Ï²»¶±à³Ì£¬Ò»Çж¼ÊÇ×ÔѧµÄ¡£ËùÒÔÓдíÎóµÄµØ·½Çë´ó¼ÒÖ¸³ö¡£×îºóÎÒÏë˵¾ä»°£ºÐËȤÊÇÄã×îºÃµÄÀÏʦ£¬Ã»ÓÐÐËȤÄãÊÇѧ²»ºÃÒ»Ñù¶«Î÷¡£±à³Ì²¢Ã»ÓÐʲôÄÑ£¬Ö»ÒªÅ¬Á¦ÄãÒ²Äܱà³öºÃµÄ³ÌÐòÀ´µÄ¡£ ±¾³ÌÐòÔÚWindows 2000+VC6.0ÖбàÒëͨ¹ý¡£
|