谁能提供个俄罗斯方块的C语言代码??谢谢 求一个简单的c语言写的俄罗斯方块程序

\u4fc4\u7f57\u65af\u65b9\u5757c\u8bed\u8a00\u7684\u4ee3\u7801

\uff081\uff09\u7b2c\u4e00\u4e2acpp\uff1a
#include "colorConsole.h"


HANDLE initiate()
{
HANDLE hOutput;
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
return hOutput;
}
BOOL textout(HANDLE hOutput,int x,int y,WORD wColors[],int nColors,LPTSTR lpszString)
{
DWORD cWritten;
BOOL fSuccess;
COORD coord;

coord.X = x; // start at first cell
coord.Y = y; // of first row
fSuccess = WriteConsoleOutputCharacter(
hOutput, // screen buffer handle
lpszString, // pointer to source string
lstrlen(lpszString), // length of string
coord, // first cell to write to
&cWritten); // actual number written
if (! fSuccess)
cout<<"error:WriteConsoleOutputCharacter"<<endl;


for (;fSuccess && coord.X < lstrlen(lpszString)+x; coord.X += nColors)
{
fSuccess = WriteConsoleOutputAttribute(
hOutput, // screen buffer handle
wColors, // pointer to source string
nColors, // length of string
coord, // first cell to write to
&cWritten); // actual number written
}
if (! fSuccess)
cout<<"error:WriteConsoleOutputAttribute"<<endl;

return 0;
}


(2)\u7b2c\u4e8c\u4e2acpp
#include
#include
#include
#include
#include
#pragma comment(lib,"winmm.lib") //\u64ad\u653e\u80cc\u666f\u97f3\u4e50\u7684\u5934\u6587\u4ef6
#include "colorConsole.h"
#include
#define SQUARE_COLOR BACKGROUD_BLUE|BACKGROUD_RED| BACKGROUD_INTENSITY //\u80cc\u666f\u989c\u8272
#define SQUARE_COLOR FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY //\u65b9\u5757\u7684\u989c\u8272
#define up 72
#define down 80
#define left 75
#define right 77
#define esc 27
#define MAPW 15 //\u5730\u56fe\u7684\u5bbd\u5ea6
#define MAPH 25 //\u5730\u56fe\u7684\u9ad8\u5ea6

void initiate1();
int * build(); //\u521b\u5efa\u65b9\u5757 //\u521d\u59cb\u5316\u5de5\u4f5c
BOOL isavailable(int a[],int x,int y,int w,int h); //\u5224\u5b9a\u662f\u5426\u80fd\u653e\u4e0b
void drawblocks(int a[],int w,int h,int x,int y,WORD wColors[],int nColors);
void delete_cache(); //\u6e05\u9664\u952e\u76d8\u7f13\u51b2\u533a
void revolve(int a[][4],int w,int h,int *x,int y); //\u8f6c\u52a8\u65b9\u5757
void pro();
void end();
void delete_blocks(int *a,int w,int h,int x,int y);
void gameover();
void deletefull_line(int m[][MAPW],int row,int w,int h); //\u6d88\u9664\u4e00\u884c

int dx=30,dy=5; //\u5c4f\u5e55\u4e0a\u7684\u504f\u79fb\u91cf
int score=0,level=0;
int map[MAPH][MAPW];
int a1[4][4]={{1},{1,1,1}};
int a2[4][4]={{0,1},{1,1,1}};
int a3[4][4]={{1,1},{0,1,1}};
int a4[4][4]={{0,0,1},{1,1,1}};
int a5[4][4]={{0,1,1},{1,1}};
int a6[4][4]={{1,1,1,1}};
int a7[4][4]={{1,1},{1,1}};
int a[4][4];

int main()
{
HANDLE handle;
handle=initiate();
WORD wColors[1]={FOREGROUND_BLUE| FOREGROUND_GREEN|FOREGROUND_INTENSITY };
while(1)
{
sndPlaySound("Resource\\Just Dance.wav",SND_LOOP|SND_ASYNC);//\u7528\u5f02\u6b65\u65b9\u5f0f\u64ad\u653e\u97f3\u4e50\uff0cPlaySound\u51fd\u6570\u5728\u5f00\u59cb\u64ad\u653e\u540e\u7acb\u5373\u8fd4\u56de
system("CLS");
int n=0;
printf("\u76ee\u5f55\n1.\u5f00\u59cb\u6e38\u620f\n2.\u9000\u51fa\u6e38\u620f\n\n\n");
scanf("%d",&n);
switch(n)
{
case 1:
system("CLS");
textout(handle,22,6,wColors+2,1,"\u8bf7\u9009\u62e9\u6e38\u620f\u7b49\u7ea7\uff1a");
textout(handle,32,8,wColors+2,1,"1.\u521d\u7ea7");
textout(handle,32,10,wColors+2,1,"2.\u4e2d\u7ea7");
textout(handle,32,12,wColors+2,1,"3.\u9ad8\u7ea7");
while(1)
{
char choice;
choice=_getch();
if(choice=='1')
{
textout(handle,22,6,wColors+2,1,"\u5f00\u59cb\u6e38\u620f\uff0c\u521d\u7ea7");
textout(handle,32,8,wColors+2,1," ");
textout(handle,32,10,wColors+2,1," ");
textout(handle,32,12,wColors+2,1," ");
level=0,score=0;
Sleep(2000);
textout(handle,22,6,wColors+2,1," ");
break;
}
else if(choice=='2')
{
textout(handle,22,6,wColors+2,1,"\u5f00\u59cb\u6e38\u620f\uff0c\u4e2d\u7ea7");
textout(handle,32,8,wColors+2,1," ");
textout(handle,32,10,wColors+2,1," ");
textout(handle,32,12,wColors+2,1," ");
level=2,score=20;
Sleep(2000);
textout(handle,22,6,wColors+2,1," ");
break;
}
else if(choice=='3')
{
textout(handle,22,6,wColors+2,1,"\u5f00\u59cb\u6e38\u620f\uff0c\u9ad8\u7ea7");
textout(handle,32,8,wColors+2,1," ");
textout(handle,32,10,wColors+2,1," ");
textout(handle,32,12,wColors+2,1," ");
level=4,score=40;
Sleep(2000);
textout(handle,22,6,wColors+2,1," ");
break;
}
else if(choice!='1'&&choice!='2'&&choice!='3')
continue;
}
pro();
break;
case 2:
return 0;
default:
printf("\u9519\u8bef\uff0c\u6309\u952e\u7ee7\u7eed");
while(!_kbhit());
}
}
}


