俄罗斯方块c语言的代码 求C语言俄罗斯方块代码

\u8c01\u80fd\u63d0\u4f9b\u4e2a\u4fc4\u7f57\u65af\u65b9\u5757\u7684C\u8bed\u8a00\u4ee3\u7801\uff1f\uff1f\u8c22\u8c22

\uff081\uff09\u7531\u4e8ec\u7684\u968f\u673a\u6027\u51fd\u6570\u4e0d\u597d\uff0c\u6240\u4ee5\u6bcf\u6b21\u6e38\u620f\u5f00\u59cb\u6839\u636ebios\u65f6\u95f4\u8bbe\u7f6e\u79cd\u5b50\u3002
\uff082\uff09\u5f97\u5206\u8d8a\u9ad8\uff0c\u65b9\u5757\u4e0b\u964d\u901f\u5ea6\u8d8a\u5feb\uff08\u6bcf200\u5206\u4e3a\u5355\u4f4d\uff09\u3002
\uff083\uff09\u6bcf\u4e0b\u843d\u4e00\u4e2a\u65b9\u5757\u52a01\u5206\uff0c\u6bcf\u6d88\u9664\u4e00\u884c\u52a010\u5206\uff0c\u4e24\u884c\u52a030\u5206\uff0c\u4e09\u884c\u52a070\u5206\uff0c\u56db\u884c\u52a0150\u5206\u3002\u521d\u8bd5\u5206\u6570\u4e3a100\u5206\u3002
\u6e38\u620f\u63a7\u5236\uff1a
up-\u65cb\u8f6c\uff1b\u7a7a\u683c-\u4e0b\u843d\u5230\u5e95\uff1b \u5de6\u53f3\u4e0b\u65b9\u5411\u952e-\u63a7\u5236\u65b9\u5411\u3002P-\u5f00\u59cb\u6216\u6682\u505c\u6e38\u620f\u3002 ESC-\u9000\u51fa\u3002
\u7279\u70b9\uff1a
\uff081\uff09\u7531\u4e8etc\u4e0d\u652f\u6301\u4e2d\u6587\uff0c\u6240\u4ee5\u57fa\u672c\u90fd\u662f\u82f1\u6587\u6ce8\u91ca\u3002
\uff082\uff09\u51fd\u6570\u547d\u540d\u5c3d\u53ef\u80fd\u89c4\u8303\u7684\u8868\u8fbe\u5176\u5185\u90e8\u5904\u7406\u76ee\u7684\u548c\u8fc7\u7a0b\u3002
\uff083\uff09\u4ee3\u7801\u52a0\u4e0a\u6ce8\u91ca\u4ec5\u6709577\u884c\u3002\uff08\u6211\u4e0b\u8f7d\u8fc7\u7684\u4e24\u4e2a\u4fc4\u7f57\u65af\u65b9\u5757\u4ee3\u7801\u4e00\u4e2a\u57281087\u884c\uff0c\u4e00\u4e2a\u5728993\u884c\uff0c\u6211\u7684\u6bd4\u5b83\u4eec\u4ee3\u7801\u5c11\uff09\u3002
\uff084\uff09\u9664\u4e86\u6d88\u9664\u7a7a\u683c\u65f6\u7b97\u6cd5\u6bd4\u8f83\u590d\u6742\uff0c\u5176\u4ed6\u7b97\u6cd5\u90fd\u6bd4\u8f83\u7b80\u5355\u6613\u8bfb\u3002
\uff085\uff09\u7ed8\u56fe\u6548\u7387\u548c\u5c40\u90e8\u4ee3\u7801\u6548\u7387\u6254\u6709\u5f85\u63d0\u9ad8\u3002
\uff086\uff09FrameTime\u53c2\u6570\u53ef\u80fd\u4f9d\u636e\u4e0d\u540c\u786c\u4ef6\u73af\u5883\u8fdb\u884c\u5177\u4f53\u8bbe\u7f6e\uff0cInitGame\u9700\u8981\u6b63\u786e\u7684TC\u8def\u5f84\u3002

