俄罗斯方块代码.docx

上传人:b****1 文档编号:14355712 上传时间:2023-06-22 格式:DOCX 页数:22 大小:19.30KB
下载 相关 举报
俄罗斯方块代码.docx_第1页
第1页 / 共22页
俄罗斯方块代码.docx_第2页
第2页 / 共22页
俄罗斯方块代码.docx_第3页
第3页 / 共22页
俄罗斯方块代码.docx_第4页
第4页 / 共22页
俄罗斯方块代码.docx_第5页
第5页 / 共22页
俄罗斯方块代码.docx_第6页
第6页 / 共22页
俄罗斯方块代码.docx_第7页
第7页 / 共22页
俄罗斯方块代码.docx_第8页
第8页 / 共22页
俄罗斯方块代码.docx_第9页
第9页 / 共22页
俄罗斯方块代码.docx_第10页
第10页 / 共22页
俄罗斯方块代码.docx_第11页
第11页 / 共22页
俄罗斯方块代码.docx_第12页
第12页 / 共22页
俄罗斯方块代码.docx_第13页
第13页 / 共22页
俄罗斯方块代码.docx_第14页
第14页 / 共22页
俄罗斯方块代码.docx_第15页
第15页 / 共22页
俄罗斯方块代码.docx_第16页
第16页 / 共22页
俄罗斯方块代码.docx_第17页
第17页 / 共22页
俄罗斯方块代码.docx_第18页
第18页 / 共22页
俄罗斯方块代码.docx_第19页
第19页 / 共22页
俄罗斯方块代码.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

俄罗斯方块代码.docx

《俄罗斯方块代码.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块代码.docx(22页珍藏版)》请在冰点文库上搜索。

俄罗斯方块代码.docx

俄罗斯方块代码

#include"stdafx.h"

#include

#include"resource.h"

#defineMAX_LOADSTRING100

#defineUNIT_SIZE15//模块单元大小

#defineSQUARE_AMOUNT17//窗体中模块单元的数目

#defineWM_NEWSQUAREWM_USER+1//自定义消息

#defineMYTIMER1//自定义时钟标示

#defineDIFLEVEL500//难易度,即时钟间隔

//GlobalVariables:

HINSTANCEhInst;//currentinstance

TCHARszTitle[MAX_LOADSTRING];//Thetitlebartext

TCHARszWindowClass[MAX_LOADSTRING];//Thetitlebartext

//Fowarddeclarationsoffunctionsincludedinthiscodemodule:

ATOMMyRegisterClass(HINSTANCEhInstance);

BOOLInitInstance(HINSTANCE,int);

LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);

LRESULTCALLBACKAbout(HWND,UINT,WPARAM,LPARAM);

typedefstruct_Square

{

POINTps[4];

HWNDhUnitWnd[4];

inttype;

}Square,*pSquare;

intAPIENTRYWinMain(HINSTANCEhInstance,

HINSTANCEhPrevInstance,

LPSTRlpCmdLine,

intnCmdShow)

{

//TODO:

Placecodehere.

MSGmsg;

HACCELhAccelTable;

//Initializeglobalstrings

LoadString(hInstance,IDS_APP_TITLE,szTitle,MAX_LOADSTRING);

LoadString(hInstance,IDC_I_GOV1,szWindowClass,MAX_LOADSTRING);

MyRegisterClass(hInstance);

//Performapplicationinitialization:

if(!

InitInstance(hInstance,nCmdShow))

{

returnFALSE;

}

hAccelTable=LoadAccelerators(hInstance,(LPCTSTR)IDC_I_GOV1);

//Mainmessageloop:

while(GetMessage(&msg,NULL,0,0))

{

if(!

TranslateAccelerator(msg.hwnd,hAccelTable,&msg))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

returnmsg.wParam;

}

ATOMMyRegisterClass(HINSTANCEhInstance)

{

WNDCLASSEXwcex;

wcex.cbSize=sizeof(WNDCLASSEX);

wcex.style=CS_HREDRAW|CS_VREDRAW;

wcex.lpfnWndProc=(WNDPROC)WndProc;

wcex.cbClsExtra=0;

wcex.cbWndExtra=0;

wcex.hInstance=hInstance;

wcex.hIcon=LoadIcon(hInstance,(LPCTSTR)IDI_I_GOV1);

wcex.hCursor=LoadCursor(NULL,IDC_ARROW);

wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);

wcex.lpszMenuName=(LPCSTR)IDC_I_GOV1;

wcex.lpszClassName=szWindowClass;

wcex.hIconSm=LoadIcon(wcex.hInstance,(LPCTSTR)IDI_SMALL);

returnRegisterClassEx(&wcex);

}