void pro() //\u6e38\u620f\u4e3b\u9898
{
initiate1();
int *b=NULL;
b=build(); //\u521b\u5efa\u65b9\u5757
int sign,blank,x,y;
while(1)
{
for(int i=0;i<4;i++) //\u590d\u5236\u65b9\u5757
for(int j=0;j<4;j++)
if(a[i][j]=*(b+i*4+j)) blank=i;
y=1-blank;x=4;
delete_blocks(&a[0][0],4,4,16,10);

b=build();
HANDLE handle;
handle=initiate();
WORD wColors[1]={FOREGROUND_BLUE| FOREGROUND_GREEN|FOREGROUND_INTENSITY };
drawblocks(b,4,4,16,10,wColors,1);

wColors[0]=SQUARE_COLOR;
drawblocks(&a[0][0],4,4,x,y,wColors,1);

delete_cache();

char string[5];
wColors[0]=FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_INTENSITY;
textout(handle,dx-10,8+dy,wColors,1,itoa(score,string,10));
textout(handle,dx-10,14+dy,wColors,1,itoa(level,string,10));

sign=1;
while(sign)
{
int delay=0,max_delay=100-10*level; //\u5ef6\u8fdf\u91cf
while(delay<max_delay)
{
if(_kbhit()) //\u7528if\u907f\u514d\u6309\u4f4f\u952e\u4f7f\u65b9\u5757\u5361\u4f4f
{
int draw=0;
int key=_getch();
switch (key)
{
case up:
delete_blocks(&a[0][0],4,4,x,y);
revolve(a,4,4,&x,y);
draw=1;
break;
case down:
delay=max_delay;
break;
case left:
if(isavailable(&a[0][0],x-1,y,4,4))
{
delete_blocks(&a[0][0],4,4,x,y);
x--;
draw=1;
}
break;
case right:
if(isavailable(&a[0][0],x+1,y,4,4))
{
delete_blocks(&a[0][0],4,4,x,y);
x++;
draw=1;
}
break;
case 32://32 \u662f\u7a7a\u683c\u952e\u7684ASCII\u7801\uff0c\u6309\u7a7a\u683c\u952e\u6682\u505c
while(1)
{
textout(handle,dx,-2+dy,wColors,1,"Press any key to continue");
Sleep(200);
textout(handle,dx,-2+dy,wColors,1," ");
Sleep(200);
if(_kbhit())
{
draw=1;
break;
}
}
break;
case esc://\u6309\u952e\u9000\u51fa\u6e38\u620f
exit(EXIT_SUCCESS);
}
if(draw)
{
HANDLE handle;
handle=initiate();
WORD wColors[1]={SQUARE_COLOR};
drawblocks(&a[0][0],4,4,x,y,wColors,1);
draw=0;
}
}
_sleep(5);delay++;
}
if(isavailable(&a[0][0],x,y+1,4,4)) //\u662f\u5426\u80fd\u4e0b\u79fb
{
delete_blocks(&a[0][0],4,4,x,y);
y++;
HANDLE handle;
handle=initiate();
WORD wColors[1]={SQUARE_COLOR};
drawblocks(&a[0][0],4,4,x,y,wColors,1);
}
else
{
sign=0; //\u6807\u8bb0\uff0c\u4f7f\u8df3\u51fa while(sign) \u5faa\u73af\uff0c\u4ea7\u751f\u65b0\u65b9\u5757
if(y<=1)
{
system("CLS");
HANDLE handle;
handle=initiate();
WORD wColors[1]={FOREGROUND_RED| FOREGROUND_GREEN};
textout(handle,4+dx,6+dy,wColors,1,"GAME OVER!!!");
textout(handle,4+dx,8+dy,wColors,1,"\u5206\u6570\uff1a");
textout(handle,10+dx,8+dy,wColors,1,itoa(score,string,10));
textout(handle,4+dx,10+dy,wColors,1,"\u5236\u4f5c\u8005\uff1a***");
delete_cache();
exit(EXIT_SUCCESS);
} //\u662f\u5426\u7ed3\u675f
for(int i=0;i<4;i++) //\u653e\u4e0b\u65b9\u5757
for(int j=0;j<4;j++)
if(a[i][j]&&((i+y)<MAPH-1)&&((j+x)<MAPW-1))
map[i+y][j+x]=a[i][j];
int full,k=0;
for( i=y;i<min(y+4,MAPH-1);i++)
{
full=1;
for(int j=1;j<14;j++)
if(!map[i][j]) full=0;
if(full) //\u6d88\u6389\u4e00\u884c
{
deletefull_line(map,i,MAPW,MAPH);
k++;
score=score+k;
level=min(score/10,9);
}
}
}
}

}
}
void initiate1() //\u521d\u59cb\u5316
{
int i;
for(i=0;i<25;i++)
{
map[i][0]=-2;
map[i][14]=-2;
}
for(i=0;i<15;i++)
{
map[0][i]=-1;
map[24][i]=-1;
}
map[0][0]=-3;
map[0][14]=-3;
map[24][0]=-3;
map[24][14]=-3;

HANDLE handle;
handle=initiate();
WORD wColors[1]={FOREGROUND_GREEN| FOREGROUND_BLUE|FOREGROUND_INTENSITY};
textout(handle,dx-10,6+dy,wColors,1,"SCORE");
textout(handle,dx-10,12+dy,wColors,1,"LEVEL");
textout(handle,32+dx,8+dy,wColors,1,"NEXT");
wColors[0]=FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY;
drawblocks(&map[0][0],15,25,0,0,wColors,1);
textout(handle,dx,dy,wColors,1,"\u25ce\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u25ce");
wColors[0]=FOREGROUND_BLUE| FOREGROUND_GREEN|FOREGROUND_INTENSITY;
textout(handle,dx+8,dy+5,wColors,1,"\u6309\u4efb\u610f\u952e\u5f00\u59cb");
wColors[0]=FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_INTENSITY ;
textout(handle,dx+7,dy-3,wColors,1,"\u5236\u4f5c\u8005:***");

int x=_getch();
srand(time(NULL));
textout(handle,dx+8,dy+5,wColors,1," ");
}

int * build() //\u521b\u5efa\u65b9\u5757
{
int * a=NULL;
int c=rand()%7;
switch(c)
{
case 0:
a=&a1[0][0];break;
case 1:
a=&a2[0][0];break;
case 2:
a=&a3[0][0];break;
case 3:
a=&a4[0][0];break;
case 4:
a=&a5[0][0];break;
case 5:
a=&a6[0][0];break;
case 6:
a=&a7[0][0];break;
}
return a;
}

void drawblocks(int a[],int w,int h,int x,int y,WORD wColors[],int nColors) //\u753b\u51fa\u65b9\u5757
{
HANDLE handle;
handle = initiate();
int temp;

for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
if((temp=a[i*w+j])&&y+i>0)
{
if(temp==-3)
{
textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"\u25ce");
_sleep(30);
}
else if(temp==-2)
{
textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"\u2551");
_sleep(30);
}

else if(temp==1)
textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"\u25ce");
else if(temp==-1)
{
textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"\u2550");
_sleep(30);
}
}
}

void delete_cache() //\u6e05\u9664\u7f13\u51b2\u533a
{
while(_kbhit())
{
_getch();
}
}

void delete_blocks(int *a,int w,int h,int x,int y) //\u8986\u76d6\u65b9\u5757
{
HANDLE handle;
handle=initiate();
WORD wColors[1]={SQUARE_COLOR};
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
if(a[i*w+j]&&i+y>0)
textout(handle,2*(x+j)+dx,y+i+dy,wColors,1," ");
}


