玩(看你有多色)這個游戲的絕竅
C++ 游戲 (看你有多色) 代碼
/*看你有多色小游戲
*
*曙光2014年11月19日16:18
*/
#include<stdlib.h>
#include<string.h>
#include<Windows.h>
#ifndef_T
#ifdefUNICODE
#define_T(str)L##str
#el
#define_T(str)str
#endif//UNICODE
#endif//_T
#if!__STDC_WANT_SECURE_LIB__
#definestrcpy_s(DstText,TextLen,SrcText)strcpy(DstText,SrcText)
#definestrcat_s(DstText,TextLen,SrcText)strcat(DstText,SrcText)
#define_itoa_s(Val,Text,TextLen,Radix)itoa(Val,Text,Radix)
#endif
//全局變量
HWNDMainWindow;//主窗口
intTruthX,TruthY;//正確答案坐標
intArraySize,Level;//顏色塊矩陣邊長、級別
COLORREFColorDef,ColorTruth;//默認顏色與正確答案顏色
//畫矩形
BOOLPolyRect(HDChdc,LONGleft,LONGtop,LONGwidth,LONGhight){
POINTpoint[4];
point[0].x=left;
point[0].y=top;
point[1].x=left+width;
point[1].y=top;
point[2].x=left+width;
point[2].y=top+hight;
point[3].x=left;
point[3].y=top+hight;
returnPolygon(hdc,point,4);
}
//重繪窗口事件
voidPaintWindow(void){
HBRUSHhBrush,hOldBrush;
PAINTSTRUCTps;
HDChdc;
RECTrect;
intx,y;
doublew,h;
ArraySize=ArraySize<2?2:ArraySize;
GetClientRect(MainWindow,&rect);
hdc=BeginPaint(MainWindow,&ps);
hBrush=CreateSolidBrush(ColorDef);
hOldBrush=(HBRUSH)SelectObject(hdc,hBrush);
w=(double)(rect.right-rect.left)/ArraySize;
h=(double)(rect.bottom-rect.top)/ArraySize;
for(x=0;x<ArraySize;++x){
for(y=0;y<ArraySize;++y){
PolyRect(hdc,(LONG)w*x,(LONG)h*y,(LONG)w-1,(LONG)h-1);
}
}
hBrush=CreateSolidBrush(ColorTruth);
DeleteObject(SelectObject(hdc,hBrush));
PolyRect(hdc,(LONG)w*TruthX,(LONG)h*TruthY,(LONG)w-1,(LONG)h-1);
SelectObject(hdc,hOldBrush);
DeleteObject(hBrush);
EndPaint(MainWindow,&ps);
}
//新游戲
voidNewGame(intlev){
BYTEr,g,b;
chartext[1024];
if(lev>100){
MessageBox(MainWindow,_T("您已經通關了,在下佩服!"),_T("通關提示"),0);
}
lev=lev<1||lev>100?1:lev;
ArraySize=lev/10+2;
Level=lev;
TruthX=rand()%ArraySize;
TruthY=rand()%ArraySize;
r=rand()&0x7f;
g=rand()&0x7f;
b=rand()&0x7f;
ColorDef=RGB(r,g,b);
ColorTruth=RGB(r+51-lev/2,g+51-lev/2,b+51-lev/2);
InvalidateRect(MainWindow,NULL,TRUE);
strcpy_s(text,sizeof(text),"看你有多色-第");
_itoa_s(lev,text+strlen(text),4,10);
strcat_s(text,sizeof(text),"關");
SetWindowTextA(MainWindow,text);
}
//點擊事件響應
voidWindowClick(intx,inty){
chartext[1024];
RECTrect;
doublew,h;
GetClientRect(MainWindow,&rect);
w=(double)(rect.right-rect.left)/ArraySize;
h=(double)(rect.bottom-rect.top)/ArraySize;
x=x/(int)w;
y=y/(int)h;
if(x==TruthX&&y==TruthY){
NewGame(Level+1);
}el{
strcpy_s(text,sizeof(text),"你點錯了哦,正確答案:");
_itoa_s(TruthX+1,text+strlen(text),3,10);
strcat_s(text,sizeof(text),",");
_itoa_s(TruthY+1,text+strlen(text),3,10);
MessageBoxA(MainWindow,text,"重新開始",0);
NewGame(1);
}
}
//窗口消息響應
LRESULTCALLBACKWndProc(HWNDhWnd,UINTuMsg,WPARAMwParam,LPARAMlParam){
switch(uMsg){
caWM_DESTROY://窗口銷毀
PostQuitMessage(0);
break;
caWM_SIZE://窗口大小被改變
InvalidateRect(hWnd,NULL,TRUE);
break;
caWM_PAINT://重繪窗口
PaintWindow();
break;
caWM_LBUTTONDOWN://鼠標左鍵按下
WindowClick(LOWORD(lParam),HIWORD(lParam));
break;
default:
returnDefWindowProc(hWnd,uMsg,wParam,lParam);
}
return0;
}
//入口函數
intWINAPIWinMain(HINSTANCEhInstance,HINSTANCE/*hPrevInstance*/,LPSTR/*lpCmdLine*/,intnCmdShow){
WNDCLASSEXwce;
MSGmsg;
//注冊窗口類
wce.cbSize=sizeof(wce);
wce.style=0;
wce.lpfnWndProc=(WNDPROC)WndProc;//窗口消息處理函數
wce.cbClsExtra=wce.cbWndExtra=0;
wce.hInstance=hInstance;
wce.hCursor=LoadCursor(NULL,IDC_ARROW);
wce.hbrBackground=(HBRUSH)COLOR_BTNSHADOW;
wce.hIcon=wce.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
wce.lpszClassName=_T("ShuGuang");
wce.lpszMenuName=NULL;
RegisterClassEx(&wce);
MainWindow=CreateWindowEx(0,_T("ShuGuang"),_T("看你有多色"),WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(MainWindow,nCmdShow);
UpdateWindow(MainWindow);
srand(GetTickCount());
NewGame(1);
//消息循環
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
returnmsg.wParam;
}
水平有限,可以參考 呵呵
一種找不同顏色的游戲叫什么名字
微信小游戲看你有多色用c++寫出來,這段代碼是什么意思?
在很多漢字中找岀不一樣的字哪個是什么游戲
1、《找不同》;
2、猜字游戲是一款益智游戲,喜歡玩具有挑戰性單詞游戲的你就可以來體驗一下了,給你一個字母板。嘗試通過想象相鄰字母的單詞;
3、您將獲得一個分數,根據您使用的字母,你已經使用了多少個字母,并以這些字母相關聯的任何修飾符都可以的。
html看你有多色設計思路怎么寫
本文發布于:2023-02-28 19:04:00,感謝您對本站的認可!
本文鏈接:http://www.newhan.cn/zhishi/a/167759706951217.html
版權聲明:本站內容均來自互聯網,僅供演示用,請勿用于商業和其他非法用途。如果侵犯了您的權益請與我們聯系,我們將在24小時內刪除。
本文word下載地址:看你有多色 游戲(看你有多色 游戲怎么玩).doc
本文 PDF 下載地址:看你有多色 游戲(看你有多色 游戲怎么玩).pdf
| 留言與評論(共有 0 條評論) |