/********************************/
/* Desc: \u4fc4\u7f57\u65af\u65b9\u5757\u6e38\u620f */
/* By: hoodlum1980 */
/* Email: [email protected] */
/* Date: 2008.03.12 22\uff1a30 */
/********************************/
#include
#include
#include
#include
#include
#include
#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(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(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;isize;i++)
{
for(j=0;jsize;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;isize;i++)
{
for(j=0;jsize;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();
}
----------------------------------\u3010\u4ee3\u7801\u6587\u4ef6\u7ed3\u5c3e\u3011--------------------------------------------------

\u4fc4\u7f57\u65af\u65b9\u5757C\u6e90\u4ee3\u7801
#include
#include
#include
#include
#define ZL 4 //\u5750\u6807\u589e\u91cf, \u4e0d\u4f7f\u6e38\u620f\u7a97\u53e3\u9760\u8fb9
#define WID 36 //\u6e38\u620f\u7a97\u53e3\u7684\u5bbd\u5ea6
#define HEI 20 //\u6e38\u620f\u7a97\u53e3\u7684\u9ad8\u5ea6
int i,j,Ta,Tb,Tc; // Ta,Tb,Tc\u7528\u4e8e\u8bb0\u4f4f\u548c\u8f6c\u6362\u65b9\u5757\u53d8\u91cf\u7684\u503c
int a[60][60]={0}; //\u6807\u8bb0\u6e38\u620f\u5c4f\u5e55\u5404\u5750\u6807\u70b9\uff1a0,1,2\u5206\u522b\u4e3a\u7a7a\u3001\u65b9\u5757\u3001\u8fb9\u6846
int b[4]; //\u6807\u8bb04\u4e2a"\u53e3"\u65b9\u5757\uff1a1\u6709\uff0c0\u65e0\uff0c\u7c7b\u4f3c\u5f00\u5173
int x,y, level,score,speed; //\u65b9\u5757\u4e2d\u5fc3\u4f4d\u7f6e\u7684x,y\u5750\u6807\uff0c\u6e38\u620f\u7b49\u7ea7\u3001\u5f97\u5206\u548c\u6e38\u620f\u901f\u5ea6
int flag,next; //\u5f53\u524d\u8981\u64cd\u4f5c\u7684\u65b9\u5757\u7c7b\u578b\u5e8f\u53f7\uff0c\u4e0b\u4e00\u4e2a\u65b9\u5757\u7c7b\u578b\u5e8f\u53f7
void gtxy(int m, int n); //\u4ee5\u4e0b\u58f0\u660e\u8981\u7528\u5230\u7684\u81ea\u7f16\u51fd\u6570
void gflag( ); //\u83b7\u5f97\u4e0b\u4e00\u65b9\u5757\u5e8f\u53f7
void csh( ); //\u521d\u59cb\u5316\u754c\u9762
void start( ); //\u5f00\u59cb\u90e8\u5206
void prfk ( ); //\u6253\u5370\u65b9\u5757
void clfk( ); //\u6e05\u9664\u65b9\u5757
void mkfk( ); //\u5236\u4f5c\u65b9\u5757
void keyD( ); //\u6309\u952e\u64cd\u4f5c
int ifmov( ); //\u5224\u65ad\u65b9\u5757\u80fd\u5426\u79fb\u52a8\u6216\u53d8\u4f53
void clHA( ); //\u6e05\u9664\u6ee1\u884c\u7684\u65b9\u5757
void clNEXT( ); //\u6e05\u9664\u8fb9\u6846\u5916\u7684NEXT\u65b9\u5757
int main( )
{ csh( );
while(1)
{start( ); //\u5f00\u59cb\u90e8\u5206
while(1)
{ prfk( );
Sleep(speed); //\u5ef6\u65f6
clfk( );
Tb=x;Tc=flag; //\u4e34\u5b58\u5f53\u524dx\u5750\u6807\u548c\u5e8f\u53f7\uff0c\u4ee5\u5907\u64a4\u9500\u64cd\u4f5c
keyD( );
y++; //\u65b9\u5757\u5411\u4e0b\u79fb\u52a8
if (ifmov( )==0) { y--; prfk( ); dlHA( ); break;} //\u4e0d\u53ef\u52a8\u653e\u4e0b,\u5220\u884c,\u8de8\u51fa\u5faa\u73af
}
for(i=y-2;i<y+2;i++){ if (i==ZL) { j=0; } } //\u65b9\u5757\u89e6\u5230\u6846\u9876
if (j==0) { system("cls");gtxy(10,10);printf("\u6e38\u620f\u7ed3\u675f\uff01"); getch(); break; }
clNEXT( ); //\u6e05\u9664\u6846\u5916\u7684NEXT\u65b9\u5757
}
return 0;
}
void gtxy(int m, int n) //\u63a7\u5236\u5149\u6807\u79fb\u52a8
{COORD pos; //\u5b9a\u4e49\u53d8\u91cf
pos.X = m; //\u6a2a\u5750\u6807
pos.Y = n; //\u7eb5\u5750\u6807
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void csh( ) //\u521d\u59cb\u5316\u754c\u9762
{gtxy(ZL+WID/2-5,ZL-2); printf("\u4fc4\u7f57\u65af\u65b9\u5757"); //\u6253\u5370\u6e38\u620f\u540d\u79f0
gtxy(ZL+WID+3,ZL+7); printf("******* NEXT\uff1a"); //\u6253\u5370\u83dc\u5355\u4fe1\u606f
gtxy(ZL+WID+3,ZL+13); printf("**********");
gtxy(ZL+WID+3,ZL+15); printf("Esc \uff1a\u9000\u51fa\u6e38\u620f");
gtxy(ZL+WID+3,ZL+17); printf("\u2191\u952e\uff1a\u53d8\u4f53");
gtxy(ZL+WID+3,ZL+19); printf("\u7a7a\u683c\uff1a\u6682\u505c\u6e38\u620f");
gtxy(ZL,ZL); printf("\u2554"); gtxy(ZL+WID-2,ZL); printf("\u2557"); //\u6253\u5370\u6846\u89d2
gtxy(ZL,ZL+HEI); printf("\u255a"); gtxy(ZL+WID-2,ZL+HEI); printf("\u255d");
a[ZL][ZL+HEI]=2; a[ZL+WID-2][ZL+HEI]=2; //\u8bb0\u4f4f\u6709\u56fe\u6848
for(i=2;i<WID-2;i+=2) {gtxy(ZL+i,ZL); printf("\u2550"); } //\u6253\u5370\u4e0a\u6a2a\u6846
for(i=2;i<WID-2;i+=2) {gtxy(ZL+i,ZL+HEI); printf("\u2550"); a[ZL+i][ZL+HEI]=2; } //\u4e0b\u6846
for(i=1;i<HEI;i++) { gtxy(ZL,ZL+i); printf("\u2551"); a[ZL][ZL+i]=2; } //\u5de6\u7ad6\u6846\u8bb0\u4f4f\u6709\u56fe\u6848
for(i=1;i<HEI;i++) {gtxy(ZL+WID-2,ZL+i); printf("\u2551"); a[ZL+WID-2][ZL+i]=2; } //\u53f3\u6846
CONSOLE_CURSOR_INFO cursor_info={1,0}; //\u4ee5\u4e0b\u662f\u9690\u85cf\u5149\u6807\u7684\u8bbe\u7f6e
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
level=1; score=0; speed=400;
gflag( ); flag=next; //\u83b7\u5f97\u4e00\u4e2a\u5f53\u524d\u65b9\u5757\u5e8f\u53f7
}
void gflag( ) //\u83b7\u5f97\u4e0b\u4e00\u4e2a\u65b9\u5757\u7684\u5e8f\u53f7
{ srand((unsigned)time(NULL)); next = rand()%19+1; }
void start( ) //\u5f00\u59cb\u90e8\u5206
{ gflag( ); Ta=flag; flag=next; //\u4fdd\u5b58\u5f53\u524d\u65b9\u5757\u5e8f\u53f7\uff0c\u5c06\u4e0b\u4e00\u65b9\u5757\u5e8f\u53f7\u4e34\u65f6\u64cd\u4f5c
x=ZL+WID+6; y=ZL+10; prfk( ); //\u7ed9x,y\u8d4b\u503c\uff0c\u5728\u6846\u5916\u6253\u5370\u51fa\u4e0b\u4e00\u65b9\u5757
flag=Ta; x=ZL+WID/2; y=ZL-1; //\u53d6\u56de\u5f53\u524d\u65b9\u5757\u5e8f\u53f7\uff0c\u5e76\u7ed9x,y\u8d4b\u503c
}
void prfk ( ) //\u6253\u5370\u4fc4\u7f57\u65af\u65b9\u5757
{ for(i=0;i<4;i++) {b[i]=1; } //\u6570\u7ec4b[4]\u6bcf\u4e2a\u5143\u7d20\u7684\u503c\u90fd\u4e3a1
mkfk ( ); //\u5236\u4f5c\u4fc4\u7f57\u65af\u65b9\u5757
for( i= x-2; i<=x+4; i+=2 ) //\u6253\u5370\u65b9\u5757
{ for(j=y-2;jZL ){ gtxy(i,j); printf("\u25a1"); } } }
gtxy(ZL+WID+3,ZL+1); printf("level : %d",level); //\u4ee5\u4e0b\u6253\u5370\u83dc\u5355\u4fe1\u606f
gtxy(ZL+WID+3,ZL+3); printf("score : %d",score);
gtxy(ZL+WID+3,ZL+5); printf("speed : %d",speed);
}
void clfk( ) //\u6e05\u9664\u4fc4\u7f57\u65af\u65b9\u5757
{ for(i=0;i<4;i++) { b[i]=0; } //\u6570\u7ec4b[4]\u6bcf\u4e2a\u5143\u7d20\u7684\u503c\u90fd\u4e3a0
mkfk ( ); //\u5236\u4f5c\u4fc4\u7f57\u65af\u65b9\u5757
for( i=x-2; i<=x+4; i+=2 ) //\u6e05\u9664\u65b9\u5757
{ for(j=y-2;jZL ){ gtxy(i,j); printf(" "); } } }
}
void mkfk( ) //\u5236\u4f5c\u4fc4\u7f57\u65af\u65b9\u5757
{ a[x][ y]=b[0]; //\u65b9\u5757\u4e2d\u5fc3\u4f4d\u7f6e\u72b6\u6001: 1-\u6709,0-\u65e0
switch(flag) //\u51716\u5927\u7c7b\uff0c19\u79cd\u5c0f\u7c7b\u578b
{ case 1: { a[x][y-1]=b[1]; a[x+2][y-1]=b[2]; a[x+2][y]=b[3]; break; } //\u7530\u5b57\u65b9\u5757
case 2: { a[x-2][y]=b[1]; a[x+2][y]=b[2]; a[x+4][y]=b[3]; break; } //\u76f4\u7ebf\u65b9\u5757:----
case 3: { a[x][y-1]=b[1]; a[x][y-2]=b[2]; a[x][y+1]=b[3]; break; } //\u76f4\u7ebf\u65b9\u5757: |
case 4: { a[x-2][y]=b[1]; a[x+2][y]=b[2]; a[x][y+1]=b[3]; break; } //T\u5b57\u65b9\u5757
case 5: { a[x][y-1]=b[1]; a[x][y+1]=b[2]; a[x-2][y]=b[3]; break; } //T\u5b57\u987a\u65f6\u9488\u8f6c90\u5ea6
case 6: { a[x][y-1]=b[1]; a[x-2][y]=b[2]; a[x+2][y]=b[3]; break; } //T\u5b57\u987a\u8f6c180\u5ea6
case 7: { a[x][y-1]=b[1]; a[x][y+1]=b[2]; a[x+2][y]=b[3]; break; } //T\u5b57\u987a\u8f6c270\u5ea6
case 8: { a[x][y+1]=b[1]; a[x-2][y]=b[2]; a[x+2][y+1]=b[3]; break; } //Z\u5b57\u65b9\u5757
case 9: { a[x][y-1]=b[1]; a[x-2][y]=b[2]; a[x-2][y+1]=b[3]; break; } //Z\u5b57\u987a\u8f6c90\u5ea6
case 10: { a[x][y-1]=b[1]; a[x-2][y-1]=b[2]; a[x+2][y]=b[3]; break; } //Z\u5b57\u987a\u8f6c180\u5ea6
case 11: { a[x][y+1]=b[1]; a[x+2][y-1]=b[2]; a[x+2][ y]=b[3]; break; } //Z\u5b57\u987a\u8f6c270\u5ea6
case 12: { a[x][y-1]=b[1]; a[x][y+1]=b[2]; a[x-2][y-1]=b[3]; break; } //7\u5b57\u65b9\u5757
case 13: {a[x-2][y]=b[1]; a[x+2][y-1]=b[2]; a[x+2][y]=b[3]; break; } //7\u5b57\u987a\u8f6c90\u5ea6
case 14: { a[x][y-1]=b[1]; a[x][y+1]=b[2]; a[x+2][y+1]=b[3]; break; } //7\u5b57\u987a\u8f6c180\u5ea6
case 15: { a[x-2][y]=b[1]; a[x-2][y+1]=b[2]; a[x+2][y]=b[3]; break; } //7\u5b57\u987a\u8f6c270\u5ea6
case 16: { a[x][y+1]=b[1]; a[x][y-1]=b[2]; a[x+2][y-1]=b[3]; break; } //\u50127\u5b57\u65b9\u5757
case 17: { a[x-2][y]=b[1]; a[x+2][y+1]=b[2]; a[x+2][y]=b[3]; break; } //\u50127\u5b57\u987a\u8f6c90\u5ea6
case 18: { a[x][y-1]=b[1]; a[x][y+1]=b[2]; a[x-2][y+1]=b[3]; break; } //\u50127\u5b57\u987a\u8f6c180\u5ea6
case 19: { a[x-2][y]=b[1]; a[x-2][y-1]=b[2]; a[x+2][y]=b[3]; break; } //\u50127\u5b57\u987a\u8f6c270\u5ea6
}
}
void keyD( ) //\u6309\u952e\u64cd\u4f5c
{ if (kbhit( ))
{ int key;
key=getch();
if (key==224)
{ key=getch();
if (key==75) { x-=2; } //\u6309\u4e0b\u5de6\u65b9\u5411\u952e\uff0c\u4e2d\u5fc3\u6a2a\u5750\u6807\u51cf2
if (key==77) { x+=2; } //\u6309\u4e0b\u53f3\u65b9\u5411\u952e\uff0c\u4e2d\u5fc3\u6a2a\u5750\u6807\u52a02
if (key==72) //\u6309\u4e0b\u5411\u4e0a\u65b9\u5411\u952e,\u65b9\u5757\u53d8\u4f53
{ if (flag>=2 && flag<=3 ) { flag++; flag%=2; flag+=2; }
if ( flag>=4 && flag<=7 ) { flag++; flag%=4; flag+=4; }
if (flag>=8 && flag<=11 ) { flag++; flag%=4; flag+=8; }
if (flag>=12 && flag<=15 ) { flag++; flag%=4; flag+=12; }
if ( flag>=16 && flag<=19 ) { flag++; flag%=4; flag+=16; } }
}
if (key==32) //\u6309\u7a7a\u683c\u952e\uff0c\u6682\u505c
{ prfk( ); while(1) { if (getch( )==32) { clfk( );break;} } } //\u518d\u6309\u7a7a\u683c\u952e\uff0c\u7ee7\u7eed\u6e38\u620f
if (ifmov( )==0) { x=Tb; flag=Tc; } //\u5982\u679c\u4e0d\u53ef\u52a8\uff0c\u64a4\u9500\u4e0a\u9762\u64cd\u4f5c
else { prfk( ); Sleep(speed); clfk( ); Tb=x;Tc=flag;} //\u5982\u679c\u53ef\u52a8\uff0c\u6267\u884c\u64cd\u4f5c
}
}
int ifmov( ) //\u5224\u65ad\u80fd\u5426\u79fb\u52a8
{ if (a[x][y]!=0) { return 0; } //\u65b9\u5757\u4e2d\u5fc3\u5904\u6709\u56fe\u6848\u8fd4\u56de0\uff0c\u4e0d\u53ef\u79fb\u52a8
else{ if ( (flag==1 && ( a[x][ y-1]==0 && a[x+2][y-1]==0 && a[x+2][y]==0 ) ) ||
(flag==2 && ( a[x-2][y]==0 && a[x+2][y]==0 && a[x+4][y]==0 ) ) ||
(flag==3 && ( a[x][y-1]==0 && a[x][y-2]==0 && a[x][y+1]==0 ) ) ||
(flag==4 && ( a[x-2][y]==0 && a[x+2][y]==0 && a[x][y+1]==0 ) ) ||
(flag==5 && ( a[x][y-1]==0 && a[x][y+1]==0 && a[x-2][y]==0 ) ) ||
(flag==6 && ( a[x][ y-1]==0 && a[x-2][y]==0 && a[x+2][y]==0 ) ) ||
(flag==7 && ( a[x][y-1]==0 && a[x][y+1]==0 && a[x+2][y]==0 ) ) ||
(flag==8 && ( a[x][y+1]==0 && a[x-2][y]==0 && a[x+2][y+1]==0 ) ) ||
(flag==9 && ( a[x][y-1]==0 && a[x-2][y]==0 && a[x-2][y+1]==0 ) ) ||
(flag==10 && ( a[x][y-1]==0 && a[x-2][y-1]==0 && a[x+2][y]==0 ) ) ||
(flag==11 && ( a[x][y+1]==0 && a[x+2][y-1]==0 && a[x+2][y]==0 ) ) ||
(flag==12 && ( a[x][y-1]==0 && a[x][y+1]==0 && a[x-2][y-1]==0 ) ) ||
( flag==13 && ( a[x-2][y]==0 && a[x+2][y-1]==0 && a[x+2][y]==0 ) ) ||
( flag==14 && ( a[x][y-1]==0 && a[x][y+1]==0 && a[x+2][y+1]==0 ) ) ||
(flag==15 && ( a[x-2][y]==0 && a[x-2][y+1]==0 && a[x+2][y]==0 ) ) ||
(flag==16 && ( a[x][y+1]==0 && a[x][y-1]==0 && a[x+2][y-1]==0 ) ) ||
( flag==17 && ( a[x-2][y]==0 && a[x+2][y+1]==0 && a[x+2][y]==0 ) ) ||
(flag==18 && ( a[x][y-1]==0 &&a[x][y+1]==0 && a[x-2][y+1]==0 ) ) ||
(flag==19 && ( a[x-2][y]==0 && a[x-2][y-1]==0
&& a[x+2][y]==0 ) ) ) { return 1; }
}
return 0; //\u5176\u5b83\u60c5\u51b5\u8fd4\u56de0
}
void clNEXT( ) //\u6e05\u9664\u6846\u5916\u7684NEXT\u65b9\u5757
{ flag = next; x=ZL+WID+6; y=ZL+10; clfk( ); }
void clHA( ) //\u6e05\u9664\u6ee1\u884c\u7684\u65b9\u5757
{ int k, Hang=0; //k\u662f\u67d0\u884c\u65b9\u5757\u4e2a\u6570, Hang\u662f\u5220\u9664\u7684\u65b9\u5757\u884c\u6570
for(j=ZL+HEI-1;j>=ZL+1;j--) //\u5f53\u67d0\u884c\u6709WID/2-2\u4e2a\u65b9\u5757\u65f6\uff0c\u5219\u4e3a\u6ee1\u884c
{ k=0; for(i=ZL+2;i<ZL+WID-2;i+=2)
{ if (a[i][j]==1) //\u7ad6\u5750\u6807\u4ece\u4e0b\u5f80\u4e0a\uff0c\u6a2a\u5750\u6807\u7531\u5de6\u81f3\u53f3\u4f9d\u6b21\u5224\u65ad\u662f\u5426\u6ee1\u884c
{ k++; //\u4e0b\u9762\u5c06\u64cd\u4f5c\u5220\u9664\u884c
if (k==WID/2-2) { for(k=ZL+2;k<ZL+WID-2;k+=2)
{ a[k][j]=0; gtxy(k,j); printf(" "); Sleep(1); }
for(k=j-1;k>ZL;k--)
{ for(i=ZL+2;i<ZL+WID-2;i+=2) //\u5df2\u5220\u884c\u6570\u4e0a\u9762\u6709\u65b9\u5757\uff0c\u5148\u6e05\u9664\u518d\u5168\u90e8\u4e0b\u79fb\u4e00\u884c
{ if(a[i][k]==1) { a[i][k]=0; gtxy(i,k); printf(" ");a[i][k+1]=1;
gtxy(i,k+1); printf("\u25a1"); } }
}
j++; //\u65b9\u5757\u4e0b\u79fb\u540e\uff0c\u91cd\u65b0\u5224\u65ad\u5220\u9664\u884c\u662f\u5426\u6ee1\u884c
Hang++; //\u8bb0\u5f55\u5220\u9664\u65b9\u5757\u7684\u884c\u6570
}
}
}
}
score+=100*Hang; //\u6bcf\u5220\u9664\u4e00\u884c\uff0c\u5f97100\u5206
if ( Hang>0 && (score%500==0 || score/500> level-1 ) ) //\u5f97\u5206\u6ee1500\u901f\u5ea6\u52a0\u5feb\u5347\u4e00\u7ea7
{ speed-=20; level++; if(speed<200)speed+=20; }
}

(1)第一个cpp:
#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)第二个cpp
#include <conio.h>
#include <stdlib.h>
#include<stdio.h>
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib") //播放背景音乐的头文件
#include "colorConsole.h"
#include<time.h>
#define SQUARE_COLOR BACKGROUD_BLUE|BACKGROUD_RED| BACKGROUD_INTENSITY //背景颜色
#define SQUARE_COLOR FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY //方块的颜色
#define up 72
#define down 80
#define left 75
#define right 77
#define esc 27
#define MAPW 15 //地图的宽度
#define MAPH 25 //地图的高度

void initiate1();
int * build(); //创建方块 //初始化工作
BOOL isavailable(int a[],int x,int y,int w,int h); //判定是否能放下
void drawblocks(int a[],int w,int h,int x,int y,WORD wColors[],int nColors);
void delete_cache(); //清除键盘缓冲区
void revolve(int a[][4],int w,int h,int *x,int y); //转动方块
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); //消除一行