void revolve(int a[][4],int w,int h,int *x,int y) //\u8f6c\u52a8\u65b9\u5757
{
int b[4][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
int sign=0,line=0;
for(int i=h-1;i>=0;i--)
{
for(int j=0;j<w;j++)
if(a[i][j])
{
b[j][line]=a[i][j];
sign=1;
}
if(sign)
{
line++;
sign=0;
}
}
for(i=0;i<4;i++)
if(isavailable(&b[0][0],*x-i,y,w,h))
{
*x-=i;
for(int k=0;k<h;k++)
for(int j=0;j<w;j++)
a[k][j]=b[k][j];
break;
}
}

void deletefull_line(int m[][MAPW],int row,int w,int h) //\u6d88\u9664\u6ee1\u884c\u7684\u65b9\u5757
{
HANDLE handle;
handle=initiate();
WORD wColors[1]={SQUARE_COLOR};
textout(handle,2+dx,row+dy,wColors,1,"\ufe4c\ufe4c\ufe4c\ufe4c\ufe4c\ufe4c\ufe4c\ufe4c\ufe4c\ufe4c");
_sleep(100);

int i;
for(i=row;i>1;i--)
{
delete_blocks(&m[i][1],MAPW-2,1,1,i);
for(int j=1;j<MAPW-1;j++)
m[i][j]=m[i-1][j];
drawblocks(&m[i][1],MAPW-2,1,1,i,wColors,1);
}
for(i=1;i<MAPW-1;i++)
m[1][i]=0;
}

BOOL isavailable(int a[],int x,int y,int w,int h)
{
for(int i=max(y,1);i<y+h;i++)
for(int j=x;j<x+w;j++)
if(map[i][j]&&a[w*(i-y)+j-x])
return 0;
return 1;
}

\u671b\u91c7\u7eb3\uff01\uff01
\uff03i nclude
\uff03i nclude
\uff03i nclude
\uff03i nclude
\uff03i nclude

#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
#define MINBOXSIZE 15 /* \u6700\u5c0f\u65b9\u5757\u7684\u5c3a\u5bf8 */
#define BGCOLOR 7 /* \u80cc\u666f\u7740\u8272 */
#define GX 200
#define GY 10
#define SJNUM 10000 /* \u6bcf\u5f53\u73a9\u5bb6\u6253\u5230\u4e00\u4e07\u5206\u7b49\u7ea7\u52a0\u4e00\u7ea7*/

/* \u6309\u952e\u7801*/
#define VK_LEFT 0x4b00
#define VK_RIGHT 0x4d00
#define VK_DOWN 0x5000
#define VK_UP 0x4800
#define VK_HOME 0x4700
#define VK_END 0x4f00
#define VK_SPACE 0x3920
#define VK_ESC 0x011b
#define VK_ENTER 0x1c0d

/* \u5b9a\u4e49\u4fc4\u7f57\u65af\u65b9\u5757\u7684\u65b9\u5411\uff08\u6211\u5b9a\u4e49\u4ed6\u4e3a4\u79cd\uff09*/
#define F_DONG 0
#define F_NAN 1
#define F_XI 2
#define F_BEI 3

#define NEXTCOL 20 /* \u8981\u51fa\u7684\u4e0b\u4e00\u4e2a\u65b9\u5757\u7684\u7eb5\u5750\u6807*/
#define NEXTROW 12 /* \u8981\u51fa\u7684\u4e0b\u4e00\u4e2a\u65b9\u5757\u7684\u6a2a\u4ece\u6807*/
#define MAXROW 14 /* \u6e38\u620f\u5c4f\u5e55\u5927\u5c0f*/
#define MAXCOL 20
#define SCCOL 100 /*\u6e38\u620f\u5c4f\u5e55\u5927\u663e\u793a\u5668\u4e0a\u7684\u76f8\u5bf9\u4f4d\u7f6e*/
#define SCROW 60



int gril[22][16]; /* \u6e38\u620f\u5c4f\u5e55\u5750\u6807*/
int col=1,row=7; /* \u5f53\u524d\u65b9\u5757\u7684\u6a2a\u7eb5\u5750\u6807*/
int boxfx=0,boxgs=0; /* \u5f53\u524d\u5bfa\u5757\u7684\u5f62\u58ee\u548c\u65b9\u5411*/
int nextboxfx=0,nextboxgs=0,maxcol=22;/*\u4e0b\u4e00\u4e2a\u65b9\u5757\u7684\u5f62\u58ee\u548c\u65b9\u5411*/
int minboxcolor=6,nextminboxcolor=6;
int num=0; /*\u6e38\u620f\u5206*/
int dj=0,gamedj[10]={18,16,14,12,10,8,6,4,2,1};/* \u6e38\u620f\u7b49\u7ea7*/
/* \u4ee5\u4e0b\u6211\u7528\u4e86\u4e00\u4e2a3\u7ef4\u6570\u7ec4\u6765\u7eaa\u5f55\u65b9\u5757\u7684\u6700\u521d\u5f62\u72b6\u548c\u65b9\u5411*/
int boxstr[7][4][16]={{
{1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0},
{0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0},
{1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0},
{0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,0}},
{
{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},
{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0},
{0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0},
{1,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0}},
{
{1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0},
{1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0},
{1,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0},
{0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0}},
{
{1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
{1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0},
{1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0}},
{
{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0},
{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},
{0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0},
{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0}},
{
{1,1,0,0,1,1,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},
{1,1,0,0,1,1,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,1,1,1,0,0,1,0,0,0,0,0,0},
{1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0},
{0,1,0,0,1,1,1,0,0,0,0,0.0,0,0,0},
{0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0}}

};

/* \u968f\u673a\u5f97\u5230\u5f53\u524d\u65b9\u5757\u548c\u4e0b\u4e00\u4e2a\u65b9\u5757\u7684\u5f62\u72b6\u548c\u65b9\u5411*/
void boxrad(){
minboxcolor=nextminboxcolor;
boxgs=nextboxgs;
boxfx=nextboxfx;
nextminboxcolor=random(14)+1;
if(nextminboxcolor==4||nextminboxcolor==7||nextminboxcolor==8)
nextminboxcolor=9;
nextboxfx=F_DONG;
nextboxgs=random(7);
}
/*\u521d\u59cb\u5316\u56fe\u5f62\u6a21\u8bd5*/
void init(int gdrive,int gmode){
int errorcode;
initgraph(&gdrive,&gmode,"e:\\tc");
errorcode=graphresult();
if(errorcode!=grOk){
printf("error of: %s",grapherrormsg(errorcode));
exit(1);
}
}

/* \u5728\u56fe\u5f62\u6a21\u5f0f\u4e0b\u7684\u6e05\u5c4f */
void cls()
{
setfillstyle(SOLID_FILL,0);
setcolor(0);
bar(0,0,640,480);
}
/*\u5728\u56fe\u5f62\u6a21\u5f0f\u4e0b\u7684\u9ad8\u7ea7\u6e05\u5c4f*/
void clscr(int a,int b,int c,int d,int color){
setfillstyle(SOLID_FILL,color);
setcolor(color);
bar(a,b,c,d);
}
/*\u6700\u5c0f\u65b9\u5757\u7684\u7ed8\u5236*/
void minbox(int asc,int bsc,int color,int bdcolor){
int a=0,b=0;
a=SCCOL+asc;
b=SCROW+bsc;
clscr(a+1,b+1,a-1+MINBOXSIZE,b-1+MINBOXSIZE,color);
if(color!=BGCOLOR){
setcolor(bdcolor);
line(a+1,b+1,a-1+MINBOXSIZE,b+1);
line(a+1,b+1,a+1,b-1+MINBOXSIZE);
line(a-1+MINBOXSIZE,b+1,a-1+MINBOXSIZE,b-1+MINBOXSIZE);
line(a+1,b-1+MINBOXSIZE,a-1+MINBOXSIZE,b-1+MINBOXSIZE);
}
}

/*\u6e38\u620f\u4e2d\u51fa\u73b0\u7684\u6587\u5b57*/
void txt(int a,int b,char *txt,int font,int color){
setcolor(color);
settextstyle(0,0,font);
outtextxy(a,b,txt);
}
/*windows \u7ed8\u5236*/
void win(int a,int b,int c,int d,int bgcolor,int bordercolor){
clscr(a,b,c,d,bgcolor);
setcolor(bordercolor);
line(a,b,c,b);
line(a,b,a,d);
line(a,d,c,d);
line(c,b,c,d);

}

/* \u5f53\u524d\u65b9\u5757\u7684\u7ed8\u5236*/
void funbox(int a,int b,int color,int bdcolor){
int i,j;
int boxz[4][4];
for(i=0;i<16;i++)
boxz[i/4][i%4]=boxstr[boxgs][boxfx][i];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(boxz[i][j]==1)
minbox((j+row+a)*MINBOXSIZE,(i+col+b)*MINBOXSIZE,color,bdcolor);
}
/*\u4e0b\u4e00\u4e2a\u65b9\u5757\u7684\u7ed8\u5236*/
void nextfunbox(int a,int b,int color,int bdcolor){
int i,j;
int boxz[4][4];
for(i=0;i<16;i++)
boxz[i/4][i%4]=boxstr[nextboxgs][nextboxfx][i];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(boxz[i][j]==1)
minbox((j+a)*MINBOXSIZE,(i+b)*MINBOXSIZE,color,bdcolor);
}
/*\u65f6\u95f4\u4e2d\u65ad\u5b9a\u4e49*/
#define TIMER 0x1c
int TimerCounter=0;
void interrupt ( *oldhandler)(__CPPARGS);
void interrupt newhandler(__CPPARGS){
TimerCounter++;
oldhandler();
}
void SetTimer(void interrupt (*IntProc)(__CPPARGS)){
oldhandler=getvect(TIMER);
disable();
setvect(TIMER,IntProc);
enable();
}
/*\u7531\u4e8e\u6e38\u620f\u7684\u89c4\u5219\uff0c\u6d88\u6389\u90fd\u6709\u6700\u5c0f\u65b9\u5757\u7684\u4e00\u884c*/
void delcol(int a){
int i,j;
for(i=a;i>1;i--)
for(j=1;j<15;j++){
minbox(j*MINBOXSIZE,i*MINBOXSIZE,BGCOLOR,BGCOLOR);
gril[i][j]=gril[i-1][j];
if(gril[i][j]==1)
minbox(j*MINBOXSIZE,i*MINBOXSIZE,minboxcolor,0);
}
}

/*\u6d88\u6389\u6240\u6709\u90fd\u6709\u6700\u5c0f\u65b9\u5757\u7684\u884c*/
void delete(){
int i,j,zero,delgx=0;
char *nm="00000";
for(i=1;i<21;i++){
zero=0;
for(j=1;j<15;j++)
if(gril[i][j]==0)
zero=1;
if(zero==0){
delcol(i);
delgx++;
}
}
num=num+delgx*delgx*10;
dj=num/10000;

sprintf(nm,"%d",num);
clscr(456,173,500,200,4);
txt(456,173,"Number:",1,15);
txt(456,193,nm,1,15);
}
/*\u65f6\u95f4\u4e2d\u65ad\u7ed3\u675f*/
void KillTimer(){
disable();
setvect(TIMER,oldhandler);
enable();
}
/* \u6d4b\u8bd5\u5f53\u524d\u65b9\u5757\u662f\u5426\u53ef\u4ee5\u5411\u4e0b\u843d*/
int downok(){
int i,j,k=1,a[4][4];
for(i=0;i<16;i++)
a[i/4][i%4]=boxstr[boxgs][boxfx][i];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(a[i][j] && gril[col+i+1][row+j])
k=0;
return(k);
}
/* \u6d4b\u8bd5\u5f53\u524d\u65b9\u5757\u662f\u5426\u53ef\u4ee5\u5411\u5de6\u884c*/
int leftok(){
int i,j,k=1,a[4][4];
for(i=0;i<16;i++)
a[i/4][i%4]=boxstr[boxgs][boxfx][i];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(a[i][j] && gril[col+i][row+j-1])
k=0;
return(k);
}
/* \u6d4b\u8bd5\u5f53\u524d\u65b9\u5757\u662f\u5426\u53ef\u4ee5\u5411\u53f3\u884c*/
int rightok(){
int i,j,k=1,a[4][4];
for(i=0;i<16;i++)
a[i/4][i%4]=boxstr[boxgs][boxfx][i];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(a[i][j] && gril[col+i][row+j+1])
k=0;
return(k);
}
/* \u6d4b\u8bd5\u5f53\u524d\u65b9\u5757\u662f\u5426\u53ef\u4ee5\u53d8\u5f62*/
int upok(){
int i,j,k=1,a[4][4];
for(i=0;i<4;i++)
for(i=0;i<16;i++)
a[i/4][i%4]=boxstr[boxgs][boxfx+1][i];
for(i=3;i>=0;i--)
for(j=3;j>=0;j--)
if(a[i][j] && gril[col+i][row+j])
k=0;
return(k);
}
/*\u5f53\u524d\u65b9\u5757\u843d\u4e0b\u4e4b\u540e\uff0c\u7ed9\u5c4f\u5e55\u5750\u6807\u4f5c\u6807\u8bb0*/
void setgril(){
int i,j,a[4][4];
funbox(0,0,minboxcolor,0);
for(i=0;i<16;i++)
a[i/4][i%4]=boxstr[boxgs][boxfx][i];
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(a[i][j])
gril[col+i][row+j]=1;
col=1;row=7;
}
/*\u6e38\u620f\u7ed3\u675f*/
void gameover(){
int i,j;

for(i=20;i>0;i--)
for(j=1;j<15;j++)
minbox(j*MINBOXSIZE,i*MINBOXSIZE,2,0);
txt(103,203,"Game Over",3,10);
}
/*\u6309\u952e\u7684\u8bbe\u7f6e*/
void call_key(int keyx){
switch(keyx){
case VK_DOWN: { /*\u4e0b\u65b9\u5411\u952e\uff0c\u6a2a\u5750\u6807\u52a0\u4e00\u3002*/
if(downok()){
col++;
funbox(0,0,minboxcolor,0);}
else{
funbox(0,0,minboxcolor,0);
setgril();
nextfunbox(NEXTCOL,NEXTROW,4,4);
boxrad();
nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);
delete();
}
break;
}
case VK_UP: { /*\u4e0a\u65b9\u5411\u952e\uff0c\u65b9\u5411\u5f62\u72b6\u65cb\u8f6c90\u5ea6*/
if(upok())
boxfx++;
if(boxfx>3)
boxfx=0;
funbox(0,0,minboxcolor,0);
break;
}
case VK_LEFT:{ /*\u5de6\u65b9\u5411\u952e\uff0c\u7eb5\u5750\u6807\u51cf\u4e00*/
if(leftok())
row--;
funbox(0,0,minboxcolor,0);
break;
}
case VK_RIGHT:{ /*\u53f3\u65b9\u5411\u952e\uff0c\u7eb5\u5750\u6807\u52a0\u4e00*/
if(rightok())
row++;
funbox(0,0,minboxcolor,0);
break;
}
case VK_SPACE: /*\u7a7a\u683c\u952e\uff0c\u76f4\u63a5\u843d\u5230\u6700\u540e\u53ef\u4ee5\u843d\u5230\u7684\u4eec\u7f6e*/
while(downok())
col++;
funbox(0,0,minboxcolor,0);
setgril();
nextfunbox(NEXTCOL,NEXTROW,4,4);
boxrad();
nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);
delete();
break;
default:
{
txt(423,53,"worng key!",1,4);
txt(428,80,"Plese Enter Anly Key AG!",1,4);
getch();
clscr(420,50,622,97,BGCOLOR);
}
}
}

