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

📄 els6.cpp

📁 有排行榜
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <graphics.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <bios.h>
#include <process.h>
#include <fcntl.h>
#include <order.h>



//#include <bmp.h>
#define ORGNX    120   /*初始坐标*/      
#define ORGNY    15
#define EDGEX       14   /*边界 X*/
#define EDGEY       21   /*边界Y*/
#define BLOCKSIZE   16    /*方块大小*/

#define FORECOLOR WHITE
#define BGCOLOR   BLACK
		      
#define UP     0x4800 /*按键*/
#define DOWN   0x5000
#define LEFT   0x4b00
#define RIGHT   0x4d00
#define ESC    0x11b  
#define YES  0x1579
#define NO  0x316e
#define SPACE 0x3920

int playboard[EDGEY+4][EDGEX+4]; /*游戏板初始化 */
int presentblock[5][5];          /*当前下落的方块*/
int presentX, presentY;         /*当前方块在地图上的位置*/
int nextblock[5][5];         /*下一个形状的方块*/
int level=0,score=0;
int killline=0;
char lv[]="0",sc[]="0";
FILE *fp;               /*文件指针,用于读取字库*/
long int fpos;          /*具体汉字在字库中的偏移量*/
char bitdata[32];       /*存储汉字字模*/



struct blockshape
{
int shape[5][5];
};
struct blockshape shapes[7]=
{
	    {
		0,0,0,0,0,
		0,0,0,0,0,
		1,1,1,1,0,
		0,0,0,0,0,
		0,0,0,0,0
	    },

	    {
		0,0,0,0,0,
		0,0,1,0,0,
		0,1,1,1,0,
		0,0,0,0,0,
		0,0,0,0,0
	    },

	    {
		0,0,0,0,0,
		0,1,1,0,0,
		0,0,1,1,0,
		0,0,0,0,0,
		0,0,0,0,0
	    },

	    {
		0,0,0,0,0,
		0,0,1,1,0,
		0,1,1,0,0,
		0,0,0,0,0,
		0,0,0,0,0
	    },

	    {
		0,0,0,0,0,
		0,1,1,0,0,
		0,0,1,0,0,
		0,0,1,0,0,
		0,0,0,0,0
	    },

	    {
		0,0,0,0,0,
		0,0,1,1,0,
		0,0,1,0,0,
		0,0,1,0,0,
		0,0,0,0,0
	    },

	    {
		0,0,0,0,0,
		0,0,1,1,0,
		0,0,1,1,0,
		0,0,0,0,0,
		0,0,0,0,0
	    }
};


/*时钟结构*/
typedef struct {           /*时钟结构*/
    int enabled;          /*时钟是否开启*/
    unsigned int intervel; /*定时间隔*/
    unsigned int lasttime; /*这个属于内部使用变量*/
} Timer;

int GetTickCount();        /*返回电脑或操作系统运行逝去的时间*/
int setTimer(Timer *t, unsigned int intv, int en);
	   /*设置时钟t,参数分别为时钟指针,时间间隔,是否活动*/
int checkTimer(Timer *t);  /*测试时钟t是否到达定时时间*/
void WriteHzStr(char *s,int x,int y,int color);
void WriteHz(unsigned char left,unsigned char right,int x,int y,int color);
void GetHzBit(unsigned char left,unsigned char right);
	  
void renovate(void);/*刷新*/         	  
void initplayboard(void);        /*初始化游戏板*/
void start();            /*开始游戏*/
void rotateBlock(int shape1[5][5], int shape2[5][5]);
	   /*逆时针旋转90度*/
void rebuidblock();
	   /*生成下一个方块*/
int drop();
	   /*核心函数成员,将下落的方块向下移,无法下移返回0*/
void fillblock();
	   /*画方块*/
void clear();
int move(int direction);
	   /*左右移动下落方块,direction指出向左还是向右*/
int checkblock(int x, int y, int shape[5][5]);
	   /*判断block能不能放在x,y上*/
int rotate();
	   /*旋转下落的方块,旋转无效返回0*/
int next();
	   /*下个方块*/

void changespeed();
void gameover();

//void showbmp();/*进行位图输出,友好界面*/





/******************************************************\
*                      时钟                          *
\******************************************************/
/*时钟部分也非常理解的,一个用到设置时钟,一个用来测试时钟激活态*/

Timer tDown;               /*正常下落定时时钟intervel会比较大*/
Timer tFast;               /*按DOWN时使用的快速下落*/
int speed = 13;            /*控制下落时间间隔*/
#define FAST_INTV    1     /*快时钟的间隔*/

int GetTickCount() {       /*读取BIOS时钟*/
    int ret;
    ret = peek(0x0,0x46e); /*实际上读取了内存0:046e处的内容*/
    ret <<= 8;            
    ret += peek(0x0,0x46c); 
    return (ret);
}

int setTimer(Timer *t, unsigned int intv, int en) {
    t -> enabled = en;              /*设置一个时钟*/
    t -> intervel = intv;
    t -> lasttime = GetTickCount(); /*lasttime记录的是上一个*/
				    /*tickcount返回的东西*/
		   /*这样当再一次测试时间时新的tickcount产生了
		     它来减去上一次的tickcount就得出了一个时间
		     间隔,这个就可以和intervel比较从而得出是否
		     激活了
		   */
    return 0;
}