int dx=30,dy=5; //屏幕上的偏移量
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);//用异步方式播放音乐,PlaySound函数在开始播放后立即返回
system("CLS");
int n=0;
printf("目录\n1.开始游戏\n2.退出游戏\n\n\n");
scanf("%d",&n);
switch(n)
{
case 1:
system("CLS");
textout(handle,22,6,wColors+2,1,"请选择游戏等级:");
textout(handle,32,8,wColors+2,1,"1.初级");
textout(handle,32,10,wColors+2,1,"2.中级");
textout(handle,32,12,wColors+2,1,"3.高级");
while(1)
{
char choice;
choice=_getch();
if(choice=='1')
{
textout(handle,22,6,wColors+2,1,"开始游戏,初级");
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,"开始游戏,中级");
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,"开始游戏,高级");
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("错误,按键继续");
while(!_kbhit());
}
}
}

void pro() //游戏主题
{
initiate1();
int *b=NULL;
b=build(); //创建方块
int sign,blank,x,y;
while(1)
{
for(int i=0;i<4;i++) //复制方块
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; //延迟量
while(delay<max_delay)
{
if(_kbhit()) //用if避免按住键使方块卡住
{
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 是空格键的ASCII码,按空格键暂停
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://按键退出游戏
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)) //是否能下移
{
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; //标记,使跳出 while(sign) 循环,产生新方块
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,"分数:");
textout(handle,10+dx,8+dy,wColors,1,itoa(score,string,10));
textout(handle,4+dx,10+dy,wColors,1,"制作者:***");
delete_cache();
exit(EXIT_SUCCESS);
} //是否结束
for(int i=0;i<4;i++) //放下方块
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) //消掉一行
{
deletefull_line(map,i,MAPW,MAPH);
k++;
score=score+k;
level=min(score/10,9);
}
}
}
}

}
}
void initiate1() //初始化
{
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,"◎═════════════◎");
wColors[0]=FOREGROUND_BLUE| FOREGROUND_GREEN|FOREGROUND_INTENSITY;
textout(handle,dx+8,dy+5,wColors,1,"按任意键开始");
wColors[0]=FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_INTENSITY ;
textout(handle,dx+7,dy-3,wColors,1,"制作者:***");

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