/*\u65f6\u95f4\u4e2d\u65ad\u5f00\u59cb*/
void timezd(void){
int key;
SetTimer(newhandler);
boxrad();
nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);
for(;;){
if(bioskey(1)){
key=bioskey(0);
funbox(0,0,BGCOLOR,BGCOLOR);
if(key==VK_ESC)
break;
call_key(key);
}
if(TimerCounter>gamedj[dj]){
TimerCounter=0;
if(downok()){
funbox(0,0,BGCOLOR,BGCOLOR);
col++;
funbox(0,0,minboxcolor,0);
}
else {
if(col==1){
gameover();
getch();
break;
}
setgril();
delete();
funbox(0,0,minboxcolor,0);
col=1;row=7;
funbox(0,0,BGCOLOR,BGCOLOR);
nextfunbox(NEXTCOL,NEXTROW,4,4);
boxrad();
nextfunbox(NEXTCOL,NEXTROW,nextminboxcolor,0);
}
}
}
}

/*\u4e3b\u7a0b\u5e8f\u5f00\u59cb*/
void main(void){
int i,j;
char *nm="00000";
init(VGA,VGAHI);
cls();
/*\u5c4f\u5e55\u5750\u6807\u521d\u59cb\u5316*/
for(i=0;i<=MAXCOL+1;i++)
for(j=0;j<=MAXROW+1;j++)
gril[i][j]=0;
for(i=0;i<=MAXCOL+1;i++) {
gril[i][0]=1;
gril[i][15]=1;
}
for(j=1;j<=MAXROW;j++){
gril[0][j]=1;
gril[21][j]=1;
}
clscr(0,0,640,480,15);
win(1,1,639,479,4,15);
win(SCCOL+MINBOXSIZE-2,SCROW+MINBOXSIZE-2,SCCOL+15*MINBOXSIZE+2,SCROW+21*MINBOXSIZE+2,BGCOLOR,0);
nextboxgs=random(8);
nextboxfx=random(4);
sprintf(nm,"%d",num);
txt(456,173,"Number:",1,15);
txt(456,193,nm,1,15);
txt(456,243,"Next Box:",1,15);
timezd();
KillTimer();
closegraph();
}

