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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

C语言实战俄罗斯方块子函数.docx

1、C语言实战俄罗斯方块子函数#includeelsfkhead.h/背景数组char g_arrBackGroud2010 = 0 ;char g_arrsqare24 = 0 ;int g_nSqareID = -1;int g_nLine = -1;int g_nList = -1;int g_nScore = 0;void onpaint(HDC hdc)/函数实现 /创建兼容性DC HDC hMemDC = CreateCompatibleDC(hdc);/HMemDC一张纸的编号 HBITMAP hbitmapback= CreateCompatibleBitmap(hdc,500,6

2、00);/创建一张纸 SelectObject(hMemDC, hbitmapback);/将编号与纸关联起来 paintsqare(hMemDC); ShowSqare2(hMemDC); ShowScore(hMemDC); BitBlt(hdc, 0, 0, 500, 600, hMemDC, 0, 0, SRCCOPY);/传递 DeleteObject(hbitmapback);/释放位图 DeleteDC(hMemDC);/释放DCvoid ShowScore(HDC hMemDC) char strScore10 = 0 ; Rectangle(hMemDC, 300, 0, 5

3、00, 600); itoa(g_nScore, strScore,10); TextOut(hMemDC, 400, 10, 得分, strlen(得分); TextOut(hMemDC, 400, 32, strScore, strlen(strScore);void onCreate() srand(unsigned int)time(NULL); CreateRandomSqare(); CopySqareToBack();void paintsqare(HDC hMemDC)int i=0, j = 0; Rectangle(hMemDC, 0, 0, 300, 600); /窗口上

4、的内容,大方块 for (i = 0; i 20; i+) for (j = 0; j 10; j+) if (1 = g_arrBackGroudij) Rectangle(hMemDC, j*30, i*30, j*30+30, i*30+30); /画小格子 int CreateRandomSqare()/创建随机快 int nInedx =rand()%7; switch (nInedx) case 0:g_arrsqare00 = 1, g_arrsqare01 = 1, g_arrsqare02 = 0, g_arrsqare03 = 0; g_arrsqare10 = 0, g_

5、arrsqare11 = 1, g_arrsqare12 = 1, g_arrsqare13 = 0; g_nLine = 0; g_nList = 3; break; case 1:g_arrsqare00 = 0, g_arrsqare01 =1, g_arrsqare02 = 1, g_arrsqare03 = 0; g_arrsqare10 = 1, g_arrsqare11 = 1, g_arrsqare12 = 0, g_arrsqare13 = 0; g_nLine = 0; g_nList = 3; break; case 2:g_arrsqare00 = 1, g_arrsq

6、are01 = 0, g_arrsqare02 = 0, g_arrsqare03 = 0; g_arrsqare10 = 1, g_arrsqare11 = 1, g_arrsqare12 = 1, g_arrsqare13 = 0; g_nLine = 0; g_nList = 3; break; case 3:g_arrsqare00 = 0, g_arrsqare01 = 0, g_arrsqare02 =1, g_arrsqare03 = 0; g_arrsqare10 =1, g_arrsqare11 = 1, g_arrsqare12 = 1, g_arrsqare13 = 0;

7、 g_nLine = 0; g_nList = 3; break; case 4:g_arrsqare00 = 0, g_arrsqare01 = 1, g_arrsqare02 = 0, g_arrsqare03 = 0; g_arrsqare10 = 1, g_arrsqare11 = 1, g_arrsqare12 = 1, g_arrsqare13 = 0; g_nLine = 0; g_nList = 3; break; case 5:g_arrsqare00 = 0, g_arrsqare01 = 1, g_arrsqare02 = 1, g_arrsqare03 = 0; g_a

8、rrsqare10 = 0, g_arrsqare11 = 1, g_arrsqare12 = 1, g_arrsqare13 = 0; g_nLine = 0; g_nList = 4; break; case 6:g_arrsqare00 = 1, g_arrsqare01 = 1, g_arrsqare02 = 1, g_arrsqare03 =0; g_arrsqare10 = 0, g_arrsqare11 = 0, g_arrsqare12 = 0, g_arrsqare13 = 0; g_nLine = 0; g_nList = 3; break; g_nSqareID = nI

9、nedx; return nInedx;void CopySqareToBack( ) int i = 0, j = 0; for (i = 0; i 2; i+) for (j = 0; j = 0; i-) for (j = 0; j 10; j+) if (1 = g_arrBackGroudij) g_arrBackGroudi + 1j = g_arrBackGroudij; g_arrBackGroudij = 0; /定时器响应函数void OnTimer(HWND hwnd) HDC hdc = GetDC(hwnd);/内核对象 if (1 = CanSqaerDown()

10、& 1 = CanSqaerDown2() sqareDwon();/调用下落 g_nLine+; else Change1To2();/1变2 DestroyOneLineSqare(); if (0 = CanGameOver() /结束 KillTimer(hwnd, DEF_TIMER1); return ; CreateRandomSqare();/产生随机快 CopySqareToBack();/复制到背景 /调用显示 paintsqare(hdc); onpaint(hdc); ReleaseDC( hwnd,hdc);/内核对象释放int CanGameOver() int i

11、 = 0; for (i = 0; i 10; i+) if ( 2 = g_arrBackGroud0i) MessageBox(NULL, GameOver, 提示, MB_OK); return 0; return 1;int CanSqaerDown()/方块停在最底层,返回0不可以下落,1可以下落 int i = 0; for (i = 0; i 10; i+) if (1 = g_arrBackGroud19i) return 0; return 1;void Change1To2()/1变2 int i = 0, j = 0; for (i = 0; i 20; i+) for

12、(j = 0; j 10; j+) if (1 = g_arrBackGroudij) g_arrBackGroudij =2; /显示2void ShowSqare2(HDC hMemDC) int i = 0, j = 0; HBRUSH hOldBrush; HBRUSH hNewBrush = CreateSolidBrush(RGB(244, 38, 2); hOldBrush = (HBRUSH)SelectObject(hMemDC, hNewBrush); for (i = 0; i 20; i+) for (j = 0; j 0; i-) for (j = 0; j 10;

13、j+) if (1 = g_arrBackGroudij) if (2 = g_arrBackGroudi + 1j) return 0; return 1;void OnLeft(HWND hwnd) if (1 = CanSqaerLeft() & 1=CanSqaerLeft2() HDC hdc = GetDC(hwnd); /方块左移 sqareLeft(); g_nList-; /显示方块 onpaint(hdc); ReleaseDC(hwnd, hdc); void sqareLeft() int i = 0, j = 0; for (i = 0; i 20; i+) for

14、(j = 0; j 10; j+) if (1 = g_arrBackGroudij) g_arrBackGroudij-1 = g_arrBackGroudij; g_arrBackGroudij = 0; int CanSqaerLeft() int i = 0; for (i = 0; i 20; i+) if (1 = g_arrBackGroudi0) return 0; return 1;int CanSqaerLeft2() int i = 0, j = 0; for (i = 0; i 20; i+) for (j = 0; j 10; j+) if (1 = g_arrBac

15、kGroudij) if (2 = g_arrBackGroudij - 1) return 0; return 1;void OnRight(HWND hwnd) if (1 = CanSqaerRight() & 1 = CanSqaerRight2() HDC hdc = GetDC(hwnd); /方块右移 g_nList+; sqareRight(); onpaint(hdc); ReleaseDC(hwnd, hdc); void sqareRight() int i = 0, j = 0; for (i = 0; i = 0; j-) if (1 = g_arrBackGroud

16、ij) g_arrBackGroudij+1 = g_arrBackGroudij; g_arrBackGroudij = 0; int CanSqaerRight() int i = 0; for (i = 0; i 20; i+) if (1 = g_arrBackGroudi9) return 0; return 1;int CanSqaerRight2() int i = 0, j = 0; for (i = 0; i = 0; j-) if (1=g_arrBackGroudij) if (2 = g_arrBackGroudij+1) return 0; return 1;void

17、 OnDown(HWND hwnd) OnTimer( hwnd);void OnChangeSqare(HWND hwnd) HDC hdc = GetDC(hwnd); switch (g_nSqareID) case 0: case 1: case 2: case 3: case 4: /普通变形 if (1 = CanSqaerChangeShape() ChangeSqare(); else return; break; case 5:/正方形 return; case 6:/长条 /变形 if (CanLineSqaerChange() ChangeLineSqare(); bre

18、ak; onpaint(hdc); ReleaseDC(hwnd, hdc);void ChangeSqare() int i = 0, j = 0; int nTemp = 2; char arrSqare33 = 0 ; /背景块复制出来 for (i = 0; i 3; i+) for (j = 0; j 3; j+) arrSqareij = g_arrBackGroudg_nLine + ig_nList + j;/将背景当中的方块传递到小口袋 /变形后的方块数组复制回去 for (i = 0; i 3; i+) for (j = 0; j 3; j+) g_arrBackGroud

19、g_nLine + ig_nList + j = arrSqarenTempi; nTemp-; nTemp = 2; int CanSqaerChangeShape() int i = 0, j = 0; for (i = 0; i 3; i+) for (j = 0; j 3; j+) if (2 = g_arrBackGroudg_nLine + ig_nList + j) return 0; /if (g_nList9) / / return 0; / if (g_nList 9) g_nList = 7; return 1;void ChangeLineSqare() if (1 =

20、 g_arrBackGroudg_nLineg_nList - 1) /清零 g_arrBackGroudg_nLineg_nList - 1 = 0; g_arrBackGroudg_nLineg_nList + 1 = 0; g_arrBackGroudg_nLineg_nList + 2 = 0; if (2 = g_arrBackGroudg_nLine + 1g_nList) g_arrBackGroudg_nLine - 1g_nList = 1; g_arrBackGroudg_nLine - 2g_nList = 1; g_arrBackGroudg_nLine - 3g_nL

21、ist = 1; else if (2 = g_arrBackGroudg_nLine + 2g_nList) g_arrBackGroudg_nLine + 1g_nList = 1; g_arrBackGroudg_nLine - 1g_nList = 1; g_arrBackGroudg_nLine - 2g_nList = 1; else /元素赋值 g_arrBackGroudg_nLine - 1g_nList = 1; g_arrBackGroudg_nLine + 1g_nList = 1; g_arrBackGroudg_nLine + 2g_nList = 1; else

22、g_arrBackGroudg_nLine - 1g_nList = 0; g_arrBackGroudg_nLine + 1g_nList = 0; g_arrBackGroudg_nLine + 2g_nList = 0; if (2 = g_arrBackGroudg_nLineg_nList + 1|9=g_nList) g_arrBackGroudg_nLineg_nList - 1 = 1; g_arrBackGroudg_nLineg_nList - 2 = 1; g_arrBackGroudg_nLineg_nList - 3 = 1; g_nList = g_nList -

23、2; else if (2 = g_arrBackGroudg_nLineg_nList + 2|8= g_nList) g_arrBackGroudg_nLineg_nList + 1 = 1; g_arrBackGroudg_nLineg_nList - 1 = 1; g_arrBackGroudg_nLineg_nList - 2 = 1; g_nList = g_nList - 1; else if (2 = g_arrBackGroudg_nLineg_nList - 1 | 0 = g_nList) g_arrBackGroudg_nLineg_nList + 1 = 1; g_arrBackGroudg_nLineg_nList + 2 = 1; g_arrBackGroudg_nLineg_nList + 3 = 1; g_nList = g_nList + 1; else /元素复制 g_arrBackGroudg_nLineg_nList - 1 = 1; g_arrBackGroudg_nLineg_nList + 1 = 1; g_arrBack

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

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