BOOLInitInstance(HINSTANCEhInstance,intnCmdShow)

{

HWNDhWnd;

hInst=hInstance;//Storeinstancehandleinourglobalvariable

hWnd=CreateWindow(szWindowClass,szTitle,WS_CAPTION|WS_SYSMENU,

CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);

if(!

hWnd)

{

returnFALSE;

}

ShowWindow(hWnd,nCmdShow);

UpdateWindow(hWnd);

returnTRUE;

}

LRESULTCALLBACKWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam)

{

intwmId,wmEvent;

PAINTSTRUCTps;

HDChdc;

TCHARszHello[MAX_LOADSTRING];

LoadString(hInst,IDS_HELLO,szHello,MAX_LOADSTRING);

staticRECTrc;

staticBOOLIsFilled[SQUARE_AMOUNT][SQUARE_AMOUNT];

staticHWNDhWndSquare[SQUARE_AMOUNT][SQUARE_AMOUNT];

staticSquaresq;

inti,j;

intxFirstUnitPos=SQUARE_AMOUNT/2;

staticHMENUhMenu;

switch(message)

{

caseWM_CREATE:

rc.left=rc.top=0;

rc.right=rc.bottom=UNIT_SIZE*SQUARE_AMOUNT;

AdjustWindowRect(&rc,WS_CAPTION|WS_SYSMENU,TRUE);

SetWindowPos(hWnd,NULL,0,0,rc.right-rc.left,

rc.bottom-rc.top,SWP_NOMOVE);

break;

caseWM_TIMER:

//是否不能再往下落了

for(i=0;i<4;i++)

{

if(IsFilled[sq.ps[i].x][sq.ps[i].y]==1)

{

KillTimer(hWnd,MYTIMER);

MessageBox(hWnd,"你已失败","注意",MB_OK);

PostMessage(hWnd,WM_DESTROY,0,0);

return0;

}

if(sq.ps[i].y==SQUARE_AMOUNT-1||IsFilled[sq.ps[i].x][sq.ps[i].y+1]==TRUE)

{

for(j=0;j<4;j++)//填充方块所占的区域

{

IsFilled[sq.ps[j].x][sq.ps[j].y]=TRUE;

hWndSquare[sq.ps[j].x][sq.ps[j].y]=sq.hUnitWnd[j];

}

KillTimer(hWnd,MYTIMER);

//消去方块

//浏览,产生记录条

{//procedure

unsignedintflag=0;

for(i=SQUARE_AMOUNT-1;i>=0;i--)//yshaft

{

for(j=0;j

if(!

IsFilled[j][i])

break;

if(j==SQUARE_AMOUNT)

flag|=1l<

}

if(flag)//有行要消掉

{

for(i=SQUARE_AMOUNT-1;i>=0;i--)

if(flag&1l<

for(j=0;j

{

DestroyWindow(hWndSquare[j][i]);

IsFilled[j][i]=FALSE;

}

for(i=SQUARE_AMOUNT-1;i>=0;i--)

if(!

(flag&1l<

{

inttemp,offset;

temp=i+1;

offset=0;

while(temp

{

if(flag&1l<

offset++;

temp++;

}

for(j=0;j

{

RECTrcUnit;

if(IsFilled[j][i])

{GetWindowRect(hWndSquare[j][i],&rcUnit);

POINTpt;

pt.x=rcUnit.left;

pt.y=rcUnit.top;

ScreenToClient(hWnd,&pt);

MoveWindow(hWndSquare[j][i],

pt.x,pt.y+offset*UNIT_SIZE,

UNIT_SIZE,UNIT_SIZE,TRUE);

IsFilled[j][i]=FALSE;

IsFilled[j][i+offset]=TRUE;

hWndSquare[j][i+offset]=hWndSquare[j][i];

}

}

}

}

}//procedure

SendMessage(hWnd,WM_NEWSQUARE,NULL,NULL);

return0;

}

}

//移动方块

for(i=0;i<4;i++)

{

//_beginthread();

MoveWindow(sq.hUnitWnd[i],sq.ps[i].x*UNIT_SIZE,

(++sq.ps[i].y)*UNIT_SIZE,UNIT_SIZE,UNIT_SIZE,TRUE);

}

break;

caseWM_NEWSQUARE:

//生成方块

srand((unsigned)time(NULL));

switch(rand()%6)

{

/*@@@@*/

case0:

sq.type=0;

xFirstUnitPos=8;

for(i=0;i<4;i++)

{

sq.ps[i].x=xFirstUnitPos+i;

sq.ps[i].y=0;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,0,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

break;

/*@

@@@*/

case1:

sq.type=1;

for(i=0;i<4;i++)

{

if(0==i)

{

sq.ps[i].x=xFirstUnitPos;

sq.ps[i].y=0;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,sq.ps[i].y,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

else

{

sq.ps[i].x=xFirstUnitPos+i-1;

sq.ps[i].y=1;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,sq.ps[i].y,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

}

break;

/*@@

@@*/

case2:

sq.type=2;

for(i=0;i<4;i++)

{

if(i==0||i==1)

{

sq.ps[i].x=xFirstUnitPos+i;

sq.ps[i].y=0;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,0,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

else

{

sq.ps[i].x=xFirstUnitPos+i-2;

sq.ps[i].y=1;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,0,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

}

break;

/*@

@@@*/

case3:

sq.type=3;

for(i=0;i<4;i++)

{

if(i==0)

{

sq.ps[i].x=xFirstUnitPos+1;

sq.ps[i].y=0;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,0,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

else

{

sq.ps[i].x=xFirstUnitPos+i-1;

sq.ps[i].y=1;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,0,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

}

break;

/*@@

@@*/

case4:

sq.type=4;

for(i=0;i<4;i++)

{

if(i==0||i==1)

{

sq.ps[i].x=xFirstUnitPos+i;

sq.ps[i].y=0;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,0,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

else

{

sq.ps[i].x=xFirstUnitPos+i-1;

sq.ps[i].y=1;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,0,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

}

break;

/*@@

@@*/

case5:

sq.type=5;

for(i=0;i<4;i++)

{

if(i==0||i==1)

{

sq.ps[i].x=xFirstUnitPos+i+1;

sq.ps[i].y=0;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,0,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

else

{

sq.ps[i].x=xFirstUnitPos+i-2;

sq.ps[i].y=1;

sq.hUnitWnd[i]=CreateWindow("BUTTON",

NULL,WS_VISIBLE|WS_CHILD,sq.ps[i].x*UNIT_SIZE,0,

UNIT_SIZE,UNIT_SIZE,hWnd,NULL,hInst,NULL);

}

}

break;

}

SetTimer(hWnd,MYTIMER,DIFLEVEL,NULL);

break;

caseWM_KEYDOWN:

switch(wParam)

{

caseVK_LEFT:

for(i=0;i<4;i++)

{

if(sq.ps[i].x-1<0||IsFilled[sq.ps[i].x-1][sq.ps[i].y]==TRUE)

return0;

}

for(i=0;i<4;i++)

MoveWindow(sq.hUnitWnd[i],--sq.ps[i].x*UNIT_SIZE,

sq.ps[i].y*UNIT_SIZE,UNIT_SIZE,UNIT_SIZE,TRUE);

break;

caseVK_RIGHT:

for(i=0;i<4;i++)

{

if(sq.ps[i].x+1>SQUARE_AMOUNT-1||

IsFilled[sq.ps[i].x+1][sq.ps[i].y]==TRUE)

return0;

}

for(i=0;i<4;i++)

MoveWindow(sq.hUnitWnd[i],++sq.ps[i].x*UNIT_SIZE,

sq.ps[i].y*UNIT_SIZE,UNIT_SIZE,UNIT_SIZE,TRUE);

break;

caseVK_DOWN:

SendMessage(hWnd,WM_TIMER,0,0);

break;

caseVK_SPACE:

//方块变形

intshaft;

switch(sq.type)//确定每个方块的中轴方向

{

/*@@@@*/

case0:

shaft=1;

break;

/*@

@@@*/

case1:

shaft=1;

break;

/*@@

@@*/

case2:

re

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2