C++大作业俄罗斯方块[教育材料].doc

上传人:rrsccc 文档编号:9559341 上传时间:2021-03-05 格式:DOC 页数:10 大小:55KB
返回 下载 相关 举报
C++大作业俄罗斯方块[教育材料].doc_第1页
第1页 / 共10页
C++大作业俄罗斯方块[教育材料].doc_第2页
第2页 / 共10页
亲,该文档总共10页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《C++大作业俄罗斯方块[教育材料].doc》由会员分享,可在线阅读,更多相关《C++大作业俄罗斯方块[教育材料].doc(10页珍藏版)》请在三一文库上搜索。

1、#include#include#include#include#includeusing namespace std;#define A1 0/A代表长条型,B为方块,C为L型,D为闪电型(实在无法描述那个形状)#define A2 1#define B 2#define C11 3#define C12 4#define C13 5#define C14 6#define C21 7#define C22 8#define C23 9#define C24 10#define D11 11#define D12 12#define D21 13#define D22 14void SetP

2、os(int i,int j)/设定光标位置COORD pos=i,j;HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(Out, pos);int sharp158=0,0,1,0,2,0,3,0,0,0,0,1,0,2,0,3,0,0,1,0,0,1,1,1,0,0,1,0,1,1,1,2,0,1,1,1,2,0,2,1,0,0,0,1,0,2,1,2,0,0,0,1,1,0,2,0,1,0,1,1,1,2,0,2,0,0,0,1,1,1,2,1,0,0,0,1,0,2,1,0,0,0,1,0,2,0,

3、2,1,0,0,0,1,1,1,1,2,0,1,1,0,1,1,2,0,0,1,0,2,1,0,1,1,0,0,1,0,1,1,2,1;/这个2维数组是用来保存各个形状位置的int high15=4,1,2,2,3,2,3,2,3,2,3,2,3,2,3;/这个数组是用来保存各个形状高度的class Box/俄罗斯方块类 private: int map2312;/画面坐标 int hotpoint2;/热点(即当前活动的点,所有图形都是相当此点绘制的) int top;/当前最高位置 int point;/分数 int level;/等级 int ID;/当前活动图形的ID号 public:

4、 Box()/初始化 int i,j; for(i=0;i23;i+) for(j=0;j12;j+) mapij=0; hotpoint0=0; hotpoint1=5; point=0; level=1; top=99; ID=0; void DrawMap();/画界面 int Judge(int x,int y);/判断当前位置能否绘制图形 void Welcome();/欢迎界面 void DrawBox(int x,int y,int num);/绘制图形 void Redraw(int x,int y,int num);/擦除图形 void Run();/运行 void Turn

5、();/转动方块 void UpdataMap();/更新画面;/画界面void Box:DrawMap()int i;for(i=0;i14;i+) SetPos(i*2,0); cout;for(i=1;i=24;i+)SetPos(0,i);cout;SetPos(13*2,i);cout;for(i=0;i14;i+) SetPos(i*2,24); cout;i=15;for(i=15;i=25;i+) SetPos(i*2,0); cout;for(i=1;i=8;i+)SetPos(15*2,i);cout;SetPos(25*2,i);cout;for(i=15;i=25;i+

6、) SetPos(i*2,9); cout;SetPos(16*2,16);cout俄罗斯方块;SetPos(16*2,17);cout分数:point;SetPos(16*2,18);cout等级:level;/绘制图形void Box:DrawBox(int x,int y,int num) int i; int nx,ny; for(i=0;i4;i+) nx=x+sharpnumi*2;ny=y+sharpnumi*2+1;SetPos(ny+1)*2,nx+1);/利用sharp数组相对于点x,y绘制形状cout;void Box:Redraw(int x,int y,int num

7、)/擦除图形,原理同上 int i; int nx,ny; for(i=0;i4;i+) nx=x+sharpnumi*2;ny=y+sharpnumi*2+1;SetPos(ny+1)*2,nx+1);cout ;void Box:Turn()/转动图形,单纯的该ID而已switch(ID) case A1: ID=A2; break; case A2: ID=A1; break; case B: ID=B; break;case C11: ID=C12; break;case C12: ID=C13; break;case C13: ID=C14; break;case C14: ID=C

