⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eluosi.c

📁 C语言编写的俄罗斯方块游戏.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*俄罗斯方块程序源代码
 文件名:TETRIS.C  
 编程时间: 1999.10.9
*/
#include	"vga13h.h"	/* 包含游戏函数库(vga13hlib) */
#define NUM_SQU		15	/* 方块总数 */
#define BK_X	17	/* 背景宽度 */
#define BK_Y	21	/* 背景高度 */
#define START_X	100	/* 背景显示起始X坐标 */
#define START_Y	10	/* 背景显示起始Y坐标 */
#define MAX_SPEED	14	/* 游戏最高速度值 */
#define MAX_LINE	30	/* 游戏速度升级最大行数值 */
#define MAX_LEVEL	14	/* 游戏水平限制值 */
#define MAX_MODE	3	/* 游戏模式最高值 */
typedef struct GAME_INFO	/* 游戏信息结构 */
{
	int music;
	int cur_squ_num;	/* 当前模式方块数量 */
	int k;	/* 系数值 */
	int disp_clock;	/* 游戏速度控制计数 */
	int bk[BK_Y][BK_X];	/* 游戏背景数据 */
	unsigned char mask[21600];	/* 游戏背景掩模(120*180) */
}GameInfo,*GameInfoPtr;
typedef struct SQU_INFO	/* 方块信息结构 */
{
	int squ_num;	/* 当前方块号 */
	int shape;	/* 当前方块旋转方向 */
	int x;	/* 方块屏幕X坐标 */
	int y;	/* 方块屏幕Y坐标 */
	int w;	/* 方块宽度 */
	int h;	/* 方块高度 */
	unsigned char mask[1600];	/* 方块掩模(40*40) */
}SquInfo,*SquInfoPtr;
typedef struct NUMBER_INFO	/* 数值信息结构 */
{
	long n;	/* 数值 */
	int x;	/* 数值X坐标 */
	int y;	/* 数值Y坐标 */
	int w;	/* 数值宽度 */
	int h;  /* 数值高度 */
	char string[8];	/* 数值转换字符串 */
	unsigned char mask[448];	/* 数值掩模(56*8) */
}NumberInfo,*NumberInfoPtr;
int squ_temp[NUM_SQU][4][4][4]= /* 方块模板,每种方块有四个旋转方向的形状 */
{
	/* 方块0 */
	1,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1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,
	-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
	-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
};
char far *squ_image[NUM_SQU];	/* 组成方块的图案指针 */
GameInfo	game_info;	/* 游戏信息结构变量 */
PCXPicture	pcx_pic1,pcx_pic2;	/* PCX图像结构变量 */
SquInfo ThisSqu,NextSqu;	/* 方块结构变量 */
NumberInfo Level,Speed,Score,Line,Mode;	/* 数值结构变量 */
void PrintNumber(NumberInfoPtr number)	/* 打印游戏分数数字 */
{
	ltoa(number->n,number->string,10);
	DrawImage(number->x,number->y,number->w,number->h,number->mask);
	PrintString(number->x+number->w-strlen(number->string)*number->h,number->y,number->string,80,0,0);
}
void InitGameData(void)	/* 初始化游戏数据 */
{
	int i,j;
	LoadPCX("bk1.pcx",&pcx_pic1,1);
	LoadPCX("bk2.pcx",&pcx_pic2,1);
	DrawImage(0,0,320,200,pcx_pic2.buffer);
	GetImage(START_X,START_Y,120,180,game_info.mask);
	game_info.k=1;
	game_info.cur_squ_num=7;
	game_info.music=1;
	for(i=0;i<BK_Y;i++)
		for(j=0;j<BK_X;j++)
			game_info.bk[i][j]=bk_temp[i][j];
	NextSqu.x=255;
	NextSqu.y=25;
	NextSqu.w=40;
	NextSqu.h=40;
	NextSqu.squ_num=random(game_info.cur_squ_num);
	NextSqu.shape=random(4);
	GetImage(NextSqu.x,NextSqu.y,NextSqu.w,NextSqu.h,NextSqu.mask);
	ThisSqu.x=5;
	ThisSqu.y=0;
	ThisSqu.w=40;
	ThisSqu.h=40;
	ThisSqu.squ_num=NextSqu.squ_num;
	ThisSqu.shape=NextSqu.shape;
	Score.n=0;
	Score.x=8;
	Score.y=20;
	Score.w=56;
	Score.h=8;
	GetImage(Score.x,Score.y,Score.w,Score.h,Score.mask);
	Line.n=0;
	Line.x=8;
	Line.y=40;
	Line.w=56;
	Line.h=8;
	GetImage(Line.x,Line.y,Line.w,Line.h,Line.mask);
	Level.n=0;
	Level.x=8;
	Level.y=60;
	Level.w=56;
	Level.h=8;
	GetImage(Level.x,Level.y,Level.w,Level.h,Level.mask);
	Speed.n=0;
	Speed.x=8;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -