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

新建“.h”头文件,将“头文件”代码粘贴至其中,

新建“.c”源文件,将“源代码”代码粘贴到其中。

新建空白工程,将头文件和源代码添加进去,调试使用。

//头文件

//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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值