沧海一粟之垃圾游戏一
2008-03-08 12:42:19 来源:WEB开发网核心提示:这个方块写得很简单,我只保留了一部分功能,沧海一粟之垃圾游戏一,但能运行,初学编程,不足之处请原谅,不明白之处可以发邮件给我
这个方块写得很简单,我只保留了一部分功能,但能运行,
初学编程,不足之处请原谅,
不明白之处可以发邮件给我。
#include<graphics.h>
#include<stdio.h>
#include<dos.h>
#include<bios.h>
#define TIMEINT 5
#define X x-10
#define d 20
#define up 72
#define left 75
#define right 77
#define enter 2
#define esc 1
int x,y,boxshape,boxdir,start=1;//方块横纵坐标,方块外形,方块方向
int board[22][12];//桌面
int fq[7][4][9]={
{{-2,0,-1,0,0,0,0,1,1},
{0,-1,0,0,-1,1,0,1,2},
{-2,0,-2,1,-1,1,0,1,3},
{-1,-1,-1,0,-1,1,0,-1,0}},
{{-1,-1,-1,0,0,0,0,1,1},
{-1,0,-2,1,-1,1,0,0,2},
{-1,-1,-1,0,0,0,0,1,3},
{-1,0,-2,1,-1,1,0,0,0}},
{{-2,0,-2,1,-1,0,0,0,1},
{-1,-1,0,-1,0,0,0,1,2},
{0,0,-2,1,-1,1,0,1,3},
{-1,-1,-1,0,-1,1,0,1,0}},
{{0,-1,-1,0,0,0,0,1,1},
{-1,0,-2,1,-1,1,0,1,2},
{-1,-1,-1,0,-1,1,0,0,3},
{-2,0,-1,0,-1,1,0,0,0}},
{{-1,0,-1,1,0,0,0,1,1},
{-1,0,-1,1,0,0,0,1,1},
{-1,0,-1,1,0,0,0,1,1},
{-1,0,-1,1,0,0,0,1,1}},
{{-3,0,-2,0,-1,0,0,0,1},
{-1,-1,-1,0,-1,1,-1,2,2},
{-3,0,-2,0,-1,0,0,0,1},
{-1,-1,-1,0,-1,1,-1,2,2}},
{{0,-1,-1,0,-1,1,0,0},
{-2,0,-1,0,-1,1,0,1},
{0,-1,-1,0,-1,1,0,0},
{-2,0,-1,0,-1,1,0,1}},};
int collison();
void init();
void drawbox();
void clearoldbox();
int timeCome();
int get_key();
main()
{
int gdrive=VGA,gmode=VGAHI,errorcode;
int i,j,flag,k,m,key;
initgraph(&gdrive,&gmode,"d:\\tc");
errorcode=graphresult();
if(errorcode!=0)
{PRintf("the graph error:%s",grapherrormsg(errorcode));
printf("press any key to halt");
getch();
exit(1);
}
for(i=0;i<22;i++)
board[i][0]=board[i][11]=1;
for(j=0;j<12;j++)
board[21][j]=1;
for(i=1;i<=20;i++)
for(j=1;j<=10;j++)
board[i][j]=0;
init();
while(1)
{
if(start==1){x=15;y=4;boxshape=rand()%7;boxdir=0;drawbox();start=0;}
if(bioskey(1)!=0)
{key=get_key();
switch(key)
{case left: clearoldbox();
x=x-1;
if(collison())x=x+1;
else x=x;
drawbox();
break;
case right: clearoldbox();
x=x+1;
if(collison())x=x-1;
else x=x;
drawbox();
break;
case up: clearoldbox();
boxdir=(boxdir+1)%4;
if(collison())boxdir=(boxdir+3)%4;
else boxdir=boxdir;
drawbox();
break;
case esc:exit(0);
default :break;
}
}
if(timeCome())
{clearoldbox();
y=y+1;
if(collison())
{if(y>4)y=y-1;
else {getch();exit(0);}
board[y+fq[boxshape][boxdir][0]-1][x+fq[boxshape][boxdir][1]-9]=1;
board[y+fq[boxshape][boxdir][2]-1][x+fq[boxshape][boxdir][3]-9]=1;
board[y+fq[boxshape][boxdir][4]-1][x+fq[boxshape][boxdir][5]-9]=1;
board[y+fq[boxshape][boxdir][6]-1][x+fq[boxshape][boxdir][7]-9]=1;
drawbox();
for(i=20;i>4;i--)
{ flag=1;
for(j=1;j<11;j++)
{flag=flag&&board[i][j];
/*if(board[i][j]==0)flag=1;else flag=flag;*/}
if(flag)
{
for(k=i;k>4;k--)
for(m=1;m<=10;m++)
board[k][m]=board[k-1][m];
init();
}
&nbs
#include<stdio.h>
#include<dos.h>
#include<bios.h>
#define TIMEINT 5
#define X x-10
#define d 20
#define up 72
#define left 75
#define right 77
#define enter 2
#define esc 1
int x,y,boxshape,boxdir,start=1;//方块横纵坐标,方块外形,方块方向
int board[22][12];//桌面
int fq[7][4][9]={
{{-2,0,-1,0,0,0,0,1,1},
{0,-1,0,0,-1,1,0,1,2},
{-2,0,-2,1,-1,1,0,1,3},
{-1,-1,-1,0,-1,1,0,-1,0}},
{{-1,-1,-1,0,0,0,0,1,1},
{-1,0,-2,1,-1,1,0,0,2},
{-1,-1,-1,0,0,0,0,1,3},
{-1,0,-2,1,-1,1,0,0,0}},
{{-2,0,-2,1,-1,0,0,0,1},
{-1,-1,0,-1,0,0,0,1,2},
{0,0,-2,1,-1,1,0,1,3},
{-1,-1,-1,0,-1,1,0,1,0}},
{{0,-1,-1,0,0,0,0,1,1},
{-1,0,-2,1,-1,1,0,1,2},
{-1,-1,-1,0,-1,1,0,0,3},
{-2,0,-1,0,-1,1,0,0,0}},
{{-1,0,-1,1,0,0,0,1,1},
{-1,0,-1,1,0,0,0,1,1},
{-1,0,-1,1,0,0,0,1,1},
{-1,0,-1,1,0,0,0,1,1}},
{{-3,0,-2,0,-1,0,0,0,1},
{-1,-1,-1,0,-1,1,-1,2,2},
{-3,0,-2,0,-1,0,0,0,1},
{-1,-1,-1,0,-1,1,-1,2,2}},
{{0,-1,-1,0,-1,1,0,0},
{-2,0,-1,0,-1,1,0,1},
{0,-1,-1,0,-1,1,0,0},
{-2,0,-1,0,-1,1,0,1}},};
int collison();
void init();
void drawbox();
void clearoldbox();
int timeCome();
int get_key();
main()
{
int gdrive=VGA,gmode=VGAHI,errorcode;
int i,j,flag,k,m,key;
initgraph(&gdrive,&gmode,"d:\\tc");
errorcode=graphresult();
if(errorcode!=0)
{PRintf("the graph error:%s",grapherrormsg(errorcode));
printf("press any key to halt");
getch();
exit(1);
}
for(i=0;i<22;i++)
board[i][0]=board[i][11]=1;
for(j=0;j<12;j++)
board[21][j]=1;
for(i=1;i<=20;i++)
for(j=1;j<=10;j++)
board[i][j]=0;
init();
while(1)
{
if(start==1){x=15;y=4;boxshape=rand()%7;boxdir=0;drawbox();start=0;}
if(bioskey(1)!=0)
{key=get_key();
switch(key)
{case left: clearoldbox();
x=x-1;
if(collison())x=x+1;
else x=x;
drawbox();
break;
case right: clearoldbox();
x=x+1;
if(collison())x=x-1;
else x=x;
drawbox();
break;
case up: clearoldbox();
boxdir=(boxdir+1)%4;
if(collison())boxdir=(boxdir+3)%4;
else boxdir=boxdir;
drawbox();
break;
case esc:exit(0);
default :break;
}
}
if(timeCome())
{clearoldbox();
y=y+1;
if(collison())
{if(y>4)y=y-1;
else {getch();exit(0);}
board[y+fq[boxshape][boxdir][0]-1][x+fq[boxshape][boxdir][1]-9]=1;
board[y+fq[boxshape][boxdir][2]-1][x+fq[boxshape][boxdir][3]-9]=1;
board[y+fq[boxshape][boxdir][4]-1][x+fq[boxshape][boxdir][5]-9]=1;
board[y+fq[boxshape][boxdir][6]-1][x+fq[boxshape][boxdir][7]-9]=1;
drawbox();
for(i=20;i>4;i--)
{ flag=1;
for(j=1;j<11;j++)
{flag=flag&&board[i][j];
/*if(board[i][j]==0)flag=1;else flag=flag;*/}
if(flag)
{
for(k=i;k>4;k--)
for(m=1;m<=10;m++)
board[k][m]=board[k-1][m];
init();
}
&nbs
- ››游戏定位成牵引Android发展的火车头
- ››游戏场景烘焙贴图制作
- ››垃圾邮件死光光-SpamAssassin 3.3.1 发布了
- ››游戏植物大战僵尸 iPhone 版9天销售额超100万美元...
- ››游戏开发包 iPhone cocos2d 初体验
- ››垃圾邮件杀光光,SpamAssassin 3.3.0发布
- ››游戏三维怪物施法特效教程
- ››游戏人生Silverlight(2) - 趣味钢琴[Silverlight ...
- ››游戏人生Silverlight(3) - 打苍蝇[Silverlight 2....
- ››游戏人生Silverlight(4) - 连连看[Silverlight 2....
- ››游戏人生Silverlight(5) - 星际竞技场[Silverligh...
- ››游戏《封神榜》人物纣王3DMAX制作全过程
赞助商链接