8、11; break;case C21: ID=C22; break;case C22: ID=C23; break;case C23: ID=C24; break;case C24: ID=C21; break;case D11: ID=D12; break;case D12: ID=D11; break;case D21: ID=D22; break;case D22: ID=D21; break;void Box:Welcome()/欢迎界面char x;while(1) system(cls); coutendl; cout 俄罗斯方块控制台版(不闪屏) endl; coutendl;

9、cout A,D左右移动 S向下加速 endl; cout 空格键转动方块 endl; coutendl; cout 何某制作 endl; cout 百度ID:HapHapYear endl; cout endl; cout 按1-9选择等级! endl; cout endl; cout endl; coutendl; SetPos(8,10); x=getch(); if(x=1)/设置等级 level=x-0; break; void Box:UpdataMap()/更新画面(关键) int clear; int i,j,k; int nx,ny; int flag; for(i=0;i4

10、;i+)/更新map数组的信息 nx=hotpoint0+sharpIDi*2;ny=hotpoint1+sharpIDi*2+1;mapnxny=1; if(hotpoint0top)/如果热点高于顶点则更新顶点 top=hotpoint0; clear=0;/消除的格数 for(i=hotpoint0;ihotpoint0+highID;i+) flag=0; for(j=0;j=top;k-)/从当前位置向上所有的点下移一行 if(k=0)/最高点特殊处理 for(j=0;j12;j+) mapkj=0; SetPos(j+1)*2,k+1); cout ; else for(j=0;j

11、12;j+) mapkj=mapk-1j; SetPos(j+1)*2,k+1); if(mapkj=0) cout ; elsecout; top+;/消除成功,最高点下移 clear+; point+=clear*100; SetPos(16*2,17); cout分数:=Count)/时间到i=0;/计数器清零if(Judge(hotpoint0+1,hotpoint1)/如果下个位置无效(即到底) UpdataMap();/更新画面 ID=tempID;/生成新ID,用原等待ID替换为当前ID hotpoint0=0;/热点更新 hotpoint1=5; Redraw(3,17,tem

12、pID); tempID=rand()%15; DrawBox(hotpoint0,hotpoint1,ID); DrawBox(3,17,tempID); if(Judge(hotpoint0,hotpoint1)/无法绘制开始图形,游戏结束 system(cls); SetPos(25,15); cout游戏结束!最终得分为:pointendl; system(pause); exit(0); elseRedraw(hotpoint0,hotpoint1,ID);/没有到底,方块下移一位 hotpoint0+;/热点下移DrawBox(hotpoint0,hotpoint1,ID);if(

13、kbhit()/读取键盘信息x=getch();if(x=a|x=A)/左移 if(Judge(hotpoint0,hotpoint1-1)=0) Redraw(hotpoint0,hotpoint1,ID); hotpoint1-=1; DrawBox(hotpoint0,hotpoint1,ID); if(x=d|x=D)/右移 if(Judge(hotpoint0,hotpoint1+1)=0) Redraw(hotpoint0,hotpoint1,ID); hotpoint1+=1; DrawBox(hotpoint0,hotpoint1,ID); if(x=s|x=S)/向下加速 i

14、f(Judge(hotpoint0+1,hotpoint1)=0) Redraw(hotpoint0,hotpoint1,ID); hotpoint0+=1; DrawBox(hotpoint0,hotpoint1,ID); if(x= )/转动方块temp=ID;Turn();if(Judge(hotpoint0,hotpoint1)=0) Redraw(hotpoint0,hotpoint1,temp); DrawBox(hotpoint0,hotpoint1,ID); else ID=temp;while(kbhit()/读掉剩下的键盘信息getch();Sleep(1);/等待1毫秒i+;/计数器加1 int Box:Judge(int x,int y)/判断当前是否可以绘制方块int i;int nx,ny;for(i=0;i4;i+) nx=x+sharpIDi*2;ny=y+sharpIDi*2+1;if(nx=23|ny=12|mapnxny=1)/不能,返回1return 1;return 0;int main()/主函数Box game; game.Welcome();system(cls);game.DrawMap();game.Run();system(pause);10辅导工具a

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

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1