(1)由于c的随机性函数不好,所以每次游戏开始根据bios时间设置种子。
(2)得分越高,方块下降速度越快(每200分为单位)。
(3)每下落一个方块加1分,每消除一行加10分,两行加30分,三行加70分,四行加150分。初试分数为100分。
游戏控制:
up-旋转;空格-下落到底; 左右下方向键-控制方向。P-开始或暂停游戏。 ESC-退出。
特点:
(1)由于tc不支持中文,所以基本都是英文注释。
(2)函数命名尽可能规范的表达其内部处理目的和过程。
(3)代码加上注释仅有577行。(我下载过的两个俄罗斯方块代码一个在1087行,一个在993行,我的比它们代码少)。
(4)除了消除空格时算法比较复杂,其他算法都比较简单易读。
(5)绘图效率和局部代码效率扔有待提高。
(6)FrameTime参数可能依据不同硬件环境进行具体设置,InitGame需要正确的TC路径。

/********************************/
/* Desc: 俄罗斯方块游戏 */
/* By: hoodlum1980 */
/* Email: [email protected] */
/* Date: 2008.03.12 22:30 */
/********************************/
#include <stdio.h>
#include <bios.h>
#include <dos.h>
#include <graphics.h>
#include <string.h>
#include <stdlib.h>
#define true 1
#define false 0
#define BoardWidth 12
#define BoardHeight 23
#define _INNER_HELPER /*inner helper method */
/*Scan Codes Define*/
enum KEYCODES
{
K_ESC =0x011b,
K_UP =0x4800, /* upward arrow */
K_LEFT =0x4b00,
K_DOWN =0x5000,
K_RIGHT =0x4d00,
K_SPACE =0x3920,
K_P =0x1970
};

/* the data structure of the block */
typedef struct tagBlock
{
char c[4][4]; /* cell fill info array, 0-empty, 1-filled */
int x; /* block position cx [ 0,BoardWidht -1] */
int y; /* block position cy [-4,BoardHeight-1] */
char color; /* block color */
char size; /* block max size in width or height */
char name; /* block name (the block's shape) */
} Block;

/* game's global info */
int FrameTime= 1300;
int CellSize= 18;
int BoardLeft= 30;
int BoardTop= 30;

/* next block grid */
int NBBoardLeft= 300;
int NBBoardTop= 30;
int NBCellSize= 10;

/* score board position */
int ScoreBoardLeft= 300;
int ScoreBoardTop=100;
int ScoreBoardWidth=200;
int ScoreBoardHeight=35;
int ScoreColor=LIGHTCYAN;

/* infor text postion */
int InfoLeft=300;
int InfoTop=200;
int InfoColor=YELLOW;

int BorderColor=DARKGRAY;
int BkGndColor=BLACK;
int GameRunning=true;
int TopLine=BoardHeight-1; /* top empty line */
int TotalScore=100;
char info_score[20];
char info_help[255];
char info_common[255];

/* our board, Board[x][y][0]-isFilled, Board[x][y][1]-fillColor */
unsigned char Board[BoardWidth][BoardHeight][2];
char BufferCells[4][4]; /* used to judge if can rotate block */
Block curBlock; /* current moving block */
Block nextBlock; /* next Block to appear */

/* function list */
int GetKeyCode();
int CanMove(int dx,int dy);
int CanRotate();
int RotateBlock(Block *block);
int MoveBlock(Block *block,int dx,int dy);
void DrawBlock(Block *block,int,int,int);
void EraseBlock(Block *block,int,int,int);
void DisplayScore();
void DisplayInfo(char* text);
void GenerateBlock(Block *block);
void NextBlock();
void InitGame();
int PauseGame();
void QuitGame();

/*Get Key Code */
int GetKeyCode()
{
int key=0;
if(bioskey(1))
{
key=bioskey(0);
}
return key;
}

/* display text! */
void DisplayInfo(char *text)
{
setcolor(BkGndColor);
outtextxy(InfoLeft,InfoTop,info_common);
strcpy(info_common,text);
setcolor(InfoColor);
outtextxy(InfoLeft,InfoTop,info_common);
}

