ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:19.17KB ,
资源ID:6806523      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6806523.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(俄罗斯方块.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

俄罗斯方块.docx

1、俄罗斯方块#ifndef block_h#define block_hint shape744=0,1,5,9,2,4,5,6,0,4,8,9,0,1,2,4,0,1,4,8,0,1,2,6,1,5,8,9,0,4,5,6,0,1,5,6,1,4,5,8,0,1,5,6,1,4,5,8,1,2,4,5,0,4,5,9,1,2,4,5,0,4,5,9,1,4,5,6,0,4,5,8,0,1,2,5,1,4,5,9,0,1,4,5,0,1,4,5,0,1,4,5,0,1,4,5,0,1,2,3,0,4,8,12,0,1,2,3,0,4,8,12;#endif函数声明: #ifndef functi

2、on_h#define function_hLRESULT CALLBACK WndProc(HWND hwnd,UINT mesage,WPARAM wParam, LPARAM lParam);void Draw_shape(HWND hwnd,int shape_num,int shape_direction,POINT position,COLORREF color);void Draw_block(HWND hwnd,POINT block,COLORREF color);void Init_map();void New_shape(HWND hwnd);void Down_shap

3、e(HWND hwnd);void Right_shape(HWND hwnd);void Left_shape(HWND hwnd);void Change_direction(HWND hwnd);bool Downable();bool Rightable();bool Leftable();bool Changeable();void Update_map();int Full_row();void Clean_full_row(HWND hwnd,int row);void Pause();void Draw_edge(HWND hwnd);void Pre_to_cur(HWND

4、hwnd);bool Over();void Show_over(HWND hwnd);void Init_frame(HWND hwnd);void Show_score(HWND hwnd);void Show_level(HWND hwnd);void Change_level(HWND hwnd);void Show_preview(HWND hwnd);#endif主程序: # include# include# includeblock.h# includefunction.hint block_size = 15;/小方块边长POINT cur_pos = 8,1;/图形当前坐标

5、int cur_shape_num = 0;/图形当前号码int cur_shape_direction = 0;/图形当前方向 方向表示同种图形内部的变形变化int pre_shape_num = 0;int pre_shape_direction = 0;#define X_max 20/画图区域宽度#define Y_max 30/画图区域高度int mapY_maxX_max;/画图区域坐标系COLORREF shape_color = RGB(0,200,200);/图形颜色COLORREF bg_color = RGB(150,20,20);/背景颜色COLORREF edge_c

6、olor = RGB(0,100,100);int score = 0;int level = 1;int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, PSTR szCmdLine, int iCmdShow)const int caption_height=GetSystemMetrics(SM_CYCAPTION);/标题栏高度const int frame_height=GetSystemMetrics(SM_CYFRAME);/窗口边框高度const int frame_width=GetSystemMetri

7、cs(SM_CXFRAME);/窗口侧边栏宽度static TCHAR classname=TEXT(classname);MSG msg;HWND hwnd;WNDCLASS wc;wc.style= CS_HREDRAW | CS_VREDRAW;wc.lpfnWndProc= WndProc;wc.cbClsExtra= 0;wc.cbWndExtra= 0;wc.hInstance= hInstance;wc.hIcon= LoadIcon(NULL,IDI_APPLICATION);wc.hCursor= LoadCursor(NULL,IDC_ARROW);wc.hbrBackgr

8、ound= CreateSolidBrush(bg_color); ;wc.lpszMenuName= NULL;wc.lpszClassName= classname;if(!RegisterClass(&wc)MessageBox(NULL,TEXT(需要windowsNT),TEXT(出错啦!),MB_OK|MB_ICONERROR);return 0;hwnd = CreateWindow(classname,TEXT(俄罗斯方块_林语),WS_SYSMENU,500,200,(frame_width*2)+(X_max+5)*block_size),/+5用于显示预览,得分,等级(f

9、rame_height*2)+(caption_height)+(Y_max*block_size),NULL,NULL,hInstance,NULL);ShowWindow(hwnd,iCmdShow);/UpdateWindow(hwnd);while(GetMessage(&msg,NULL,0,0)TranslateMessage(&msg);DispatchMessage(&msg);return msg.wParam;LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam)switch

10、(message)case WM_CREATE:Init_map();break;case WM_PAINT:Init_frame(hwnd);New_shape(hwnd);Pre_to_cur(hwnd);Draw_shape(hwnd,cur_shape_num,cur_shape_direction,cur_pos,shape_color);SetTimer(hwnd,1,1000/level,NULL);break;case WM_TIMER:Down_shape(hwnd);break;case WM_KEYDOWN:switch(wParam)case VK_UP:Change_

