资源描述:
《C语言课程设计俄罗斯方块源代码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1、新建“.h”头文件,将“头文件”代码粘贴至其中,2、新建“.c”源文件,将“源代码”代码粘贴到其中。3、新建空白工程,将头文件和源代码添加进去,调试使用。//头文件//1.自定义枚举类型,定义7种形态的游戏方块typedefenumtetris_shape{ZShape=0,SShape,LineShape,TShape,SquareShape,LShape,MirroredLShape}shape;//2.函数声明//(1)操作方块函数intmaxX();//取得当前方块的最大x坐标intm
2、inX();//取得当前方块的最小x坐标voidturn_left();//当前方块逆时针旋转90度voidturn_right();intout_of_table();voidtransform();intleftable();intrightable();intdownable();voidmove_left();voidmove_right();//(2)操作游戏桌面的函数intadd_to_table();voidremove_full();//(3)控制游戏函数voidnew_game(
3、);voidrun_game();voidnext_shape();intrandom(intseed);//(4)绘图函数voidpaint();voiddraw_table();//(5)其他功能函数voidkey_down(WPARAMwParam);voidresize();voidinitialize();voidfinalize();//(6)回调函数,用来处理Windows消息LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);//源代码/
4、/1.文件包含#include#include#include#include"tetris.h"//2.常量定义#defineAPP_NAME"TETRIS"#defineAPP_TITLE"TetrisGame"#defineGAMEOVER"GAMEOVER"#defineSHAPE_COUNT7#defineBLOCK_COUNT4#defineMAX_SPEED5#defineCOLUMS10#defineROWS20#define
5、REDRGB(255,0,0)#defineYELLOWRGB(255,255,0)#defineGRAYRGB(128,128,128)#defineBLACKRGB(0,0,0)#defineWHITERGB(255,255,255)#defineSTONERGB(192,192,192)#defineCHARS_IN_LINE14#defineSCORE"SCORE%4d"//3.全局变量定义//(1)charscore_char[CHARS_IN_LINE]={0};//(2)char*p
6、ress_enter="PressEnterkey...";//(3)帮助提示信息char*help[]={"pressspaceorupkeytotransformshape.","Pressleftorrightkeytomovershape.","Pressdownkeytospeedup.","Pressenterkeytopausegame.","Enjoyit.:-)",0};//(4)枚举游戏的状态enumgame_state{game_start,game_run,game_pau
7、se,game_over,}state=game_start;//(5)定义方块的颜色COLORREFshape_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中类型intshape_coordinate[SHAPE_COUNT][BLOCK_COUNT][2]={{{0,1},{0,0},{-1,0},{
8、-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)得分intscore=0;//(8)下一个方块shapenext=0;//(9)当前方块shapecurrent=0;//(10)当