课程设计俄罗斯方块_第1页
课程设计俄罗斯方块_第2页
课程设计俄罗斯方块_第3页
课程设计俄罗斯方块_第4页
课程设计俄罗斯方块_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

课 程 设 计 报 告 课程名称:面向对象程序设计C+ 设计题目: 俄罗斯方块 专 业:计算机科学与技术 姓 名: 学 号: 指导教师:李 晓 虹2016 年 1 月 10 日课程设计报告模块内容:(1) 系统需求分析利用C+实现方块方块控制、显示更新、游戏记分、游戏等级以及方块控制,直接由玩家通过键盘控制,游戏区域的方块部件根据玩家具体键盘的操作左右移动、旋转、加速下落。(2) 总体设计屏幕中央有一个矩形“容器”,选择“开始”菜单或“开始”工具按钮后,俄罗斯方块的部件随机产生并在容器中自由下落。(3) 详细设计1.游戏过程中,当在矩形“容器”中,出现一个游戏方块时,必须在游戏方块的预览区域中出现下一方块,这样利于游戏玩家控制游戏的策略。2.有七种标准俄罗斯方块部件,通过各种判断,实现游戏方块并随着键盘上的上键顺时针旋转90度,随着下键加速下落,随着左、右各键分别左、右移动。3.当部件下落达“容器”底部或已停止的部件时,停止下落;当同一行部件完整拼接上时,该行消失,其他行向下移动,在适当位置显示当前累计分数。4.当部件总行数超过矩形容器的高度或没有足够的空间产生新的部件时,提示“游戏结束”信息并停止游戏运行。5.游戏计分原则:一次消去一行加个五角星,方块下落的速度会越来越快。(4) 系统调试#include#include#include#include#includeconst int back = 30;/const,限定变量不允许被改变,back表示背景颜色const int speed = 0, 12, 9, 6, 3, 1;const int number = 0, 2, 3, 5, 7, 11, 15;const int col = 11, 15, 12, 12, 13, 13, 14;int rank = 1;int level = 0; /0表示既不是向右也不是向左,1表示向左,2表示向右int kind;int pri_kind; / 7大类,颜色标记,调用colcol_kind;int revolve = 0; / 旋转状态标记struct int x; int y; current, before;struct/定义一个结构体 内容包括坐标,颜色,是否显示方块 int x; int y; int color; bool having;/布尔型变量 作逻辑判断 运算结果为真或为假,有方块为真,没有方块为假 board1525;struct int vary_x4; int vary_y4; vary = 0, 2, 4, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -2, -3, 0, 2, 2, 0, 0, 0, -1, -1, 0, -2, -2, -4, 0 , 0, -1, -1, 0, 0, 2, 2, 0, -1, -1, -2, 0, 2, 2, 4, 0, 0, -1, -1, 0, 0, -2, -2, 0, -1, -1, -2, 0, 0, 2, 4, 0, -1, 0, 0, 0, 0, 0, 2, 0, -1, -2, -2, 0, 0, -2, -4, 0, -1, -1, -1, 0, 2, 2, 2, 0, 0, -1, -2, 0, 2, 4, 4, 0, 0, 0, -1, 0, -2, -2, -2, 0, 0, -1, -2, 0, 0, 2, 4, 0, -1, -1, -1, 0, 0, 0, -2, 0, -1, -2, -2, 0 , 2, 4, 2, 0, 0, 0, -1, 0, -2, 0, 2, 0, -1, -1, -1, 0, 0, -2, 0, 0, -1, -1, -2, ;struct int sum; int connection_x5; int connection_y5; connection = 2, -2, 2, 0, 1, 1, 0, 0, 2, 2, -2, 0, 0, 2, -2, 2, 0, 0, 4, -2, 0, 4, -2, 0, 0, -1, 1, 4, -4, 2, -2, 4, 0, 0, -1, 1, 4, -2, 2, 0, 0, 0, 0, 0, 0,;void gotoxy(int x, int y)/光标移动函数 COORD pos;/COORD是Windows API中定义的一种结构,表示一个字符在控制台屏幕上的坐标 pos.X = x; pos.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);/使光标 到(x,y)这个位置void color(int b)/颜色函数 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, b);void PrintGarphy()/画界面函数,游戏界面是25*15的 color(1010);/边框的颜色 int i, j; gotoxy(2, 2);/开始画边框 for(i = 0; i 26; i+) printf();/alt+43144 gotoxy(2, 28); for(i = 0; i 26; i+) printf(); for(i = 0; i 26; i+) gotoxy(2, 2 + i); printf(); gotoxy(34, 2 + i); if(i = 8 | i = 16) printf(); else printf(); gotoxy(52, 2 + i); printf(); int t;FILE *fp = fopen(C:els.txt, r);/最高分的取出 fscanf (fp, %d, &t); fclose(fp); color(46);/最高分的颜色 gotoxy(37, 12);/最高分的显示位置 printf(最高纪录: %d, t); color(46); gotoxy(37, 14); printf(当前得分: 0); color(46); gotoxy(37, 16); printf(级数 ); color(39); gotoxy(36, 20); printf( 操作 ); gotoxy(37, 22); printf( 按空格 暂停); gotoxy(37, 24); printf( 按 ESC 退出); gotoxy(37, 26); printf( 编写人 沈志全); color(back); for(i = 0; i 25; i+)/做一个空白的游戏界面 gotoxy(4, 3 + i); for(j = 0; j = 0; i-)/清屏 for(int j = 0; j 15; j+) gotoxy(32 - j * 2, 3 + i); printf(); Sleep(10);/执行挂起一段时间 实现一种效果 color(back); for(int j = 0; j 25; j+)/恢复起始的效果 for(int i = 0; i 15; i+) boardij.having = 0; gotoxy(4 + 2 * i, j + 3); printf( ); Sleep(10);/执行挂起一段时间 实现一种效果 color(34); gotoxy(42, 16); while(rank-) printf( ); color(46); gotoxy(47, 14); printf( );void GetDepth(int *pdepth)/判断是否达到最大高度 (*pdepth) = 25; for(int j = 0; j 4; j+) int sum = 0; int n = (current.x + varykind.vary_xj - 4) / 2; int m = current.y + varykind.vary_yj - 3; if(m 0) m = 0; for(+m; m = 0 & n = 0 & m 25) sum+; else break; if(sum (*pdepth) (*pdepth) = sum; void CheckFull(int *pscore)/消行函数 int i, j; int sum = 0; int s = 0, 1, 3, 6, 10; for(i = 0; i 25; i+) bool mark = 1; for(j = 0; j 0; t-) gotoxy(4, 3 + t); for(j = 0; j = 140) rank = 5; else if(*pscore = 90) rank = 4; else if(*pscore = 50) rank = 3; else if(*pscore = 20) rank = 2; else if(*pscore = 1) rank = 1; color(44); gotoxy(42, 16); for(i = 0; i t) fp = fopen(C:els.txt, w); fprintf (fp, %d, *pscore); fclose(fp); color(43); gotoxy(47, 12); printf(%d, *pscore); fclose(fp);void PrintNext(int pkind)/显示下一个是什么方块 int i; int x = 43, y = 6; color(34); for(i = 0; i 4; i+) gotoxy(x - 3, y + i - 2); printf( ); pri_kind = pkind; if(pkind = 6) pkind = 15, x-; else if(pkind = 5) pkind = 11, x-; else if(pkind = 4) pkind = 7, x-; else if(pkind = 3) pkind = 5, x -= 2; else if(pkind = 2) pkind = 3, x += 2; else if(pkind = 1) pkind = 2, x-; else pkind = 0, x -= 3; color(colpri_kind); for(i = 0; i 4; i+) gotoxy(x + varypkind.vary_xi, y + varypkind.vary_yi); printf(); void CheckBoundary()/检查边界线 int i, n, m; for(i = 0; i 4; i+) m = current.x + varykind.vary_xi; if(m 32) current.x += (m 4 ? 2 : -2); i = -1; for(i = 0; i 4; i+) / 对四个方块分别检查 m = current.x + varykind.vary_xi; n = current.y + varykind.vary_yi; m = (m - 4) / 2; n -= 3; if(n 24 | boardmn.having) if(level = 1) /左移 current.x += 2; /复原 else if(level = 2) /右移 current.x -= 2; /复原 level = 0; break; void LevelMove()/下落速度函数 CheckBoundary(); if(level = 0) return; int i; color(back); for(i = 0; i 2) gotoxy(before.x + varykind.vary_xi, before.y + varykind.vary_yi); puts( ); color(colpri_kind); for(i = 0; i 2) gotoxy(current.x + varykind.vary_xi, current.y + varykind.vary_yi); puts(); before.x = current.x;void Revolve(int *prev_count) /旋转函数 int i; before.x = current.x; before.y = current.y; (*prev_count)+; (*prev_count) %= connectionpri_kind.sum; current.x = current.x + connectionpri_kind.connection_x *prev_count; current.y = current.y + connectionpri_kind.connection_y *prev_count; CheckBoundary(); for(i = 0; i 14 | m 24) current.x = current.x - connectionpri_kind.connection_x *prev_count; current.y = current.y - connectionpri_kind.connection_y *prev_count; revolve = 0; (*prev_count)-; before.x = current.x; before.y = current.y; return ; color(back); for(i = 0; i 2) gotoxy(before.x + varykind.vary_xi, before.y + varykind.vary_yi); puts( ); kind = numberpri_kind + *prev_count; color(colpri_kind); for(i = 0; i 2) gotoxy(current.x + varykind.vary_xi, current.y + varykind.vary_yi); puts(); Sleep(speedrank); before.x = current.x; before.y = current.y;void ChoiceDirection(int *prev_count) int t = 50 / rank; while(t-) if(_kbhit() char c = _getch(); switch(c) case 0x48:/ 上 revolve = 1; Revolve(&prev_count); break; case 0x50: /下 level = 0; return; case 0x4b: /左 before.x = current.x; current.x -= 2; level = 1; LevelMove(); break; case 0x4d: /右 before.x = current.x; current.x += 2; level = 2; LevelMove(); break; case : _getch(); break; case 27: color(back); exit(1); default: break; Sleep(speedrank); void StraightFall(int depth) int i; int rev_count = 0; before.x = current.x; before.y = current.y; while(GetDepth(&depth), depth-) ChoiceDirection(&rev_count); GetDepth(&depth); if(depth = 0) revolve = 0; before.x = current.x; before.y = current.y; break; color(back); for(i = 0; i 2) gotoxy(before.x + varykind.vary_xi, before.y + varykind.vary_yi); puts( ); current.y+; color(colpri_kind); for(i = 0; i 2) gotoxy(current.x + varykind.vary_xi, current.y + varykind.vary_yi); puts(); revolve = 0; before.x = current.x; before.y = current.y; ChoiceDirection(&rev_count); if(level | revolve) level = 0; revolve = 0; ChoiceDirection(&rev_count); StraightFall(depth); /递归调用 int main() FILE *fp = fopen(c:123sa.c, w); srand(unsigned long)time(0); system(mode con cols=56 lines=30);/画总界面大小 system(color 24); int score = 0; fp = fopen(C:els.txt, r);/打开最高分的文件 if(fp = NULL) fp = fopen(C:els.txt, w); fprintf (fp, %d, score); fclose(fp); PrintGarphy();/画游戏界面函数 kind = rand() % 7; int depth; while(1) int pkind = rand() % 7; PrintNext(pkind); current.x = 18; current.y

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论