c语言课程设计俄罗斯方块源代码
1、 新建 “.h ”头文件,将 “头文件”
代码粘贴至其中,
2、 新建 “.c ”源文件,将 “源代码”
代码粘贴到其中。
3、 新建空白工程,将头文件和源代码
添加进去,调试使用。
//头文件
//1.自定义枚举类型,定义7 种形态的游戏方块
typedefenumtetris_shape
{
ZShape 0,
SShape,
LineShape,
TShape,
SquareShape,
LShape,
MirroredLShape
}shape;
//2.函数声明
//(1)操作方块函数
intmaxX();//取得当前方块的最大x 坐标
intminX();//取得当前方块的最小x 坐标
voidturn_left();//当前方块逆时针旋转90度
voidturn_right();
int out_of_table();
voidtransform();
int leftable();
intrightable();
int downable();
voidmove_left();
voidmove_right();
//(2)操作游戏桌面的函数
int add_to_table();
voidremove_full();
//(3)控制游戏函数
voidnew_game();
voidrun_game();
voidnext_shape();
intrandom(int seed);
//(4)绘图函数
voidpaint();
voiddraw_table();
//(5)其他功能函数
voidkey_down(WPARAMwParam);
voidresize();
voidinitialize();
void finalize();
//(6)回调函数,用来处理Windows 消息
LRESULTCALLBACKWndProc (HWND,UINT,WPARAM,LPARAM);
//源代码
//1.文件包含
#include
#include
#include
#include"tetris.h"
//2.常量定义
#defineAPP_NAME "TETRIS"
#defineAPP_TITLE "TetrisGame"
#defineGAMEOVER "GAME OVER"
#define SHAPE_COUNT7
#defineBLOCK_COUNT4
#defineMAX_SPEED 5
#defineCOLUMS 10
#defineROWS20
#defineRED RGB(255,0,0)
#defineYELLOWRGB(255,255,0)
#defineGRAYRGB(128,128,128)
#defineBLACKRGB(0,0,0)
#defineWHITERGB(255,255,255)
#define STONERGB(192,192,192)
#defineCHARS_IN_LINE 14
#define SCORE "SCORE %4d"
//3.全局变量定义
//(1)
char score_char[CHARS_IN_LINE] {0};
//(2)
char*press_enter "PressEnterkey...";
//(3)帮助提示信息
char *help[]
{
"pressspaceorupkey totransform shape.",
"Pressleft orright key tomover shape.",
"Pressdownkey to speedup.",
"Pressenterkey topausegame.",
"Enjoy it.:-)",
0
};
//(4)枚举游戏的状态
enum game_state
{
game_start,
game_run,
game_pause,
game_over,
}state game_start;