/* create a new block by key number,
* the block anchor to the top-left corner of 4*4 cells
*/
void _INNER_HELPER GenerateBlock(Block *block)
{
int key=(random(13)*random(17)+random(1000)+random(3000))%7;
block->size=3;/* because most blocks' size=3 */
memset(block->c,0,16);
switch(key)
{
case 0:
block->name='T';
block->color=RED;
block->c[1][0]=1;
block->c[1][1]=1, block->c[2][1]=1;
block->c[1][2]=1;
break;
case 1:
block->name='L';
block->color=YELLOW;
block->c[1][0]=1;
block->c[1][1]=1;
block->c[1][2]=1, block->c[2][2]=1;
break;
case 2:
block->name='J';
block->color=LIGHTGRAY;
block->c[1][0]=1;
block->c[1][1]=1;
block->c[1][2]=1, block->c[0][2]=1;
break;
case 3:
block->name='z';
block->color=CYAN;
block->c[0][0]=1, block->c[1][0]=1;
block->c[1][1]=1, block->c[2][1]=1;
break;
case 4:
block->name='5';
block->color=LIGHTBLUE;
block->c[1][0]=1, block->c[2][0]=1;
block->c[0][1]=1, block->c[1][1]=1;
break;
case 5:
block->name='o';
block->color=BLUE;
block->size=2;
block->c[0][0]=1, block->c[1][0]=1;
block->c[0][1]=1, block->c[1][1]=1;
break;
case 6:
block->name='I';
block->color=GREEN;
block->size=4;
block->c[1][0]=1;
block->c[1][1]=1;
block->c[1][2]=1;
block->c[1][3]=1;
break;
}
}

/* get next block! */
void NextBlock()
{
/* copy the nextBlock to curBlock */
curBlock.size=nextBlock.size;
curBlock.color=nextBlock.color;
curBlock.x=(BoardWidth-4)/2;
curBlock.y=-curBlock.size;
memcpy(curBlock.c,nextBlock.c,16);
/* generate nextBlock and show it */
EraseBlock(&nextBlock,NBBoardLeft,NBBoardTop,NBCellSize);
GenerateBlock(&nextBlock);
nextBlock.x=1,nextBlock.y=0;
DrawBlock(&nextBlock,NBBoardLeft,NBBoardTop,NBCellSize);
}

/* rotate the block, update the block struct data */
int _INNER_HELPER RotateCells(char c[4][4],char blockSize)
{
char temp,i,j;
switch(blockSize)
{
case 3:
temp=c[0][0];
c[0][0]=c[2][0], c[2][0]=c[2][2], c[2][2]=c[0][2], c[0][2]=temp;
temp=c[0][1];
c[0][1]=c[1][0], c[1][0]=c[2][1], c[2][1]=c[1][2], c[1][2]=temp;
break;
case 4: /* only 'I' block arived here! */
c[1][0]=1-c[1][0], c[1][2]=1-c[1][2], c[1][3]=1-c[1][3];
c[0][1]=1-c[0][1], c[2][1]=1-c[2][1], c[3][1]=1-c[3][1];
break;
}
}

/* judge if the block can move toward the direction */
int CanMove(int dx,int dy)
{
int i,j,tempX,tempY;
for(i=0;i<curBlock.size;i++)
{
for(j=0;j<curBlock.size;j++)
{
if(curBlock.c[i][j])
{
/* cannot move leftward or rightward */
tempX = curBlock.x + i + dx;
if(tempX<0 || tempX>(BoardWidth-1)) return false; /* make sure x is valid! */
/* cannot move downward */
tempY = curBlock.y + j + dy;
if(tempY>(BoardHeight-1)) return false; /* y is only checked lower bound, maybe negative!!!! */
/* the cell already filled, we must check Y's upper bound before check cell ! */
if(tempY>=0 && Board[tempX][tempY][0]) return false;
}
}
}
return true;
}

/* judge if the block can rotate */
int CanRotate()
{
int i,j,tempX,tempY;
/* update buffer */
memcpy(BufferCells, curBlock.c, 16);
RotateCells(BufferCells,curBlock.size);
for(i=0;i<curBlock.size;i++)
{
for(j=0;j<curBlock.size;j++)
{
if(BufferCells[i][j])
{
tempX=curBlock.x+i;
tempY=curBlock.y+j;
if(tempX<0 || tempX>(BoardWidth-1))
return false;
if(tempY>(BoardHeight-1))
return false;
if(tempY>=0 && Board[tempX][tempY][0])
return false;
}
}
}
return true;
}

/* draw the block */
void _INNER_HELPER DrawBlock(Block *block,int bdLeft,int bdTop,int cellSize)
{
int i,j;
setfillstyle(SOLID_FILL,block->color);
for(i=0;i<block->size;i++)
{
for(j=0;j<block->size;j++)
{
if(block->c[i][j] && (block->y+j)>=0)
{
floodfill(
bdLeft+cellSize*(i+block->x)+cellSize/2,
bdTop+cellSize*(j+block->y)+cellSize/2,
BorderColor);
}
}
}
}

/* Rotate the block, if success, return true */
int RotateBlock(Block *block)
{
char temp,i,j;
int b_success;
if(curBlock.size==2)
return;
if(( b_success=CanRotate()))
{
EraseBlock(block,BoardLeft,BoardTop,CellSize);
memcpy(curBlock.c,BufferCells,16);
DrawBlock(block,BoardLeft,BoardTop,CellSize);
}
return b_success;
}

/* erase a block, only fill the filled cell with background color */
void _INNER_HELPER EraseBlock(Block *block,int bdLeft,int bdTop,int cellSize)
{
int i,j;
setfillstyle(SOLID_FILL,BkGndColor);
for(i=0;i<block->size;i++)
{
for(j=0;j<block->size;j++)
{
if(block->c[i][j] && (block->y+j>=0))
{
floodfill(
bdLeft+cellSize*(i+block->x)+cellSize/2,
bdTop+cellSize*(j+block->y)+cellSize/2,
BorderColor);
}
}
}
}

/* move by the direction if can, donothing if cannot
* return value: true - success, false - cannot move toward this direction
*/
int MoveBlock(Block *block,int dx,int dy)
{
int b_canmove=CanMove(dx,dy);
if(b_canmove)
{
EraseBlock(block,BoardLeft,BoardTop,CellSize);
curBlock.x+=dx;
curBlock.y+=dy;
DrawBlock(block,BoardLeft,BoardTop,CellSize);
}
return b_canmove;
}

/* drop the block to the bottom! */
int DropBlock(Block *block)
{
EraseBlock(block,BoardLeft,BoardTop,CellSize);
while(CanMove(0,1))
{
curBlock.y++;
}
DrawBlock(block,BoardLeft,BoardTop,CellSize);
return 0;/* return value is assign to the block's alive */
}

/* init the graphics mode, draw the board grid */
void InitGame()
{
int i,j,gdriver=DETECT,gmode;
struct time sysTime;
/* draw board cells */
memset(Board,0,BoardWidth*BoardHeight*2);
memset(nextBlock.c,0,16);
strcpy(info_help,"P: Pause Game. --by hoodlum1980");
initgraph(&gdriver,&gmode,"c:\\tc\\");
setcolor(BorderColor);
for(i=0;i<=BoardWidth;i++)
{
line(BoardLeft+i*CellSize, BoardTop, BoardLeft+i*CellSize, BoardTop+ BoardHeight*CellSize);
}
for(i=0;i<=BoardHeight;i++)
{
line(BoardLeft, BoardTop+i*CellSize, BoardLeft+BoardWidth*CellSize, BoardTop+ i*CellSize);
}
/* draw board outer border rect */
rectangle(BoardLeft-CellSize/4, BoardTop-CellSize/4,
BoardLeft+BoardWidth*CellSize+CellSize/4,
BoardTop+BoardHeight*CellSize+CellSize/4);

/* draw next block grids */
for(i=0;i<=4;i++)
{
line(NBBoardLeft+i*NBCellSize, NBBoardTop, NBBoardLeft+i*NBCellSize, NBBoardTop+4*NBCellSize);
line(NBBoardLeft, NBBoardTop+i*NBCellSize, NBBoardLeft+4*NBCellSize, NBBoardTop+ i*NBCellSize);
}

/* draw score rect */
rectangle(ScoreBoardLeft,ScoreBoardTop,ScoreBoardLeft+ScoreBoardWidth,ScoreBoardTop+ScoreBoardHeight);
DisplayScore();

/* set new seed! */
gettime(&sysTime);
srand(sysTime.ti_hour*3600+sysTime.ti_min*60+sysTime.ti_sec);

GenerateBlock(&nextBlock);
NextBlock(); /* create first block */
setcolor(DARKGRAY);
outtextxy(InfoLeft,InfoTop+20,"Up -rotate Space-drop");
outtextxy(InfoLeft,InfoTop+35,"Left-left Right-right");
outtextxy(InfoLeft,InfoTop+50,"Esc -exit");
DisplayInfo(info_help);
}

