中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > 综合其它
超级俄罗斯方块
作者:未知 时间:2005-09-13 23:33 出处:Blog.ChinaUnix.net 责编:chinaitpower
              摘要:超级俄罗斯方块
/*-------------------------------------------------------*/
/*  sunwise 整理于 2002/5/27/14:35  Original 1999   */
/*                                                       */ 
/*-------------------------------------------------------*/

/*-------------  Compile  ------------------------------ */
/*        [in os mode:]                                  */
/*            bgiobj  egavga                             */
/*            tlib    libgraphics.lib+egavga            */
/*        [in TC: ]      */
/*       make exe      */ 
/*-------------------------------------------------------*/
#include 
#include 
#include 
#define mDRAW     5
#define mLINE     6
#define mADOWN    7
#define mGEN      8
#define mLEFT     75
#define mRIGHT    77
#define mSPACE    57
#define mDOWN     80
#define mESC      1
#define TIMEINT   2
#define MAXX      9
#define MAXY   30
#define BACKCOLOR BLACK
#define WINX      50
#define WINY      470
#define GAP       6
#define AREAX     (WINX+GAP)
#define AREAY     (WINY-GAP)
#define BOXW      15

int oldarea[MAXY+1][MAXX];
int area[MAXY+1][MAXX];
int actW,actH,actX,actY;
int curX,curY,curColor,curW,curH;
int newX,newY,newColor,newW,newH;
int active;
int box[4][4];
int FORCOLOR;
int MESSAGE;
int BOX[7][4][4]={
 {
  ,
  ,
  ,
  
 },{
  ,
  ,
  ,
  
 },{
  ,
  ,
  ,
  

 },{
  ,
  ,
  ,
  
 },{
  ,
  ,
  ,
  
 },{
  ,
  ,
  ,
  
 },{
  ,
  ,
  ,
  
 }
};


void init();
void draw();
int genBox();
int getKey();
void lineFull();
int moveLeft();
int moveRight();
int moveDown();
int rotate();
int getW();
int getH();
void clearOldBox();
void putNewBox();
int collisionRotate(int box[][4]);
void getMessage();
void dispatchMessage();
int timeCome();
void fallDown();
int gameOver();

main()
{
 int i;
 init();
 do
 {
  getMessage();
  dispatchMessage();
 }
 while(!gameOver());

 getch();
 closegraph();
}

void getMessage()
{
 if(MESSAGE) return;
 if(timeCome())
 {
  MESSAGE=mADOWN;
  return;
 }
 if(bioskey(1))
 {
  MESSAGE=bioskey(0)>>8;
  return;
 }
}

void dispatchMessage()
{
 switch(MESSAGE)
 {
  case mLEFT:  moveLeft();break;
  case mRIGHT: moveRight();break;
  case mADOWN: moveDown();break;
  case mSPACE: rotate();break;
  case mDOWN:  fallDown(); break;
  case mDRAW:  draw();break;
  case mLINE:  lineFull();break;
  case mGEN:   genBox();break;
  case mESC:   closegraph(); exit(0);
  default:     MESSAGE=0;
 }
}

void fallDown()
{
 while(active)
 {
  moveDown(); draw();
 }

 MESSAGE=mLINE;
}

int timeCome()
{

 static long tm, old;
 tm=biostime(0,tm);
 if(tm-old=MAXX)curX=MAXX-1-curW;
 curY=MAXY-1-curH;
 newX=curX; newY=curY; actX=curX;actY=curY;
 actW=newW=curW; actH=newH=curH;
 active=1;
 if(collision(box)) return 0;
 putNewBox();
 draw(); MESSAGE=0;
 return 1;
}

void lineFull()
{
 int row,col, rowEnd,full,i,j;
 rowEnd=newY+newH;
 if(rowEnd>=MAXY-1) rowEnd=MAXY-2;
 for(row=newY; row<=rowEnd;)
 {
  full=1;
  for(col=0;colcurH? newH:curH;
 actW=curX+actH-newX;
 actX=newX; actY=newY; curX=newX;
 curY=newY; curW=newW; curH=newH;
 MESSAGE=mDRAW;
 return 1;
}

int getW()
{
 int i,j;
 for(i=3;i>0;i--)
  for(j=0;j<4;j++)
   if(box[j][i]) return i;
 return 0;
}

int getH()
{
 int i,j;
 for(j=3;j>0;j--)
  for(i=0;i<4;i++)
   if(box[j][i]) return j;
 return 0;
}


void clearOldBox()
{
 int i,j;
 for(j=0;j<=curH; j++)
  for(i=0;i<=curW; i++)
   if(box[j][i])
    area[curY+j][curX+i]=0;
}

void putNewBox()
{
 int i,j;
 for(j=0;j<=newH;j++)
  for(i=0;i<=newW;i++)
   if(box[j][i])
    area[newY+j][newX+i]=FORCOLOR;
}

int collision(int cbox[][4])
{
 int i,j;
 if(newX<0) return 1;
 if(newX+newW>=MAXX) return 1;
 if(newY<0) return 1;
 for(j=0;j<=newH;j++)
  for(i=0;i<=newW;i++)
   if(area[newY+j][newX+i]&&cbox[j][i]) return 1;
 return 0;
}

int collisionRotate(int cbox[][4])
{
 int i,j;
 if(newX+newW>=MAXX) newX=MAXX-1-newW;
 if(newY+newH>=MAXY) newY=MAXY-1-newH;
 if(collision(cbox)) return 1;
 for(i=0;i<=newW;i++)
  for(j=0;j<=newH;j++)
   if(area[newY+j][newX+i])
   {
    newX-=newW-i+1; goto L;
   }
 L: return collision(cbox);
}

int gameOver()
{
 if(!active &&(curY+curH>MAXY-3)) return 1;
 else return 0;
}

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有