資源簡介
自己寫的俄羅斯方塊游戲,用C語言,WIN32框架,學習C語言,游戲編寫思路

代碼片段和文件信息
#include
struct?Boarder?
{
bool?Have[15][10];
int??Per_WidthPer_Height;
int??Width_ExHeight_Ex;
};
struct?Boarder?boarder;
struct?Shape
{
bool?Have[4][4];
????int?xy;
};
struct?Shape?shapes[19];
struct?Shape?shape;
HDC?hdc;
HWND?hwnd;
RECT?wndrect;
char?title[10]=“Game“;
int?direct;
int?shape_num;
float?last_time;
float?now_time;
void?Init();
void?clearscreen();
void?Draw();
void?TestLeft();
void?TestBottom();
void?TestDisappear();
void?TestChange();
LRESULT?Windowproc(HWNDUINTWPARAMLPARAM);
int?APIENTRY?WinMain(HINSTANCE?hInstance?HINSTANCE?hPrevInstance?LPSTR?lpcmdLineint?nCmdShow)
{
MSG?msg;
WNDCLASS?wc;
????wc.style?=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc?=?(WNDPROC)Windowproc;
wc.cbWndExtra?=0;
wc.cbClsExtra?=0;
wc.hInstance?=?hInstance;
wc.hIcon?=NULL;
wc.hCursor?=NULL;
wc.hbrBackground?=(HBRUSH)GetStockobject(BLACK_BRUSH);
wc.lpszClassName?=title;
wc.lpszMenuName?=NULL;
if?(!hInstance)
{
return?0;
}
RegisterClass(&wc);
hwnd=CreateWindow(titletitleWS_OVERLAPPEDWINDOW00800600NULLNULLhInstanceNULL);
if(!hwnd)
{
return?0;
}
ShowWindow(hwndnCmdShow);
UpdateWindow(hwnd);
Init();
while?(1)
{
if?(PeekMessage(&msgNULL00PM_REMOVE))
{
if?(msg.message?==WM_QUIT)??????break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
now_time=(float)timeGetTime();
if(now_time>last_time+400)
{
last_time=now_time;
clearscreen();
Draw();
TestDisappear();
TestBottom();
TestLeft();
TestChange();
}
}
}
??return?0;
}
LRESULT?Windowproc(HWND?hwnd?UINT?message?WPARAM?wParam?LPARAM?lParam)
{
switch?(message)
{
case?WM_DESTROY:
PostQuitMessage(0);
return?1;
case?WM_KEYDOWN:
{
switch?(wParam)
{
case?VK_ESCAPE:
PostMessage(hwndWM_CLOSE00);
break;
case?VK_LEFT:
direct=?1;
break;
case?VK_RIGHT:
direct=?2;
break;
case?VK_UP:
direct=?3;
break;
}
break;
}
}
return?DefWindowProc(hwndmessagewParamlParam);
}
void?TestBottom()
{
int?ij;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shape.Have[i][j]?&&?shape.y+i?==14)
{
for(int?p?=0;p<4;p++)
{
for(int?q=0;q<4;q++)
{
if(shape.Have[p][q])
{
boarder.Have[shape.y?+p][shape.x?+q]=true;
}
}
}
shape_num=rand()%19;
shape=shapes[shape_num];//換shape記錄
return;
}
if(shape.Have[i][j]?&&?boarder.Have[shape.y?+i+1][shape.x+j])
{
for(int?p?=0;p<4;p++)
{
for(int?q=0;q<4;q++)
{
if(shape.Have[p][q])
{
boarder.Have[shape.y?+p][shape.x?+q]=true;
}
}
}
shape_num=rand()%19;
shape=shapes[shape_num];
return;
}
}
}
shape.y?+=1;
}
void?Init()
{
int?ij;
hdc=GetDC(hwnd);
GetWindowRect(hwnd&wndrect);
direct=0
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????196658??2013-05-19?10:47??els3\Debug\els3.exe
?????文件?????212728??2013-05-19?10:47??els3\Debug\els3.ilk
?????文件????3557688??2013-05-19?10:44??els3\Debug\els3.pch
?????文件?????377856??2013-05-19?10:47??els3\Debug\els3.pdb
?????文件??????27768??2013-05-19?10:44??els3\Debug\main.obj
?????文件?????140288??2013-05-19?10:48??els3\Debug\vc60.idb
?????文件??????77824??2013-05-19?10:44??els3\Debug\vc60.pdb
?????文件???????3933??2013-05-19?10:47??els3\els3.dsp
?????文件????????516??2013-05-19?10:43??els3\els3.dsw
?????文件??????41984??2013-05-19?10:48??els3\els3.ncb
?????文件??????48640??2013-05-19?10:48??els3\els3.opt
?????文件????????754??2013-05-19?10:47??els3\els3.plg
?????文件???????9616??2013-05-19?10:44??els3\main.cpp
?????目錄??????????0??2013-05-19?10:52??els3\Debug
?????目錄??????????0??2013-05-19?10:52??els3
-----------?---------??----------?-----??----
??????????????4696253????????????????????15
評論
共有 條評論