/* set the isFilled and fillcolor data to the board */
void _INNER_HELPER FillBoardData()
{
int i,j;
for(i=0;i<curBlock.size;i++)
{
for(j=0;j<curBlock.size;j++)
{
if(curBlock.c[i][j] && (curBlock.y+j)>=0)
{
Board[curBlock.x+i][curBlock.y+j][0]=1;
Board[curBlock.x+i][curBlock.y+j][1]=curBlock.color;
}
}
}
}

/* draw one line of the board */
void _INNER_HELPER PaintBoard()
{
int i,j,fillcolor;
for(j=max((TopLine-4),0);j<BoardHeight;j++)
{
for(i=0;i<BoardWidth;i++)
{
fillcolor=Board[i][j][0]? Board[i][j][1]:BkGndColor;
setfillstyle(SOLID_FILL,fillcolor);
floodfill(BoardLeft+i*CellSize+CellSize/2,BoardTop+j*CellSize+CellSize/2,BorderColor);
}
}
}

/* check if one line if filled full and increase the totalScore! */
void _INNER_HELPER CheckBoard()
{
int i,j,k,score=10,sum=0,topy,lines=0;
/* we find the top empty line! */
j=topy=BoardHeight-1;
do
{
sum=0;
for(i=0;i< BoardWidth; i++)
{
sum+=Board[i][topy][0];
}
topy--;
} while(sum>0 && topy>0);

/* remove the full filled line (max remove lines count = 4) */
do
{
sum=0;
for(i=0;i< BoardWidth; i++)
sum+=Board[i][j][0];

if(sum==BoardWidth)/* we find this line is full filled, remove it! */
{
/* move the cells data down one line */
for(k=j; k > topy;k--)
{
for(i=0;i<BoardWidth;i++)
{
Board[i][k][0]=Board[i][k-1][0];
Board[i][k][1]=Board[i][k-1][1];
}
}
/*make the top line empty! */
for(i=0;i<BoardWidth;i++)
{
Board[i][topy][0]=0;
Board[i][topy][1]=0;
}
topy++; /* move the topline downward one line! */
lines++; /* lines <=4 */
TotalScore+=score;
score*=2; /* adding: 10, 30, 70, 150 */
}
else
j--;
} while(sum>0 && j>topy && lines<4);
/* speed up the game when score is high, minimum is 400 */
FrameTime=max(1200-100*(TotalScore/200), 400);
TopLine=topy;/* update the top line */
/* if no lines remove, only add 1: */
if(lines==0)
TotalScore++;
}

/* display the score */
void _INNER_HELPER DisplayScore()
{
setcolor(BkGndColor);
outtextxy(ScoreBoardLeft+5,ScoreBoardTop+5,info_score);
setcolor(ScoreColor);
sprintf(info_score,"Score: %d",TotalScore);
outtextxy(ScoreBoardLeft+5,ScoreBoardTop+5,info_score);
}

/* we call this function when a block is inactive. */
void UpdateBoard()
{
FillBoardData();
CheckBoard();
PaintBoard();
DisplayScore();
}

/* pause the game, and timer handler stop move down the block! */
int PauseGame()
{
int key=0;
DisplayInfo("Press P to Start or Resume!");
while(key!=K_P && key!=K_ESC)
{
while(!(key=GetKeyCode())){}
}
DisplayInfo(info_help);
return key;
}