int * build() //创建方块
{
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) //画出方块
{
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,"◎");
_sleep(30);
}
else if(temp==-2)
{
textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,"║");
_sleep(30);
}

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

void delete_cache() //清除缓冲区
{
while(_kbhit())
{
_getch();
}
}

void delete_blocks(int *a,int w,int h,int x,int y) //覆盖方块
{
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) //转动方块
{
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) //消除满行的方块
{
HANDLE handle;
handle=initiate();
WORD wColors[1]={SQUARE_COLOR};
textout(handle,2+dx,row+dy,wColors,1,"﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌");
_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;
}

欢迎lz来俄罗斯方块贴吧探索……图片声音神马的调用一下相关函数就行了。

这个问题还真不知打 不过确实很好玩 呵呵

  • C璇█浠g爜淇勭綏鏂柟鍧(yCodeBlocks)?
    绛旓細HANDLE handle;// 鍒濆鍖栧彞鏌 void initHandle(){ handle = GetStdHandle(STD_OUTPUT_HANDLE);} // 璁剧疆棰滆壊 void setColor(int color){ SetConsoleTextAttribute(handle, color);} void setPos(int x, int y){ //, 锛孋OORD coord = {x*2, y};SetConsoleCursorPosition(handle, coord);} /...
  • c璇█淇勭綏鏂柟鍧椾唬鐮
    绛旓細#define VK_ESC 0x011b #define VK_ENTER 0x1c0d /* 瀹氫箟淇勭綏鏂柟鍧楃殑鏂瑰悜(鎴戝畾涔変粬涓4绉)*/ #define F_DONG 0 #define F_NAN 1 #define F_XI 2 #define F_BEI 3 #define NEXTCOL 20 /* 瑕佸嚭鐨勪笅涓涓柟鍧楃殑绾靛潗鏍*/ #define NEXTROW 12 /* 瑕佸嚭鐨勪笅涓涓柟鍧楃殑妯粠鏍*/ #define MAXRO...
  • 姹C璇█淇勭綏鏂柟鍧椾唬鐮
    绛旓細{gtxy(ZL+WID/2-5,ZL-2); printf("淇勭綏鏂柟鍧"); //鎵撳嵃娓告垙鍚嶇О gtxy(ZL+WID+3,ZL+7); printf("*** NEXT:"); //鎵撳嵃鑿滃崟淇℃伅 gtxy(ZL+WID+3,ZL+13); printf("***"); gtxy(ZL+WID+3,ZL+15); printf("Esc :閫鍑烘父鎴"); gtxy(ZL+WID+3,ZL+17); printf("鈫戦敭:鍙樹綋"); gtxy...
  • 鎬庢牱鐢c璇█缂栧啓淇勭綏鏂柟鍧绋嬪簭?
    绛旓細void mkfk( ) //鍒朵綔淇勭綏鏂柟鍧 { a[x][ y]=b[0]; //鏂瑰潡涓績浣嶇疆鐘舵: 1-鏈,0-鏃 switch(flag) //鍏6澶х被,19绉嶅皬绫诲瀷 { case 1: { a[x][y-1]=b[1]; a[x+2][y-1]=b[2]; a[x+2][y]=b[3]; break; } //鐢板瓧鏂瑰潡 case 2: { a[x-2][y]=b[1]; a[x+2][y]...
  • 淇勭綏鏂柟鍧梒璇█鐨勪唬鐮
    绛旓細int * build() //鍒涘缓鏂瑰潡{ 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...
  • 濡備綍鐢C璇█缂栦竴涓淇勭綏鏂柟鍧
    绛旓細public void Draw(System.IntPtr winHandle) //鍦ㄦ寚瀹氳澶囦笂鐢绘柟鍧 { 鈥︹ } public void Erase(System.IntPtr winHandle)//鎿﹂櫎鏂瑰潡 { 鈥︹ } } Block绫伙細杩欎釜绫绘弿杩扮殑瀵硅薄鏄煇涓涓ぇ鏂瑰潡鐨瀹炰綋銆傛瘡涓ぇ鏂瑰潡鐢卞洓涓皬姝f柟褰㈢粍鎴愶紝涓鍏辨湁7绉嶇粍鍚堟柟寮忋傝繖涓被闇瑕佸疄鐜颁竴涓ぇ鏂瑰潡瀹炰綋鎵鏈夌殑...
  • 姹C璇█淇勭綏鏂柟鍧椾唬鐮
    绛旓細_pool[16][32], (*pool)[32], tmap[8][4][16]; int x, y, s, st, t;}gt;void trsInit() { int sp[8][4] = {{15,4369},{23,785,116,547},{71,275,113,802}, {39,305,114,562},{54,561},{99,306},{51,51},{-1}}; int *p, i,...
  • 姹備竴浠界敤C璇█缂栧啓鐨淇勭綏鏂柟鍧楃殑婧愪唬鐮!
    绛旓細淇勭綏鏂柟鍧桟婧愪唬鐮 #include <stdio.h> #include <windows.h> #include <conio.h> #include #define ZL 4 //鍧愭爣澧為噺, 涓嶄娇娓告垙绐楀彛闈犺竟 #define WID 36 //娓告垙绐楀彛鐨勫搴 #define HEI 20 //娓告垙绐楀彛鐨勯珮搴 int i,j,Ta,Tb,Tc; // Ta,Tb,Tc鐢ㄤ簬璁颁綇鍜岃浆鎹㈡柟鍧楀彉閲忕殑鍊 int a[60][60]={0};...
  • 姹備竴涓畝鍗曠殑c璇█鍐欑殑淇勭綏鏂柟鍧绋嬪簭
    绛旓細score=0; c=bioskey(0); if(c!=4209) goto begin; }鍙﹀,鍥DC缃戜笂鏈夎澶氫骇鍝佸洟璐,渚垮疁鏈夊彛纰 宸茶禐杩 宸茶俯杩< 浣犲杩欎釜鍥炵瓟鐨勮瘎浠锋槸? 璇勮 鏀惰捣 鍏朵粬绫讳技闂 2011-10-02 姹C璇█淇勭綏鏂柟鍧椾唬鐮 2018-04-18 涓涓畝鍗曠殑c璇█鍐欑殑淇勭綏鏂柟鍧楃▼搴? 2008-03-19 姹備竴浠界敤C璇█缂栧啓鐨淇勭綏鏂柟鍧楃殑婧...
  • 鐢c璇█缂栧啓淇勭綏鏂柟鍧绋嬪簭 姹傝瑙
    绛旓細娉ㄦ剰锛氱敱浜庢垜浠敤鐨勬槸EasyX鍥惧舰搴擄紝鏁呮簮鏂囦欢鍚庣紑瑕佷负.cpp锛屼絾鍏朵腑鍐呭閮芥槸C鐨勮娉曘2銆佸瓨鍌ㄨ〃绀哄嚭淇勭綏鏂柟鍧鐨勫舰鐘 涓銆佹垜浠彲浠ョ敤缂栧彿锛屼笉鍚岀殑缂栧彿浠h〃涓嶅悓鐨勪縿缃楁柉鏂瑰潡锛屾牴鎹紪鍙锋妸涓嶅悓鏂瑰潡鐨勭敾娉曞啓鍦ㄤ唬鐮佷腑锛岃繖鏍19绉 鏂瑰潡灏卞緱鏈19绉嶇浉搴鐨勪唬鐮鏉ユ弿缁樸傝屼笖杩欐牱鎵╁睍鎬т笉濂斤紝鑻ヤ互鍚庤璁′簡鏂扮殑鏂瑰潡锛...
  • 扩展阅读:俄罗斯方块网站 ... c语言必背100代码 ... 俄罗斯方块游戏免费版 ... c语言推箱子简单代码 ... c语言代码生成器 ... 俄罗斯方块下载 ... c写俄罗斯方块代码 ... c语言游戏最简单代码 ... 俄罗斯方块游戏代码python ...

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