WEB开发网
开发学院软件开发C++ 沧海一粟之垃圾游戏一 阅读

沧海一粟之垃圾游戏一

 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

Tags:沧海一粟 垃圾 游戏

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接