/* quit the game and do cleaning work. */
void QuitGame()
{
closegraph();
}
/* the entry point function. */
void main()
{
int i,flag=1,j,key=0,tick=0;
InitGame();
if(PauseGame()==K_ESC)
goto GameOver;
/* wait until a key pressed */
while(key!=K_ESC)
{
/* wait until a key pressed */
while(!(key=GetKeyCode()))
{
tick++;
if(tick>=FrameTime)
{
/* our block has dead! (can't move down), we get next block */
if(!MoveBlock(&curBlock,0,1))
{
UpdateBoard();
NextBlock();
if(!CanMove(0,1))
goto GameOver;
}
tick=0;
}
delay(100);
}
switch(key)
{
case K_LEFT:
MoveBlock(&curBlock,-1,0);
break;
case K_RIGHT:
MoveBlock(&curBlock,1,0);
break;
case K_DOWN:
MoveBlock(&curBlock,0,1);
break;
case K_UP:
RotateBlock(&curBlock);
break;
case K_SPACE:
DropBlock(&curBlock);
break;
case K_P:
PauseGame();
break;
}
}
GameOver:
DisplayInfo("GAME OVER! Press any key to exit!");
getch(); /* wait the user Press any key. */
QuitGame();
}
----------------------------------【代码文件结尾】--------------------------------------------------

  • c璇█鍦╲c++涓 缂栫▼鐨淇勭綏鏂鏂规簮绋嬪簭
    绛旓細void NewBlock(); // 鐢熸垚鏂扮殑鏂瑰潡bool CheckBlock(BLOCKINFO _block); // 妫娴嬫寚瀹氭柟鍧楁槸鍚﹀彲浠ユ斁涓媣oid DrawUnit(int x, int y, COLORREF c, DRAW _draw); // 鐢诲崟鍏冩柟鍧梫oid DrawBlock(BLOCKINFO _block, DRAW _draw = SHOW); // 鐢绘柟鍧梫oid OnRotate(); // 鏃嬭浆鏂瑰潡void OnLeft(); // 宸...
  • 鎬庢牱鐢C璇█鍐淇勭綏鏂柟鍧,姹傛寚鏁,璋㈣阿!
    绛旓細棣栧厛浣犺涓嬭浇vc++锛屽垵瀛﹁呭彲浠ョ敤vs98瀹夎濂藉悗鍦ㄩ」鐩腑鍙互娣诲姞濡備笅浠g爜 include "graphics.h"#include <conio.h>#include <stdlib.h>int gcW = 20, gcColor[] = {DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA,MAGENTA, YELLOW};struct tetris { int _pool[16][...
  • 鎬ユ眰VC6.0涓嬬敤C璇█缂栧啓鐨淇勭綏鏂柟鍧楃殑婧愪唬鐮,鎬!!!
    绛旓細void gotoxy(int x,int y){//gotoxy鍦═C涓槸鍦╯ystem.h搴撴枃浠堕噷鐨勪竴涓嚱 COORD c;c.X=x-1; c.Y=y-1;SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);} void Gameover(){//娓告垙缁撴潫鐨勫垽鏂 int i,j,flag=0;for(j=1;j<SIZE_M-1;j++){ if(map[1][j]!=0){ ...
  • pic18f452鐨淇勭綏鏂柟鍧梒璇█绋嬪簭
    绛旓細CTRL_LEFT, CTRL_RIGHT, CTRL_DOWN, // 鏂瑰潡宸︺佸彸銆佷笅绉诲姩 CTRL_SINK, // 鏂瑰潡娌夊簳 CTRL_QUIT // 閫鍑烘父鎴 };// 瀹氫箟缁樺埗鏂瑰潡鐨鏂规硶 enum DRAW { SHOW, // 鏄剧ず鏂瑰潡 HIDE, // 闅愯棌鏂瑰潡 FIX // 鍥哄畾鏂瑰潡 };// 瀹氫箟涓冪淇勭綏鏂柟鍧 struct BLOCK { WORD dir[4]; // 鏂瑰潡鐨勫洓涓棆杞...
  • 澶у彅鐢C璇█瀹炵幇淇勭綏鏂柟鍧灏忔父鎴,楂樻墜鍦ㄦ皯闂!
    绛旓細鎴戣繖娆$粰澶у甯︽潵鐨勬槸锛淇勭綏鏂柟鍧楃殑灏 娓告垙 锛屽湪杩欎釜绋嬪簭涓紝鎴戜滑鍑犱箮鐢ㄥ埌浜嗕箣鍓嶆墍鏈夌殑鐭ヨ瘑鐐癸紝杩樼敤鍒颁簡涓浜沞ge搴撻噷杈圭殑鍑芥暟鍜屽姛鑳斤紝姣斿锛氭寜閿鐞嗭紝鏂囧瓧杈撳嚭銆佸浘褰㈢粯鍒讹紝杩樻湁鍥剧墖鐨勬樉绀虹瓑銆備富瑕佷负澶у璇︾粏浠嬬粛浜哃inux涓C璇█瀹炵幇淇勭綏鏂柟鍧楀皬 娓告垙 锛屽叿鏈変竴瀹氱殑鍙傝冧环鍊硷紝鎰熷叴瓒g殑灏忎紮浼翠滑鍙互鍙傝冧竴涓 ...
  • C璇█涓殑淇勭綏鏂柟鍧
    绛旓細2013-01-19 C璇█涓淇勭綏鏂柟鍧鎬庝箞鍋 1 2013-04-14 鐢╟璇█缂栧啓淇勭綏鏂柟鍧楃▼搴 姹傝瑙 62 2011-10-02 姹侰璇█淇勭綏鏂柟鍧椾唬鐮 546 2018-04-18 涓涓畝鍗鐨刢璇█鍐欑殑淇勭綏鏂柟鍧楃▼搴? 4 2017-12-16 C璇█淇勭綏鏂柟鍧椾唬鐮? 2016-10-26 c璇█淇勭綏鏂柟鍧椾唬鐮 2 2008-03-19 姹備竴浠界敤C璇█缂栧啓鐨勪縿缃楁柉鏂...
  • 璋佽兘鎻愪緵涓縿缃楁柉鏂瑰潡鐨凜璇█浠g爜??璋㈣阿
    绛旓細2011-05-16 姹備竴涓畝鍗曠殑c璇█鍐欑殑淇勭綏鏂柟鍧楃▼搴 27 2016-10-26 c璇█淇勭綏鏂柟鍧椾唬鐮 2 2013-09-22 鐢–璇█缂栧啓鐨勪縿缃楁柉鏂瑰潡浠g爜? 12 2018-01-06 璋佹湁璐悆铔,淇勭綏鏂柟鍧楃殑C璇█浠g爜 2011-10-02 姹侰璇█淇勭綏鏂柟鍧椾唬鐮 546 2013-10-19 姹備釜鑳藉湪VC涓嬭繍琛岀殑淇勭綏鏂柟鍧楃殑C璇█浠g爜,涓嶇敤GRAPHI... ...
  • 瀵绘眰c璇█鐗堢殑淇勭綏鏂柟鍧绋嬪簭
    绛旓細妤间笂鐨勪汉璇寸殑寰堝ソ,浣哹ios.h 鏄疶C 鑷甫鐨,鍏跺畠缂栬瘧鍣ㄩ氫笉杩,鐜板湪鐢ㄧ殑杈冨鐨勭紪璇戝櫒鏄疺C6.0 鎴朧S 2008鎴朇++builder,杩欎簺缂栬瘧鍣ㄩ氫笉杩嘼ios.h缂栬瘧,鑻ヨ瀹屾暣鐨勪唬鐮,鎶婇偖绠卞彿鐣欎笅,鎴戝彂缁欎綘涓涓帇缂╁寘,鏈濂藉浼氱敤宸ュ叿鎵嶈兘椤哄埄閫氳繃缂栬瘧,濡傛灉鍙浜C绋嬪簭璁捐鑰屾病鏈夌湡姝d細鎿嶄綔宸ュ叿,淇勭綏鏂柟鍧绋嬪簭鏄皟璇曚笉鍑烘潵鐨勩 宸...
  • c璇█娓告垙浠g爜澶у叏(鏀跺綍100澶氭缁忓吀娓告垙婧愮爜)
    绛旓細Step2:瑙e帇婧愮爜 浣跨敤瑙e帇杞欢灏嗕笅杞界殑婧愮爜鍘嬬缉鍖呰В鍘嬪埌鏈湴纭洏涓娿係tep3:缂栬瘧婧愮爜 浣跨敤C璇█缂栬瘧鍣紙濡侴CC锛夌紪璇戞簮鐮侊紝鐢熸垚鍙墽琛屾枃浠躲係tep4:杩愯娓告垙 杩愯鐢熸垚鐨勫彲鎵ц鏂囦欢锛屽紑濮嬫父鎴忋傜粡鍏告父鎴忔簮鐮 1.淇勭綏鏂柟鍧 淇勭綏鏂柟鍧楁槸涓娆剧粡鍏哥殑鐩婃櫤娓告垙锛岀帺瀹堕渶瑕侀氳繃鏃嬭浆鍜岀Щ鍔ㄦ柟鍧楋紝浣垮叾鍦ㄤ笅钀借繃绋嬩腑鎺掑垪鎴愬畬鏁...
  • 淇勭綏鏂柟鍧楃殑c璇█婧愪唬鐮 api瀹炵幇
    绛旓細2011-10-31 淇勭綏鏂柟鍧c璇█鐨勪唬鐮 2 2012-10-02 姹侰璇█淇勭綏鏂柟鍧楁簮浠g爜鍟!瑕佽缁嗘敞閲,鑳藉疄鐜版渶鍩虹鐨勫姛鑳藉氨... 2018-04-18 涓涓畝鍗鐨刢璇█鍐欑殑淇勭綏鏂柟鍧楃▼搴? 4 2011-10-02 姹侰璇█淇勭綏鏂柟鍧椾唬鐮 546 2013-09-22 鐢–璇█缂栧啓鐨勪縿缃楁柉鏂瑰潡浠g爜? 6 鏇村绫讳技闂 > 涓...
  • 扩展阅读:俄罗斯方块全免费 ... 手机版俄罗斯方块视频 ... 免费版俄罗斯方块下载 ... 俄罗斯方块消消乐 ... 俄罗斯方块苹果版下载 ... 解压小游戏俄罗斯方块 ... 老版经典俄罗斯方块 ... 俄罗斯向中国借钱多少 ... 俄罗斯方块完整图 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网