/*
Author: Zhou Tianya
Email: menjitianya2007@163.com
Blog: http://www.cppblog.com/menjitianya/
Description: impromptu creation, "C console tetris". You are welcome to exchange and discuss it. You can directly paste the code to the VC6.0 environment to run it.
Move left
→ Right shift
Ingress Acceleration
Rotate
For a row that is deleted consecutively, the score is 1 point, the score is 3 points for two rows, the score is 5 points for three rows, and the score is 7 points for four rows.
If the number of credits reaches a certain level, there will be a life-changing activity, with a maximum of 6 credits.
The difficulty will gradually increase with the increase of points, up to 6 of the difficulty.
*/
# Include <iostream>
# Include <windows. h>
# Include <vector>
# Include <mmsystem. h>
# Pragma comment (lib, "winmm. lib ")
Using namespace std;
# Define GameW 10
# Define GameH 20
Const int CtrlLeft = GameW * 2 + 4 + 3;
Struct Point {
Point (){}
Point (int x, int y) {_ x = x, _ y = y ;}
Int _ x, _ y;
};
HANDLE g_hOutput = GetStdHandle (STD_OUTPUT_HANDLE );
HANDLE g_hInput = GetStdHandle (STD_INPUT_HANDLE );
Point g_ptCursor (0, 0 );
BOOL isChecking = FALSE;
BOOL g_bGameOver = FALSE;
Int g_nGameBack [GameH] [GameW], Case;
Int nowKeyInfo =-1;
Int g_nDiff = 1;
Int g_nLife = 2;
Int g_nScore = 0;
Void SetCursor (COORD cd ){
SetConsoleCursorPosition (g_hOutput, cd );
}
Void SetCursor (int x, int y ){
COORD cd = {x, y };
SetCursor (cd );
}
Void SetBlockCursor (int x, int y ){
COORD cd = {2 * x + 2, y + 1 };
SetCursor (cd );
}
Void SetBack (int x, int y, BOOL bk ){
SetBlockCursor (x, y );
If (bk)
Printf ("% s", "■ ");
Else
Printf ("");
}
Bool Out (int x, int y ){
Return x <0 | y <0 | x> = GameW | y> = GameH;
}
Struct xBlock {
Public:
Int len;
Int nowRotateID;
BOOL mask [4] [4] [4];
Static vector <xBlock> List;
XBlock () {len = 0 ;}
XBlock (int l, char * str ){
Int I, j, k;
Len = l;
Memset (mask, FALSE, sizeof (mask ));
For (I = 0; I <l; I ++ ){
For (j = 0; j <l; j ++ ){
Mask [0] [I] [j] = str [I * l + j]-0;
}
}
For (k = 1; k <4; k ++ ){
For (I = 0; I <len; I ++ ){
For (j = 0; j <len; j ++ ){
Mask [k] [I] [j] = mask [k-1] [j] [len-1-i];
}
}
}
NowRotateID = rand () % 4;
}
Void rotate (){
NowRotateID ++;
If (nowRotateID> = 4)
NowRotateID = 0;
}
BOOL getUnit (int x, int y, int roID ){
If (roID =-1 ){
RoID = nowRotateID;
}
Return mask [roID] [y] [x];
}
};
Vector <xBlock> xBlock: List;
Class Block {
Public:
Int x, y;
Int ID;
XBlock bk;
Void reset (xBlock * pbk ){
Bk = * pbk;
X = 4, y = 0;
ID = ++ Case;
If (collide (0, 0 )){
LifeDown ();
}
Draw ();
* Pbk = xBlock: List [rand () % xBlock: List. size ()];
}
Void lifeDown (){
Int I, j;
For (I = 0; I <GameH; I ++ ){
For (j = 0; j <GameW; j ++ ){
SetBack (j, I, TRUE );
Sleep (10 );
}
}
If (g_nLife ){
G_nLife --;
For (I = g_nLife; I <6; I ++ ){
SetCursor (CtrlLeft + I, 15 );
Printf ("% c ",);
}
For (I = GameH-1; I> = 0; I --){
For (j = GameW-1; j> = 0; j --){
SetBack (j, I, FALSE );
Sleep (10 );
G_nGameBack [I] [j] = 0;
}
}
} Else {
G_bGameOver = TRUE;
}
}
Void erase (){
Int I, j;
For (I = 0; I <bk. len; I ++ ){
For (j = 0; j <