int checkTimer(Timer *t) {         
    unsigned int tmp, dt;
    if (!(t -> enabled)) return 0;
    tmp = GetTickCount();
    dt = tmp - (t -> lasttime);
    if(dt >= t -> intervel) {
	t -> lasttime = tmp;
	return 1;
    }
    return 0;
}

void WriteHzStr(char *s,int x,int y,int color)
/*-------------------------------------------------------
//汉字输出函数,参数依次为:汉字字串、起始坐标(x,y)
//------------------------------------------------------*/
{
  int num,i;
  num=strlen(s); /*获取字符串长度*/
  
  for(i=0;i<num;i+=2) /*每次读两个字节*/
  {
    WriteHz(s[i],s[i+1],x,y,color);
    x+=16;
    if(x>=640){y+=16;x=0;}
  }
}
void WriteHz(unsigned char left,unsigned char right,int x,int y,int color)
{
  unsigned char bit[8]={128,64,32,16,8,4,2,1};
  int i,j;
  GetHzBit(left,right);
  for(i=0;i<16;i++)
    for(j=0;j<8;j++)/*和bit[]与操作以后,在屏幕上画点*/
    {
      if(bitdata[2*i]&bit[j])putpixel(x+j,i+y,color);
      if(bitdata[2*i+1]&bit[j])putpixel(x+8+j,i+y,color);
    }
}
void GetHzBit(unsigned char left,unsigned char right)
{ 
  fpos=32L*((left-161)*94+(right-161));/*获得字模在字库中的位置*/
  fseek(fp,fpos,SEEK_SET);
  fread(bitdata,32,1,fp);/*把该汉字字模读入到bitdata中*/
}
void renovate(void) {
    int x, y;
    static int page = 0;    /*当前页*/

setactivepage(page=(page==0?1:0));      /*选择页*/
  // showbmp();

setfillstyle(SOLID_FILL,BGCOLOR);         /*清屏*/
bar(ORGNX + BLOCKSIZE * 2 - 2,
	    ORGNY + BLOCKSIZE * 3 - 2,
	    ORGNX + BLOCKSIZE * (EDGEX - 2) + 2,
	    ORGNY + BLOCKSIZE * (EDGEY - 2) + 2);
bar(360,60,440,130);
bar(362,226,420,244);
bar(362,182,420,194);     /*清屏*/


    setcolor(FORECOLOR);              /*初始化游戏板*/
    rectangle(    ORGNX + BLOCKSIZE * 2 - 2,
	    ORGNY + BLOCKSIZE * 3 - 2,
	    ORGNX + BLOCKSIZE * (EDGEX - 2) + 2,
	    ORGNY + BLOCKSIZE * (EDGEY - 2) + 2);
    rectangle(360,180,422,196);
    rectangle(360,228,422,246);

    /*setcolor(RED);
    settextstyle(0,0,1);
    outtextxy(362,185,lv);
    outtextxy(362,233,sc);*/
    if((fp=fopen("hzk16","rb"))==NULL)
      {
	outtextxy(139,448,"can't find file hzk16");
	getch();
	exit(0);
      }
      WriteHzStr("欢迎使用俄罗斯方块",200,20,13);
      WriteHzStr("制作者:谢许扬",400,330,13);
	fclose(fp);

setcolor(FORECOLOR);
setfillstyle(SOLID_FILL,LIGHTBLUE);
    for(y = 3; y < EDGEY - 2; y++) {
	for(x = 2; x < EDGEX - 2; x++) {
	    if(playboard[y][x]) {
		     bar(    x * BLOCKSIZE + ORGNX+1,
		    y * BLOCKSIZE + ORGNY+1,
		    x * BLOCKSIZE + ORGNX + BLOCKSIZE-2,
		    y * BLOCKSIZE + ORGNY + BLOCKSIZE-2);
		     rectangle(    x * BLOCKSIZE + ORGNX,
			y * BLOCKSIZE + ORGNY,
			x * BLOCKSIZE + ORGNX + BLOCKSIZE,
			y * BLOCKSIZE + ORGNY + BLOCKSIZE);

	    }
	}

}


    for(y = 0; y < 5; y++) {        /*画下落物*/
	for(x = 0; x < 5; x++) {
	    if(presentblock[y][x]) {
		if(y + presentY > 2) {
		    bar(    (x + presentX) * BLOCKSIZE + ORGNX+1,
			(y + presentY) * BLOCKSIZE + ORGNY+1,
			(x + presentX) * BLOCKSIZE + ORGNX + BLOCKSIZE-2 ,
			(y + presentY) * BLOCKSIZE + ORGNY + BLOCKSIZE-2);
		    rectangle(    (x + presentX) * BLOCKSIZE + ORGNX,
			    (y + presentY) * BLOCKSIZE + ORGNY,
			    (x + presentX) * BLOCKSIZE + ORGNX + BLOCKSIZE,
			    (y + presentY) * BLOCKSIZE + ORGNY + BLOCKSIZE);

		}
	    }
	}
    }

/*以上将下落的方块按昭它在地图上的坐标,画到对应的区域里*/
    for(y = 0; y < 5; y++) {        /*画下一个*/
	for(x = 0; x < 5; x++) {
	    if(nextblock[y][x]) {
		bar(    x * BLOCKSIZE + 360+1,
		    y * BLOCKSIZE + 50+1,
		    x * BLOCKSIZE + 376-2,

⌨️ 快捷键说明

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