11、direction(hwnd);break;case VK_DOWN:Down_shape(hwnd);break;case VK_LEFT:Left_shape(hwnd);break;case VK_RIGHT:Right_shape(hwnd);break;case VK_SPACE:Pause();break;break;case WM_CLOSE:KillTimer(hwnd,1);PostQuitMessage(0);break;return DefWindowProc(hwnd,message,wParam,lParam);/*void Draw_shape(HWND hwnd,

12、int shape_num,int shape_direction,POINT position,COLORREF color)/图形号、方向以及左上角坐标、颜色/画图形POINT block;for(int i=0;i4;+i)block.x = position.x + shapeshape_numshape_directioni % 4;block.y = position.y + shapeshape_numshape_directioni / 4;Draw_block(hwnd,block,color);void Draw_block(HWND hwnd,POINT block,CO

13、LORREF color)/小方块左上角坐标及颜色/画小方块RECT rc;SetRect(&rc,block.x * block_size + 1,/作+1 、-1的调整是为了使得方块之间有间隙block.y * block_size + 1,(block.x + 1) * block_size - 1,(block.y + 1) * block_size - 1);HDC hdc = GetDC(hwnd);HBRUSH brush = (HBRUSH)CreateSolidBrush(color);FillRect(hdc,&rc,brush);DeleteObject(brush);R

14、eleaseDC(hwnd,hdc);void Init_map()/构造一个开口朝上的半包围结构作为边界for(int i = 0;i Y_max;i+)for(int j = 0;j X_max;j+)mapij = 0;/将边界初始化为1表明此处不可被覆盖for(i = 0;i Y_max;i+)mapi0 = 1;mapiX_max-1 = 1;for(i = 0;i X_max;i+)mapY_max-1i = 1;void Init_frame(HWND hwnd)/初始化界面,画出方框和信息Draw_edge(hwnd);HDC hdc = GetDC(hwnd);HPEN hp

15、en = CreatePen(PS_SOLID,2,shape_color);SelectObject(hdc,hpen);TCHAR prev = 预览:;/previewTextOut(hdc,X_max*block_size,block_size,prev,strlen(prev);TCHAR sco = 得分:;/scoreTextOut(hdc,X_max*block_size,10*block_size,sco,strlen(sco);Show_score(hwnd);TCHAR lev = 等级:;/levelTextOut(hdc,X_max*block_size,20*blo

16、ck_size,lev,strlen(lev);Show_level(hwnd);DeleteObject(hpen);ReleaseDC(hwnd,hdc);void New_shape(HWND hwnd)/随机生成预览图形并显示srand(unsigned)time(NULL);pre_shape_num = rand() % 7;pre_shape_direction = 0;Show_preview(hwnd);void Pre_to_cur(HWND hwnd)/将预览图形变为将要出现的图形,并生成新的预览图形cur_shape_num = pre_shape_num;cur_sh

17、ape_direction = pre_shape_direction;cur_pos.x = 8;cur_pos.y = 1;New_shape(hwnd);void Down_shape(HWND hwnd)/处理图形下移if(!Downable()/如果不可以下移、Update_map();/在坐标系中记录if(Over()/判断是否结束KillTimer(hwnd,1);Show_over(hwnd);return;int row;while(row = Full_row()/是否有满行Clean_full_row(hwnd,row);Pre_to_cur(hwnd);/产生新的图形D

18、raw_shape(hwnd,cur_shape_num,cur_shape_direction,cur_pos,shape_color);return;Draw_shape(hwnd,cur_shape_num,cur_shape_direction,cur_pos,bg_color);/消除原来的痕迹cur_pos.y += 1;/图形的纵坐标+1Draw_shape(hwnd,cur_shape_num,cur_shape_direction,cur_pos,shape_color);/画出下降后的图形void Right_shape(HWND hwnd)/处理右移if(!Rightab

19、le()return;Draw_shape(hwnd,cur_shape_num,cur_shape_direction,cur_pos,bg_color);cur_pos.x += 1;Draw_shape(hwnd,cur_shape_num,cur_shape_direction,cur_pos,shape_color);void Left_shape(HWND hwnd)/处理左移if(!Leftable()return;Draw_shape(hwnd,cur_shape_num,cur_shape_direction,cur_pos,bg_color);cur_pos.x -= 1;

20、Draw_shape(hwnd,cur_shape_num,cur_shape_direction,cur_pos,shape_color);void Change_direction(HWND hwnd)/变形处理if(!Changeable()return;Draw_shape(hwnd,cur_shape_num,cur_shape_direction,cur_pos,bg_color);cur_shape_direction += 1;cur_shape_direction %= 4;Draw_shape(hwnd,cur_shape_num,cur_shape_direction,c

21、ur_pos,shape_color);bool Downable()/判断是否可以向下POINT down_pos,block_pos;down_pos.x = cur_pos.x;down_pos.y = cur_pos.y + 1;for(int i = 0;i 4;i+)/分别检查图形中的4个小块是否会与下方重叠block_pos.x = down_pos.x + shapecur_shape_numcur_shape_directioni % 4;block_pos.y = down_pos.y + shapecur_shape_numcur_shape_directioni / 4

22、;if(mapblock_pos.yblock_pos.x = 1)return false;return true;bool Rightable()/判断是否可以向右POINT down_pos,block_pos;down_pos.x = cur_pos.x + 1;down_pos.y = cur_pos.y;for(int i = 0;i 4;i+)/分别检查图形中的4个小块是否会与右方重叠block_pos.x = down_pos.x + shapecur_shape_numcur_shape_directioni % 4;block_pos.y = down_pos.y + shapecur_shape_numcur_shape_directioni / 4;if(mapblock_pos.yblock_pos.x = 1)return false;return true;bool Leftable()/判断是否可以向左POINT down_pos,block_pos;down_pos.x = cur_pos.x - 1;down_pos.y = cur_pos.y;for(int i = 0;i 4;i+)/分别检查图形中的4个小块是否会与左方重叠block_pos.x = down_pos.x + shapecur_shape_numcur_s

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1