好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

C语言课程设计报告俄罗斯方块源代码.doc

18页
  • 卖家[上传人]:大米
  • 文档编号:494643045
  • 上传时间:2023-01-23
  • 文档格式:DOC
  • 文档大小:51.50KB
  • / 18 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、 新建“.h”头文件,将“头文件”代码粘贴至其中,2、 新建“.c”源文件,将“源代码”代码粘贴到其中3、 新建空白工程,将头文件和源代码添加进去,调试使用//头文件//1.自定义枚举类型,定义7种形态的游戏方块typedef enum tetris_shape{ ZShape=0, SShape, LineShape, TShape, SquareShape, LShape, MirroredLShape}shape;//2.函数声明//(1)操作方块函数int maxX();//取得当前方块的最大x坐标int minX();//取得当前方块的最小x坐标void turn_left();//当前方块逆时针旋转90度void turn_right();int out_of_table();void transform();int leftable();int rightable();int downable();void move_left();void move_right();//(2)操作游戏桌面的函数int add_to_table();void remove_full();//(3)控制游戏函数void new_game();void run_game();void next_shape();int random(int seed);//(4)绘图函数void paint();void draw_table();//(5)其他功能函数void key_down(WPARAM wParam);void resize();void initialize();void finalize();//(6)回调函数,用来处理Windows消息LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM);//源代码//1.文件包含*include*include*include*include"tetris.h"//2.常量定义*define APP_NAME "TETRIS"*define APP_TITLE "Tetris Game"*define GAMEOVER "GAME OVER"*define SHAPE_COUNT 7*define BLOCK_COUNT 4*define MAX_SPEED 5*define COLUMS 10*define ROWS 20*define RED RGB(255,0,0)*define YELLOW RGB(255,255,0)*define GRAY RGB(128,128,128)*define BLACK RGB(0,0,0)*define WHITE RGB(255,255,255)*define STONE RGB(192,192,192)*define CHARS_IN_LINE 14*define SCORE "SCORE %4d"//3.全局变量定义//(1)char score_char[CHARS_IN_LINE]={0};//(2)char* press_enter="Press Enter key...";//(3)帮助提示信息char *help[]={ "press space or up key to transform shape.", "Press left or right key to mover shape.", "Press down key to speed up.", "Press enter key to pause game.", "Enjoy it.:-)", 0};//(4)枚举游戏的状态enum game_state{ game_start, game_run, game_pause, game_over,}state=game_start;//(5)定义方块的颜色COLORREF shape_color[]={ RGB(255,0,0), RGB(0,255,0), RGB(0,0,255), RGB(255,255,0), RGB(0,255,255), RGB(255,0,255), RGB(255,255,255)};//(6)方块的7中类型int shape_coordinate[SHAPE_COUNT][BLOCK_COUNT][2]={ {{0,1},{0,0},{-1,0},{-1,1}}, {{0,-1},{0,0},{1,0},{1,1}}, {{0,-1},{0,0},{0,1},{0,2}}, {{-1,0},{0,0},{1,0},{0,1}}, {{0,0},{1,0},{0,1},{1,1}}, {{-1,-1},{0,-1},{0,0},{0,1}}, {{1,-1},{0,-1},{0,0},{0,1}}};//(7)得分int score=0;//(8)下一个方块shape next=0;//(9)当前方块shape current=0;//(10)当前方块的每一部分坐标int current_coordinate[4][2]={0};//(11)游戏桌面int table[ROWS][COLUMS]={0};//(12)当前方块的x坐标int shapex=0;//(13)当前方块的\y坐标int shapey=0;//(14)方块下移速度int speed=0;//(15)每一帧开始时间clock_t start=0;//(16)每一帧结束时间clock_t finish=0;//(17)windows绘图用变量HWND gameWND;HBITMAP memBM;HBITMAP memBMOld;HDC memDC;RECT clientRC;HBRUSH blackBrush;HBRUSH stoneBrush;HBRUSH shapeBrush[SHAPE_COUNT];HPEN grayPen;HFONT bigFont;HFONT smallFont;//4.主要处理函数//(1)取最大坐标int maxX(){ int i=0; int x=current_coordinate[i][0]; int m=x; for(i=1;ix) { m=x; } } return m;}//(3)逆时针转动方块void turn_left(){ int i=0; int x,y; for(i=0;i<4;i++) { x=current_coordinate[i][0]; y=current_coordinate[i][1]; current_coordinate[i][0]=y; current_coordinate[i][1]=-x; }}//(4)顺时针旋转方块void turn_right(){ int i=0; int x,y; for(i=0;i<4;i++) { x=current_coordinate[i][0]; y=current_coordinate[i][1]; current_coordinate[i][0]=-y; current_coordinate[i][1]=x; }}//(5)检查方块是否越界int out_of_table(){ int i=0; int x,y; for(i=0;i<4;i++) { x=shapex+current_coordinate[i][0]; y=shapey+current_coordinate[i][1]; if(x<0||x>(COLUMS-1)||y>(ROWS-1)) { return 1; } if(table[y][x]) { return 1; } } return 0;}//(6)旋转方块void transform(){ if(current==SquareShape) { return ; } turn_right(); if(out_of_table()) { turn_left(); }}//(7)判断方块是否向左移动int leftable(){ int i=0; int x,y; for(i=0;i<4;i++) { x=shapex+current_coordinate[i][0]; y=shapey+current_coordinate[i][1]; if(x<=0||table[y][x-1]==1) { return 0; } } return 1;}//(8)判断方块是否向右移动int rightable(){ int i=0; int x,y; for(i=0;i<4;i++) { x=shapex+current_coordinate[i][0]; y=shapey+current_coordinate[i][1]; if(x>=(COLUMS-1)||table[y][x+1]==1) { return 0; } } return 1;}//(9)判断方块是否向下移动int downable(){ int i=0; int x,y; for(i=0;i<4;i++) { x=shapex+current_coordinate[i][0]; y=shapey+current_coordinate[i][1]; if(y>=(ROWS-1)||table[y+1][x]==1) { return 0; } } return 1;}//(10)向左移动当前方块void move_left(){ if(leftable()) { shapex--; }}//(11)向右移动当前方块void move_right(){ if(rightable()) { shapex++; }}//(12)向下。

      点击阅读更多内容
      相关文档
      【全国硕士研究生入学统一考试政治】2020年考研政治真题.docx 【全国硕士研究生入学统一考试政治】2015年考研政治真题.docx 【全国硕士研究生入学统一考试政治】2010年考研政治真题.docx 【全国硕士研究生入学统一考试政治】1996年政治考研真题(理科)及参考答案.doc 【全国硕士研究生入学统一考试政治】2001年政治考研真题(理科)及参考答案.doc 【全国硕士研究生入学统一考试政治】2016年考研政治真题.docx 【全国硕士研究生入学统一考试政治】2000年政治考研真题(文科)及参考答案.doc 【全国硕士研究生入学统一考试政治】1997年政治考研真题(理科)及参考答案.doc 【全国硕士研究生入学统一考试政治】2007年考研政治真题.doc 【全国硕士研究生入学统一考试政治】1997年政治考研真题(文科)及参考答案.doc 【全国硕士研究生入学统一考试政治】2004年考研政治真题.doc 【全国硕士研究生入学统一考试政治】2003年考研政治真题.doc 【全国硕士研究生入学统一考试政治】2019年考研政治真题.docx 【全国硕士研究生入学统一考试政治】2009年考研政治真题.docx 【全国硕士研究生入学统一考试政治】2001年政治考研真题(文科)及参考答案.doc 【全国硕士研究生入学统一考试政治】2021年考研政治真题.doc 【全国硕士研究生入学统一考试政治】2014年考研政治真题.docx 【全国硕士研究生入学统一考试政治】2018年考研政治真题.docx 【全国硕士研究生入学统一考试政治】2008年考研政治真题.doc 【全国硕士研究生入学统一考试政治】2011年考研政治真题.docx
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.