/*---
这里只有一份TURBO C的,可以吗?
---*/
/*--------------------------------------------------------------------------
俄罗斯方块源代码
--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
包含头文件
--------------------------------------------------------------------------*/
#include"dos.h"
#include"bios.h"
#include"math.h"
#include"time.h"
#include"alloc.h"
#include"conio.h"
#include"stdio.h"
#include"stdlib.h"
#include"graphics.h"
/*----------------------------------------------------------------------------------------------------------------------------------------------------*/
/*
#define BUILD_EXECUTE_FILE
*/
/*-生成可执行文件的处理-*/
/*
#define CONTROL_KEYBORD
*/
/*-控制键盘响应时间和重复频率-*/
/*--------------------------------------------------------------------------
--------------------------------------------------------------------------*/
#define OAX 158
#define OAY 114
/*-主游戏窗口及其内容的相对坐标-*/
#define OVX OAX-11
#define OVY OAY-8
/*-预览对象窗口及其内容的相对坐标-*/
#define STX OAX-11
#define STY OAY+284
/*-游戏状态窗口及其内容的相对坐标-*/
#define GRX 345
#define GRY 379
/*-表示得分效率的曲线所在窗口的相对坐标-*/
#define ISNORMAL(can) can>='A'&&can<='Z'||can>='a'&&can<='z'||can>='0'&&can<='9'||can==32
/*-判断can是否为常规的字符-*/
#define DISOBJ(OX,OY) putimage(OX,OY,Unit,COPY_PUT)
/*-显示一个小方块-*/
#define ERAOBJ(OX,OY) putimage(OX,OY,Erase,COPY_PUT)
/*-擦去一个小方块-*/
#define DISHOR(OX,OY) putimage(OX,OY,Distil,AND_PUT)
/*-擦去一行方块-*/
#define LEFTUNABLE(HP) (StaObjCon[HP]+(DynObjCon[HP]<<1))!=(StaObjCon[HP]|(DynObjCon[HP]<<1))
/*-判断是否不能左移-*/
#define RIGHTUNABLE(HP) (StaObjCon[HP]+(DynObjCon[HP]>>1))!=(StaObjCon[HP]|(DynObjCon[HP]>>1))
/*-判断是否不能右移-*/
#define DOWNUNABLE(HP) (StaObjCon[HP+1]+DynObjCon[HP])!=(StaObjCon[HP+1]|DynObjCon[HP])
/*-判断是否不能下降-*/
#define CIRCLEUNABLE(HP,TP) (StaObjCon[HP]+TemOC[TP])!=(StaObjCon[HP]|TemOC[TP])
/*-判断是否不能旋转-*/
/*--------------------------------------------------------------------------
使用者登记表的定义
--------------------------------------------------------------------------*/
typedef struct node
{
char name[20];
long sco;
long lay;
long spe;
int forout;
struct node *next;
}PLAYER;
/*--------------------------------------------------------------------------
全局变量的声明
--------------------------------------------------------------------------*/
unsigned int StaObjCon[30]; /*-静态对象(方块)的容器-*/
unsigned int DynObjCon[29]; /*-动态对象(方块)的容器-*/
unsigned int PVObj[4]; /*-预览对象(方块)的容器-*/
unsigned int TemOC[4]; /*-临时的动态对象(方块)的容器-*/
void far *Unit; /*-选择后的显示的方块所在缓冲区的首址-*/
void far *Erase; /*-非显示的方块所在缓冲区的首址-*/
void far *Distil; /*-清层时擦去方块的矩形所在缓冲区的首址-*/
void far *Un[5]; /*-待选的显示的方块所在缓冲区的首址-*/
int HorPos,VerPos; /*-动态对象的纵向位置和横向位置-*/
int ObjSort,ObjDirect; /*-当前动态对象的种类和显示方向*/
long Speed,Layer,Score; /*-当前的速度、实际清层的层数和得分-*/
long Seed; /*-当前的虚拟的清层的层数(用来计算速度)-*/
struct time SysTime; /*-存放当前系统时间的结构-*/
PLAYER *Play; /*-使用者登记表的头指针-*/
long RepRate; /*-对象定时下降时间的控制-*/
int Finish; /*-程序是否结束的标志-*/
int RcdLong; /*-使用者登记表每个记录的长度-*/
char OriS[5]; /*-显示游戏开始时速度的字符串-*/
int Sound; /*-声音控制-*/
void far *MovGraph; /*-曲线平移使用的图象缓冲区-*/
void far *LongBar; /*-显示字幕使用的图象缓冲区-*/
#ifdef CONTROL_KEYBORD
float RespondTime,RepeatRate; /*-键盘响应时间和重复频率-*/
#endif
char *RFName="regist.rcd"; /*-使用者登记表文件名-*/
/*--------------------------------------------------------------------------
五种方块颜色的设定
--------------------------------------------------------------------------*/
int ColSeries[5][3]={{4,12,5},{2,10,8},{1,9,5},{3,14,6},{7,15,8}};
/*--------------------------------------------------------------------------
七种对象形状和显示方向的定义
--------------------------------------------------------------------------*/
struct
{
int sort;
int obj[4][4];
}Object[7]={ /* 0 */
{1,{0x0000,0x0000,0x0003,0x0003,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}},
/* 1 */
{2,{0x0000,0x0000,0x000f,0x0000,0x0002,0x0002,0x0002,0x0002,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}},
/* 2 */
{2,{0x0000,0x0002,0x0003,0x0001,0x0000,0x0000,0x0003,0x0006,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}},
/* 3 */
{2,{0x0000,0x0002,0x0006,0x0004,0x0000,0x0000,0x0006,0x0003,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}},
/* 4 */
{4,{0x0000,0x0002,0x0007,0x0000,0x0000,0x0002,0x0006,0x0002,
0x0000,0x0000,0x0007,0x0002,0x0000,0x0002,0x0003,0x0002}},
/* 5 */
{4,{0x0000,0x0000,0x000e,0x0002,0x0000,0x0002,0x0002,0x0006,
0x0000,0x0000,0x0004,0x0007,0x0000,0x0006,0x0004,0x0004}},
/* 6 */
{4,{0x0000,0x0000,0x0007,0x0004,0x0000,0x0004,0x0004,0x0006,
0x0000,0x0000,0x0002,0x000e,0x0000,0x0006,0x0002,0x0002}},
};
/*--------------------------------------------------------------------------
函数原形的声明
--------------------------------------------------------------------------*/
void Frame();
void InitWin();
void GameWin();
void EditColor();
void CreateUnit();
void InitOC();
void uparrow();
void AlterUnit();
void GetCirObj();
void ObjPutDyn();
void RefreshSO();
void Calculate();
void QuitJudge();
void GameOver();
void SetNULL();
void LtoA();
void Choice();
void InsertMe();
void PauseControl();
void ReadRegister();
void WriteRegister();
void OutRegister();
void PlaceGraph();
void DisGraph(int srate);
void HelpTopic();
void PutBrick();
#ifdef CONTROL_KEYBORD
void ResetKeybordState();
void SetKeybordState();
#endif
/*--------------------------------------------------------------------------
置空使用者登记表
--------------------------------------------------------------------------*/
void SetNULL()
{
RcdLong=sizeof(PLAYER);
Play=malloc(RcdLong);
Play->sco=0xffffffffffffffff;
Play->lay=1;
Play->forout=0;
Play->next=NULL;
}
/*--------------------------------------------------------------------------
将使用者资料插入使用者登记表
--------------------------------------------------------------------------*/
void InsertMe(char *pn)
{
PLAYER *newplayer,*fit;
Play->lay++;
newplayer=malloc(RcdLong);
strcpy(newplayer->name,pn);
newplayer->sco=Score;
newplayer->lay=Layer;
newplayer->spe=Speed;
newplayer->forout=1;
for(fit=Play;fit->next!=NULL&&fit->next->sco>Score;fit=fit->next);
newplayer->next=fit->next;
fit->next=newplayer;
if(Play->lay>100)
Play->lay=100;
}
/*--------------------------------------------------------------------------
从文件读入使用者登记表
--------------------------------------------------------------------------*/
void ReadRegister()
{
FILE *filename;
PLAYER *fip,*fit;
long readcount;
if((filename=fopen(RFName,"rb"))==NULL)
{
filename=fopen(RFName,"wb");
fwrite(Play,RcdLong,1,filename);
fclose(filename);
filename=fopen(RFName,"rb");
}
fread(Play,RcdLong,1,filename);
fip=Play;
for(readcount=2;readcount<=Play->lay;readcount++)
{
fit=malloc(RcdLong);
fread(fit,RcdLong,1,filename);
fip->next=fit;
fip=fit;
}
fip->next=NULL;
fclose(filename);
}
这里只有一份TURBO C的,可以吗?
---*/
/*--------------------------------------------------------------------------
俄罗斯方块源代码
--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
包含头文件
--------------------------------------------------------------------------*/
#include"dos.h"
#include"bios.h"
#include"math.h"
#include"time.h"
#include"alloc.h"
#include"conio.h"
#include"stdio.h"
#include"stdlib.h"
#include"graphics.h"
/*----------------------------------------------------------------------------------------------------------------------------------------------------*/
/*
#define BUILD_EXECUTE_FILE
*/
/*-生成可执行文件的处理-*/
/*
#define CONTROL_KEYBORD
*/
/*-控制键盘响应时间和重复频率-*/
/*--------------------------------------------------------------------------
--------------------------------------------------------------------------*/
#define OAX 158
#define OAY 114
/*-主游戏窗口及其内容的相对坐标-*/
#define OVX OAX-11
#define OVY OAY-8
/*-预览对象窗口及其内容的相对坐标-*/
#define STX OAX-11
#define STY OAY+284
/*-游戏状态窗口及其内容的相对坐标-*/
#define GRX 345
#define GRY 379
/*-表示得分效率的曲线所在窗口的相对坐标-*/
#define ISNORMAL(can) can>='A'&&can<='Z'||can>='a'&&can<='z'||can>='0'&&can<='9'||can==32
/*-判断can是否为常规的字符-*/
#define DISOBJ(OX,OY) putimage(OX,OY,Unit,COPY_PUT)
/*-显示一个小方块-*/
#define ERAOBJ(OX,OY) putimage(OX,OY,Erase,COPY_PUT)
/*-擦去一个小方块-*/
#define DISHOR(OX,OY) putimage(OX,OY,Distil,AND_PUT)
/*-擦去一行方块-*/
#define LEFTUNABLE(HP) (StaObjCon[HP]+(DynObjCon[HP]<<1))!=(StaObjCon[HP]|(DynObjCon[HP]<<1))
/*-判断是否不能左移-*/
#define RIGHTUNABLE(HP) (StaObjCon[HP]+(DynObjCon[HP]>>1))!=(StaObjCon[HP]|(DynObjCon[HP]>>1))
/*-判断是否不能右移-*/
#define DOWNUNABLE(HP) (StaObjCon[HP+1]+DynObjCon[HP])!=(StaObjCon[HP+1]|DynObjCon[HP])
/*-判断是否不能下降-*/
#define CIRCLEUNABLE(HP,TP) (StaObjCon[HP]+TemOC[TP])!=(StaObjCon[HP]|TemOC[TP])
/*-判断是否不能旋转-*/
/*--------------------------------------------------------------------------
使用者登记表的定义
--------------------------------------------------------------------------*/
typedef struct node
{
char name[20];
long sco;
long lay;
long spe;
int forout;
struct node *next;
}PLAYER;
/*--------------------------------------------------------------------------
全局变量的声明
--------------------------------------------------------------------------*/
unsigned int StaObjCon[30]; /*-静态对象(方块)的容器-*/
unsigned int DynObjCon[29]; /*-动态对象(方块)的容器-*/
unsigned int PVObj[4]; /*-预览对象(方块)的容器-*/
unsigned int TemOC[4]; /*-临时的动态对象(方块)的容器-*/
void far *Unit; /*-选择后的显示的方块所在缓冲区的首址-*/
void far *Erase; /*-非显示的方块所在缓冲区的首址-*/
void far *Distil; /*-清层时擦去方块的矩形所在缓冲区的首址-*/
void far *Un[5]; /*-待选的显示的方块所在缓冲区的首址-*/
int HorPos,VerPos; /*-动态对象的纵向位置和横向位置-*/
int ObjSort,ObjDirect; /*-当前动态对象的种类和显示方向*/
long Speed,Layer,Score; /*-当前的速度、实际清层的层数和得分-*/
long Seed; /*-当前的虚拟的清层的层数(用来计算速度)-*/
struct time SysTime; /*-存放当前系统时间的结构-*/
PLAYER *Play; /*-使用者登记表的头指针-*/
long RepRate; /*-对象定时下降时间的控制-*/
int Finish; /*-程序是否结束的标志-*/
int RcdLong; /*-使用者登记表每个记录的长度-*/
char OriS[5]; /*-显示游戏开始时速度的字符串-*/
int Sound; /*-声音控制-*/
void far *MovGraph; /*-曲线平移使用的图象缓冲区-*/
void far *LongBar; /*-显示字幕使用的图象缓冲区-*/
#ifdef CONTROL_KEYBORD
float RespondTime,RepeatRate; /*-键盘响应时间和重复频率-*/
#endif
char *RFName="regist.rcd"; /*-使用者登记表文件名-*/
/*--------------------------------------------------------------------------
五种方块颜色的设定
--------------------------------------------------------------------------*/
int ColSeries[5][3]={{4,12,5},{2,10,8},{1,9,5},{3,14,6},{7,15,8}};
/*--------------------------------------------------------------------------
七种对象形状和显示方向的定义
--------------------------------------------------------------------------*/
struct
{
int sort;
int obj[4][4];
}Object[7]={ /* 0 */
{1,{0x0000,0x0000,0x0003,0x0003,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}},
/* 1 */
{2,{0x0000,0x0000,0x000f,0x0000,0x0002,0x0002,0x0002,0x0002,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}},
/* 2 */
{2,{0x0000,0x0002,0x0003,0x0001,0x0000,0x0000,0x0003,0x0006,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}},
/* 3 */
{2,{0x0000,0x0002,0x0006,0x0004,0x0000,0x0000,0x0006,0x0003,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}},
/* 4 */
{4,{0x0000,0x0002,0x0007,0x0000,0x0000,0x0002,0x0006,0x0002,
0x0000,0x0000,0x0007,0x0002,0x0000,0x0002,0x0003,0x0002}},
/* 5 */
{4,{0x0000,0x0000,0x000e,0x0002,0x0000,0x0002,0x0002,0x0006,
0x0000,0x0000,0x0004,0x0007,0x0000,0x0006,0x0004,0x0004}},
/* 6 */
{4,{0x0000,0x0000,0x0007,0x0004,0x0000,0x0004,0x0004,0x0006,
0x0000,0x0000,0x0002,0x000e,0x0000,0x0006,0x0002,0x0002}},
};
/*--------------------------------------------------------------------------
函数原形的声明
--------------------------------------------------------------------------*/
void Frame();
void InitWin();
void GameWin();
void EditColor();
void CreateUnit();
void InitOC();
void uparrow();
void AlterUnit();
void GetCirObj();
void ObjPutDyn();
void RefreshSO();
void Calculate();
void QuitJudge();
void GameOver();
void SetNULL();
void LtoA();
void Choice();
void InsertMe();
void PauseControl();
void ReadRegister();
void WriteRegister();
void OutRegister();
void PlaceGraph();
void DisGraph(int srate);
void HelpTopic();
void PutBrick();
#ifdef CONTROL_KEYBORD
void ResetKeybordState();
void SetKeybordState();
#endif
/*--------------------------------------------------------------------------
置空使用者登记表
--------------------------------------------------------------------------*/
void SetNULL()
{
RcdLong=sizeof(PLAYER);
Play=malloc(RcdLong);
Play->sco=0xffffffffffffffff;
Play->lay=1;
Play->forout=0;
Play->next=NULL;
}
/*--------------------------------------------------------------------------
将使用者资料插入使用者登记表
--------------------------------------------------------------------------*/
void InsertMe(char *pn)
{
PLAYER *newplayer,*fit;
Play->lay++;
newplayer=malloc(RcdLong);
strcpy(newplayer->name,pn);
newplayer->sco=Score;
newplayer->lay=Layer;
newplayer->spe=Speed;
newplayer->forout=1;
for(fit=Play;fit->next!=NULL&&fit->next->sco>Score;fit=fit->next);
newplayer->next=fit->next;
fit->next=newplayer;
if(Play->lay>100)
Play->lay=100;
}
/*--------------------------------------------------------------------------
从文件读入使用者登记表
--------------------------------------------------------------------------*/
void ReadRegister()
{
FILE *filename;
PLAYER *fip,*fit;
long readcount;
if((filename=fopen(RFName,"rb"))==NULL)
{
filename=fopen(RFName,"wb");
fwrite(Play,RcdLong,1,filename);
fclose(filename);
filename=fopen(RFName,"rb");
}
fread(Play,RcdLong,1,filename);
fip=Play;
for(readcount=2;readcount<=Play->lay;readcount++)
{
fit=malloc(RcdLong);
fread(fit,RcdLong,1,filename);
fip->next=fit;
fip=fit;
}
fip->next=NULL;
fclose(filename);
}
解决方案 »
- 如何通过鼠标拖放得到链接的url
- const char*类型的变量,如何转换为LPCWSTR?
- 子窗口向父窗口发送消息的问题?
- 请问如何构造Gabor小波系数呢?请指点,多谢了.
- Help!!!有关bitmap的透明显示问题。
- directshow 的显示问题
- 请问输入double型数据的格式符是什么
- 紧急求救:需要C语言考试题目 。
- 网络蚂蚁是怎么得到服务器端的文件名列表的?
- 有沒有c++里定義的全部變量和常量的定義方法,如#define BOOL int和#define TRUE 1等,多多益善
- SOS!新新手的问题:Assertion 是怎么回事?请教高手指点。
- 如何从正在播放的Media Player中得到BMP文件?
http://www.aoxiang.net/doc/index.asp?td=vc 去下载!
记得分哦
向屏幕输出使用者登记表
--------------------------------------------------------------------------*/
void OutRegister()
{
PLAYER *fip;
char *op=" ";
long outi=-1;
long sub;
int outp;
char outsub[10],outsco[12],outlay[10],outspe[5];
gotoxy(1,25);
textcolor(14);
cprintf(" %syour name%s score%s layer%s speed\n\r",op,op,op,op);
textcolor(15);
sub=0;
for(fip=Play->next,outp=1;fip!=NULL&&outp<Play->lay;fip=fip->next)
{
sub++;
LtoA(fip->sco,outsco,10);
LtoA(fip->lay,outlay,6);
LtoA(fip->spe,outspe,3);
LtoA(sub,outsub,8);
if(fip->forout==0)
cprintf(" %s%s%s%s%s%s%s%s%s\n\r",outsub,fip->name,op,outsco,op,outlay,op,outspe);
else
{
textattr(0x0084);
cprintf(" %s%s%s%s%s%s%s%s%s\n\r",outsub,fip->name,op,outsco,op,outlay,op,outspe);
outi=13;
textattr(0x000f);
}
outi--;
if(outi==0)
{
cprintf("Press any key to continue...\n\r");
bioskey(0);
}
}
cprintf("Press any key to quit...");
}
/*--------------------------------------------------------------------------
将长整型数转化为字符串,串长不足lon的以空格补足
--------------------------------------------------------------------------*/
void LtoA(long num,char *str,int lon)
{
int li;
ltoa(num,str,10);
for(li=0;str[li]!=0;li++);
for(;li<lon;li++)
str[li]=32;
str[li]=0;
}
/*--------------------------------------------------------------------------
将使用者登记表写入文件
--------------------------------------------------------------------------*/
void WriteRegister()
{
FILE *filename;
PLAYER *fip;
long readcount;
filename=fopen(RFName,"wb");
fip=Play;
for(readcount=1;readcount<=Play->lay;readcount++)
{
fip->forout=0;
fwrite(fip,RcdLong,1,filename);
fip=fip->next;
}
fclose(filename);
}
/*--------------------------------------------------------------------------
累砖块
--------------------------------------------------------------------------*/
void PutBrick()
{
int brix,briy;
void far *brick;
void far *hbrick;
long ti1,ti2; brick=farmalloc(imagesize(600,460,639,479));
hbrick=farmalloc(imagesize(600,460,619,479));
setcolor(8);
rectangle(600,460,639,479);
setfillstyle(1,1);
bar(601,461,639,479);
settextstyle(0,0,2);
setcolor(9);
outtextxy(601,462,"&");
outtextxy(622,462,"&");
outtextxy(611,462,"&");
setcolor(5);
outtextxy(603,464,"&");
outtextxy(624,464,"&");
outtextxy(613,464,"&");
setcolor(1);
outtextxy(602,463,"&");
outtextxy(623,463,"&");
outtextxy(612,463,"&");
setcolor(9);
line(601,461,639,461);
line(601,461,601,479);
setcolor(5);
line(639,479,601,479);
line(639,479,639,461);
getimage(600,460,639,479,brick);
setcolor(5);
line(619,479,619,461);
getimage(600,460,619,479,hbrick);
ti1=clock();
for(briy=460+2;briy>=0;)
{
for(brix=600;brix>=0;brix-=40)
{
if(brix>602)
putimage(brix+20,briy,hbrick,COPY_PUT);
else if(brix<-2)
putimage(brix+20,briy,hbrick,COPY_PUT);
else
putimage(brix,briy,brick,COPY_PUT);
}
briy-=20;
for(;;)
{
ti2=clock();
if(ti2-ti1>1)
{
ti1=ti2;
break;
}
}
for(brix=-20;brix<=620;brix+=40)
{
if(brix>602)
putimage(brix,briy,hbrick,COPY_PUT);
else if(brix<-2)
putimage(brix+20,briy,hbrick,COPY_PUT);
else
putimage(brix,briy,brick,COPY_PUT);
}
briy-=20;
for(;;)
{
ti2=clock();
if(ti2-ti1>1)
{
ti1=ti2;
break;
}
}
}
farfree(brick);
farfree(hbrick);
for(;;)
{
ti2=clock();
if(ti2-ti1>2)
{
ti1=ti2;
break;
}
}
}
/*--------------------------------------------------------------------------
初始化静态和动态的对象容器
--------------------------------------------------------------------------*/
void InitOC()
{
int c;
unsigned int initstaobj=0x0801;
for(c=0;c<29;c++)
{
StaObjCon[c]=initstaobj;
DynObjCon[c]=0;
}
StaObjCon[29]=0x0fff;
}
/*--------------------------------------------------------------------------
控制键盘响应时间和重复频率
--------------------------------------------------------------------------*/
#ifdef CONTROL_KEYBORD
void ResetKeybordState()
{
/*- Get the respond time and the repeat rate of the keybord
and put them into 'RespondTime' and 'RepeatTime', and
reset the state of the keybord. -*/
}
/*------------------------------------------------------------------------*/
void SetKeybordState()
{
/*- Set the respond time and the repeat rate of the keybord
with the values of 'RespondTime' and 'RepeatTime'. -*/
}
#endif
/*--------------------------------------------------------------------------
画窗口边框的函数
--------------------------------------------------------------------------*/
void Frame(int _l,int _t,int _r,int _b,int _Ty)
{
int oricolor;
oricolor=getcolor();
if(_Ty==1)
setcolor(15);
else if(_Ty==2)
setcolor(8);
else
setcolor(7);
line(_l,_t,_l,_b);
line(_l,_t,_r,_t);
if(_Ty==1)
setcolor(8);
else if(_Ty==2)
setcolor(15);
else
setcolor(7);
line(_r,_t+1,_r,_b);
line(_r,_b,_l+1,_b);
setcolor(oricolor);
}
/*--------------------------------------------------------------------------
图象模式初始化
--------------------------------------------------------------------------*/
void InitWin()
{
int _GD=DETECT;
int _GM;
#ifdef BUILD_EXECUTE_FILE
registerbgidriver(EGAVGA_driver);
#endif
initgraph(&_GD,&_GM,"");
directvideo=0;
}
显示游戏窗口
--------------------------------------------------------------------------*/
void GameWin()
{
int arrx,arry;
/*---背景---*/
EditColor(5,200,202,147);
setcolor(5);
setfillstyle(9,1);
bar(0,0,639,479);
Choice();
PutBrick();
/*---主题---*/
setcolor(15);
line(283,107,565,107);
line(77,407,565,407);
setcolor(7);
line(77,406,565,406);
line(77,408,565,408);
line(283,106,565,106);
line(283,108,565,108);
setcolor(8);
line(77,409,565,409);
line(77,410,565,410);
line(283,109,565,109);
line(283,110,565,110);
settextstyle(0,0,4);
setcolor(8);
outtextxy(176,66,"Magicroom");
setcolor(15);
outtextxy(174,64,"Magicroom");
setcolor(7);
outtextxy(175,65,"Magicroom");
settextstyle(0,0,1);
setcolor(8);
outtextxy(472,69,"R");
setcolor(15);
outtextxy(470,67,"R");
setcolor(7);
outtextxy(471,68,"R");
circle(473,71,7);
/*---主游戏窗口---*/
setfillstyle(1,0);
Frame(OAX,OAY,OAX+111,OAY+276,0);
floodfill(OAX+10,OAY+10,7);
Frame(OAX,OAY,OAX+111,OAY+276,2);
Frame(OAX-1,OAY-1,OAX+112,OAY+277,0);
Frame(OAX-2,OAY-2,OAX+113,OAY+278,0);
Frame(OAX-3,OAY-3,OAX+114,OAY+279,0);
Frame(OAX-4,OAY-4,OAX+115,OAY+280,0);
Frame(OAX-5,OAY-5,OAX+116,OAY+281,0);
Frame(OAX-6,OAY-6,OAX+117,OAY+282,0);
Frame(OAX-7,OAY-7,OAX+118,OAY+283,0);
Frame(OAX-8,OAY-8,OAX+119,OAY+284,1);
Frame(OAX-2,OAY-2,OAX+113,OAY+278,2);
Frame(OAX-4,OAY-4,OAX+115,OAY+280,1);
/*---预览窗口---*/
setfillstyle(1,7);
setcolor(15);
line(OVX-50,OVY,OVX,OVY);
line(OVX-50,OVY,OVX-70,OVY+20);
line(OVX-70,OVY+70,OVX-70,OVY+20);
line(OVX,OVY,OVX,OVY+70);
line(OVX-70,OVY+70,OVX,OVY+70);
floodfill(OVX-10,OVY+10,15);
setcolor(8);
line(OVX,OVY,OVX,OVY+70);
line(OVX-70,OVY+70,OVX,OVY+70);
line(OVX-3,OVY+3,OVX-3,OVY+67);
line(OVX-67,OVY+67,OVX-3,OVY+67);
line(OVX-67,OVY+67,OVX-67,OVY+22);
line(OVX-48,OVY+3,OVX-67,OVY+22);
line(OVX-48,OVY+3,OVX-3,OVY+3);
setfillstyle(1,0);
floodfill(OVX-10,OVY+10,8);
setcolor(15);
line(OVX-3,OVY+3,OVX-3,OVY+67);
line(OVX-67,OVY+67,OVX-3,OVY+67);
/*---游戏状态窗口---*/
setfillstyle(1,7);
setcolor(15);
Frame(STX-70,STY-219,STX,STY,0);
floodfill(STX-10,STY-10,7);
Frame(STX-70,STY-219,STX,STY,1);
setfillstyle(1,0);
bar(STX-67,STY-216,STX-3,STY-3);
Frame(STX-67,STY-216,STX-3,STY-3,2);
setcolor(7);
line(STX-62,STY-128,STX-8,STY-128);
line(STX-62,STY-78,STX-8,STY-78);
line(STX-62,STY-28,STX-8,STY-28);
settextstyle(0,0,1);
setcolor(15);
outtextxy(STX-60,STY-140,"score");
outtextxy(STX-60,STY-90,"layer");
outtextxy(STX-60,STY-40,"speed");
/*---diamond---*/
setcolor(1);
line(STX-46,STY-176,STX-24,STY-176);
line(STX-46,STY-176,STX-41,STY-166);
line(STX-35,STY-176,STX-41,STY-166);
line(STX-35,STY-176,STX-29,STY-166);
line(STX-24,STY-176,STX-29,STY-166);
line(STX-46,STY-176,STX-51,STY-166);
line(STX-24,STY-176,STX-19,STY-166);
line(STX-19,STY-166,STX-51,STY-166);
line(STX-19,STY-166,STX-35,STY-150);
line(STX-51,STY-166,STX-35,STY-150);
line(STX-41,STY-166,STX-35,STY-150);
line(STX-29,STY-166,STX-35,STY-150);
setcolor(14);
line(STX-35,STY-185,STX-35,STY-188);
line(STX-28,STY-185,STX-26,STY-187);
line(STX-42,STY-185,STX-44,STY-187);
line(STX-21,STY-183,STX-19,STY-185);
line(STX-49,STY-183,STX-51,STY-185);
line(STX-14,STY-179,STX-12,STY-181);
line(STX-56,STY-179,STX-58,STY-181);
settextstyle(0,0,2);
setcolor(4);
outtextxy(STX-58,STY-208,"CHE");
settextstyle(0,0,1);
setcolor(14);
outtextxy(STX-59,STY-122,"0");
outtextxy(STX-58,STY-72,"0");
outtextxy(STX-58,STY-22,OriS);
/*--- ---*/
PlaceGraph();
}
/*--------------------------------------------------------------------------
颜色(非系统给出的)的编辑
--------------------------------------------------------------------------*/
void EditColor(int colo,int red,int green,int blue)
{
outportb(0x3c8,colo);
outportb(0x3c9,red);
outportb(0x3c9,green);
outportb(0x3c9,blue);
}
/*--------------------------------------------------------------------------
显示向上的箭头
--------------------------------------------------------------------------*/
void uparrow(int arrx,int arry)
{
setcolor(14);
setfillstyle(1,12);
line(arrx,arry,arrx-10,arry+10);
line(arrx,arry,arrx+10,arry+10);
line(arrx-10,arry+10,arrx-4,arry+10);
line(arrx+4,arry+10,arrx+10,arry+10);
line(arrx-4,arry+17,arrx-4,arry+10);
line(arrx+4,arry+10,arrx+4,arry+17);
line(arrx-4,arry+17,arrx+4,arry+17);
floodfill(arrx,arry+3,14);
}
/*--------------------------------------------------------------------------
游戏开始时对速度和方块颜色的选择
--------------------------------------------------------------------------*/
void Choice()
{
int ox=238,oy=160;
int key;
int co,lr,ud,fr;
char *number[16]={"0","1","2","3","4","5",
"6","7","8","9","10","11",
"12","13","14","15"};
setfillstyle(1,0);
bar(180,120,465,280);
Frame(180,120,465,280,1);
Frame(181,121,464,279,0);
Frame(182,122,463,278,2);
setfillstyle(1,7);
bar(390,250,439,265);
Frame(390,250,439,265,1);
settextstyle(0,0,1);
setcolor(0);
outtextxy(396,254,"Enter");
setcolor(8);
rectangle(392,252,437,263);
setcolor(15);
outtextxy(200,136,"color of the cubes:");
outtextxy(200,216,"speed of falling:");
for(co=0;co<5;co++)
{
putimage(ox,oy,Un[co],COPY_PUT);
ox+=40;
}
settextstyle(0,0,2);
setcolor(14);
outtextxy(370,214,number[0]);
lr=2; ud=0;
ox=323; oy=181;
uparrow(ox,oy);
for(;;)
{
key=bioskey(0)>>8;
if(key==72) /*-上键按下-*/
{
if(ud<15)
{
ud++;
setfillstyle(1,0);
bar(370,214,399,227);
setcolor(4);
settextstyle(0,0,2);
outtextxy(370,214,number[ud]);
}
}
else if(key==80) /*-下键按下-*/
{
if(ud>0)
{
ud--;
setfillstyle(1,0);
bar(370,214,399,227);
setcolor(2);
settextstyle(0,0,2);
outtextxy(370,214,number[ud]);
}
}
else if(key==75) /*-左键按下-*/
{
if(lr>0)
{
lr--;
setfillstyle(1,0);
bar(ox-10,oy,ox+10,oy+17);
ox-=40;
uparrow(ox,oy);
}
}
else if(key==77) /*-右键按下-*/
{
if(lr<4)
{
lr++;
setfillstyle(1,0);
bar(ox-10,oy,ox+10,oy+17);
ox+=40;
uparrow(ox,oy);
}
}
else if(key==28) /*-回车键按下-*/
break;
}
Unit=Un[lr]; /*-选择显示方块的颜色-*/
for(fr=0;fr<4;fr++)
if(fr!=lr)
farfree(Un[fr]);
Speed=ud;
/*---设置虚拟的清层数---*/
if(Speed<=5)
Seed=30*Speed;
else if(Speed<=10)
Seed=150+50*(Speed-5);
else
Seed=400+100*(Speed-10);
RepRate=16-Speed;
strcpy(OriS,number[ud]);
}
创建各种显示或擦除对象所需的图形单元
--------------------------------------------------------------------------*/
void CreateUnit()
{
int ci;
Erase=farmalloc(imagesize(0,0,10,10));
Unit=farmalloc(imagesize(0,0,10,10));
Distil=farmalloc(imagesize(0,0,109,10));
EditColor(3,63,41,6);
setfillstyle(1,0);
bar(0,0,109,10);
getimage(0,0,10,10,Erase); /*-用作擦去单个方块-*/
setcolor(8);
setfillstyle(1,8);
bar(0,0,109,10);
getimage(0,0,109,10,Distil); /*-用作擦去一行方块-*/
/*--- 供选择用的五种颜色的显示方块 ---*/
for(ci=0;ci<5;ci++)
{
Un[ci]=farmalloc(imagesize(0,0,10,10));
setfillstyle(1,ColSeries[ci][0]);
bar(0,0,10,10);
setcolor(ColSeries[ci][1]);
line(0,0,10,0);
line(0,0,0,10);
setcolor(ColSeries[ci][2]);
line(10,0,10,10);
line(10,10,0,10);
getimage(0,0,10,10,Un[ci]);
}
}
/*--------------------------------------------------------------------------
动态对象状态的改变,包括左移、右移、下降和旋转
--------------------------------------------------------------------------*/
void AlterUnit(int type,int downtype)
{
static int endadd=0;
int rcp,recir[2]={0,-1};
int erased[4],oripos,opp;
int misup_1,misup_2,mp,lay=0;
int hpp,vpp,vbp,oi,temod;
int alterable=1,effecient=1;
int temphorp;
int judgebit=0x20002;
long refdelay1,refdelay2;
unsigned sd;
long si;
switch(type)
{
case 0: /*-方块下降-*/
for(hpp=VerPos;hpp>VerPos-4;hpp--)
if(DOWNUNABLE(hpp)) /*-对象不能下降时的处理-*/
{
alterable=0;
effecient=0;
if(VerPos<5)
{
Finish=1;
break;
}
if(downtype)
if(endadd<3)
{
endadd++;
break;
}
endadd=0;
for(hpp=VerPos;hpp>VerPos-4;hpp--)
{
StaObjCon[hpp]=StaObjCon[hpp]|DynObjCon[hpp];
DynObjCon[hpp]=0;
}
for(misup_1=28;misup_1>=4&&StaObjCon[misup_1]&0x07fe;misup_1--)
if(!(StaObjCon[misup_1]^0x0fff))
{
DISHOR(OAX+1,OAY+1+(misup_1-4)*11);
lay++;
}
if(lay)
{
Calculate(lay);
for(misup_2=28;misup_2>=misup_1;misup_2--)
if(!(StaObjCon[misup_2]^0x0fff))
{
for(mp=misup_2;mp>misup_1;mp--)
StaObjCon[mp]=StaObjCon[mp-1];
misup_1++;
misup_2++;
}
refdelay1=clock();
si=clock();
sd=30;
for(;;)
{
if(!Sound)
sound(sd);
refdelay2=clock();
if(refdelay2-refdelay1>=5)
break;
if(refdelay2!=si)
{
si=refdelay2;
sd+=30;
}
}
RefreshSO(); /*-刷新静态对象容器-*/
if(!Sound)
nosound();
}
GetCirObj(1); /*-产生新的对象-*/
}
if(alterable) /*-对象可以下降时的处理-*/
{
oripos=VerPos;
for(opp=3,hpp=VerPos;opp>=0;opp--,hpp--)
{
erased[opp]=DynObjCon[hpp];
DynObjCon[hpp+1]=DynObjCon[hpp];
}
DynObjCon[VerPos-3]=0;
for(opp=3,hpp=VerPos;opp>=0;opp--,hpp--)
erased[opp]=erased[opp]&~DynObjCon[hpp];
VerPos++;
}
break;
case 1: /*-方块左移-*/
if(VerPos<5)
{
effecient=0;
break;
}
for(hpp=VerPos;hpp>VerPos-4;hpp--)
if(LEFTUNABLE(hpp))
{
alterable=0;
effecient=0;
break;
}
if(alterable)
{
oripos=VerPos;
for(opp=3,hpp=VerPos;opp>=0;opp--,hpp--)
{
erased[opp]=DynObjCon[hpp];
DynObjCon[hpp]=DynObjCon[hpp]<<1;
erased[opp]=erased[opp]&~DynObjCon[hpp];
}
HorPos++;
}
break;
case 2: /*-方块右移-*/
if(VerPos<5)
{
effecient=0;
break;
}
for(hpp=VerPos;hpp>VerPos-4;hpp--)
if(RIGHTUNABLE(hpp))
{
alterable=0;
effecient=0;
break;
}
if(alterable)
{
oripos=VerPos;
for(opp=3,hpp=VerPos;opp>=0;opp--,hpp--)
{
erased[opp]=DynObjCon[hpp];
DynObjCon[hpp]=DynObjCon[hpp]>>1;
erased[opp]=erased[opp]&~DynObjCon[hpp];
}
HorPos--;
}
break;
case 3: /*-方块旋转-*/
if(VerPos<5)
{
effecient=0;
break;
}
rcp=0;
temphorp=HorPos;
do{
HorPos=HorPos+recir[rcp];
alterable=1;
effecient=1;
temod=(ObjDirect+1)%Object[ObjSort].sort;
for(oi=0;oi<4;oi++)
TemOC[oi]=Object[ObjSort].obj[temod][oi]<<HorPos-5;
for(hpp=VerPos,oi=3;hpp>VerPos-4;hpp--,oi--)
if(CIRCLEUNABLE(hpp,oi))
{
alterable=0;
effecient=0;
break;
}
rcp++;
}while(!alterable&&(rcp<2)&&(HorPos!=5)&&ObjSort==1);
if(!alterable)
HorPos=temphorp;
if(alterable)
{
oripos=VerPos;
for(opp=3,hpp=VerPos;opp>=0;opp--,hpp--)
erased[opp]=DynObjCon[hpp];
ObjDirect=(ObjDirect+1)%Object[ObjSort].sort;
GetCirObj(0); /*-查表取得新的方块状态-*/
for(opp=3,hpp=VerPos;opp>=0;opp--,hpp--)
erased[opp]=erased[opp]&~DynObjCon[hpp];
}
break;
}
if(effecient) /*-已经移动后画面上的处理-*/
{
for(hpp=VerPos;hpp>VerPos-4;hpp--)
for(vbp=0;vbp<10;vbp++)
if(DynObjCon[hpp]&(judgebit<<vbp)&&hpp>=4)
DISOBJ(OAX+100-11*vbp,OAY+1+(hpp-4)*11);
for(hpp=oripos,opp=3;hpp>oripos-4;hpp--,opp--)
for(vbp=0;vbp<=10;vbp++)
if(erased[opp]&(judgebit<<vbp)&&hpp>=4)
ERAOBJ(OAX+100-11*vbp,OAY+1+(hpp-4)*11);
}
}
/*--------------------------------------------------------------------------
从表中读取初始的对象或以查表方式旋转对象
--------------------------------------------------------------------------*/
void GetCirObj(int corc)
{
static unsigned char randread;
int prvsort,prvdirect;
if(corc==2) /*-游戏开始时第一个对象的生成-*/
{
gettime(&SysTime);
randread=SysTime.ti_hund;
}
if(!corc) /*-旋转操作-*/
{
ObjPutDyn(0,0,0);
}
else /*-新对象生成操作-*/
{
/*---取得新的当前对象---*/
VerPos=4;
HorPos=10;
ObjSort=randread%7;
ObjDirect=randread%Object[ObjSort].sort;
/*---取得下一个对象用作对象预览---*/
gettime(&SysTime);
randread=SysTime.ti_hund;
prvsort=randread%7;
prvdirect=randread%Object[prvsort].sort;
ObjPutDyn(prvsort,prvdirect,1);
}
}
/*--------------------------------------------------------------------------
将查表所得的对象送到动态对象容器
--------------------------------------------------------------------------*/
void ObjPutDyn(int prvs,int prvd,int type)
{
int judgebit=0x0001;
int oi,bp;
int ovx=OVX-25,ovy=OVY+57;
for(oi=0;oi<4;oi++)
{
PVObj[oi]=Object[prvs].obj[prvd][oi];
TemOC[oi]=Object[ObjSort].obj[ObjDirect][oi];
TemOC[oi]=TemOC[oi]<<HorPos-5;
DynObjCon[VerPos-3+oi]=TemOC[oi];
}
if(type) /*-显示对象预览-*/
{
for(oi=0;oi<4;oi++)
for(bp=0;bp<4;bp++)
if(PVObj[oi]&(judgebit<<bp))
DISOBJ(ovx-11*bp,ovy+(oi-4)*11);
else
ERAOBJ(ovx-11*bp,ovy+(oi-4)*11);
}
}