操作说明:
D F:左右旋转
J L:左右移动
E(一堆键都行): 加快下落速度
空格: 开始游戏 与 一落到底
上代码!
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <windows.h>
#include <ctime>
#include <conio.h>
#include <iostream>
using namespace std;
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define inf 2147483647
struct type_block
{
int a[10][10];
int color;
int size;
}now, nextA, nextB, nextC, hold;
int sblock[20][10][10] = {
{
{7, 0, 0, 0}, {0, 0, 1, 1}, {0, 1, 1, 0}, {0, 0, 0, 0}},
{
{8, 0, 0, 0}, {0, 1, 1, 0}, {0, 0, 1, 1}, {0, 0, 0, 0}},
{
{9, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{
{10, 0, 0, 0}, {0, 0, 0, 1}, {0, 1, 1, 1}, {0, 0, 0, 0}},
{
{13, 0, 0, 0}, {0, 1, 0, 0}, {0, 1, 1, 1}, {0, 0, 0, 0}},
{
{5, 0, 0, 0}, {0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}},
{
{16, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 1, 1}, {0, 0, 0, 0}},
{
{0, 0, 0, 0}, {0, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}},
{
{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 1, 0, 0}},
{
{2, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}},
{
{11, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 0, 0, 0}},
{
{12, 0, 0, 0}, {0, 1, 1, 1}, {0, 1, 0, 0}, {0, 0, 0, 0}}, //11
{
{3, 0, 1, 1}, {0, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 0, 0}},
{
{14, 1, 1, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}},
{
{15, 1, 1, 1}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{
{4, 0, 0, 1}, {0, 0, 0, 1}, {0, 0, 1, 1}, {0, 0, 0, 0}},
{
{17, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 0, 1, 0}},
{
{18, 0, 0, 0}, {0, 0, 0, 0}, {0, 1, 1, 1}, {0, 0, 1, 0}}, //17
{
{6, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}}};
HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);
int map[22][12];
int mode = 1;
int fraction = 0;
int positionX, positionY;
bool locked;
int keytime = 100000000;
bool keytimeflag;
int sleeptime = 0;
bool holdflag = 1;
int passcondition = 200;
int addlinetime = 10000, addlineflag;
int locktime = 1000;
int keydownflag;
int xray = 0;
int firstwin = 1;
int exfraction = 0;
int exgamestarttime;
int blind = 0;
int lockdelay = 300;
int clockms, stclockms;
double blockpersecond, blockperminute;
int blocknum;
void gotoxy (int x, int y);
void welcomepage ();
void reset ();
void choosedifficulty ();
void ready_go ();
void updatedata ();
void updatetime ();
type_block roundblock ();
void printblock (type_block m_block, int x, int y);
void clearblock (type_block m_block, int x, int y);
int checkblock (type_block m_block, int x, int y);
type_block myup (type_block m_block);
type_block mydown (type_block m_block);
void checkkey ();
void checkline ();
void addline ();
void gameover ();
void win ();
void easy_extra_game ();
void master_extra_game ();
void shirase_extra_game ();
int main()
{
welcomepage ();
reset ();
choosedifficulty();
ready_go ();
clearblock (nextA, 34, 4); clearblock (nextB, 38 + nextA.size, 4); clearblock (nextC, 42 + nextA.size + nextB.size, 4);
now = nextA; nextA = nextB; nextB = nextC; nextC = roundblock();
printblock (nextA, 34, 4); printblock (nextB, 38 + nextA.size, 4); printblock (nextC, 42 + nextA.size + nextB.size, 4);
positionX = 0; positionY = 4; locked = 0;
keytime = clock(); keytimeflag = 1;
addlineflag = clock (); stclockms = clock ();
while (1)
{
updatedata (); updatetime ();
if (locked)
{
++blocknum;
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
now.color = -xray * 2;
printblock (now, positionY * 2 + 8, positionX + 1);
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
if (!(i + j))
continue;
if (now.a[i][j])
map[positionX + i][positionY + j] = 1;
}
}
checkline ();
Sleep (lockdelay);
updatetime ();
if (blind)
clearblock (now, positionY * 2 + 8, positionX + 1);
locked = 0;
clearblock (nextA, 34, 4); clearblock (nextB, 38 + nextA.size, 4); clearblock (nextC, 42 + nextA.size + nextB.size, 4);
now = nextA; nextA = nextB; nextB = nextC; nextC = roundblock();
printblock (nextA, 34, 4); printblock (nextB, 38 + nextA.size, 4); printblock (nextC, 42 + nextA.size + nextB.size, 4);
positionX = 0; positionY = 4;
if (!checkblock (now, positionX, positionY))
gameover ();
if (fraction % 100 != 99 && fraction != passcondition)
++fraction;
SetConsoleTextAttribute(hOut, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
gotoxy (56, 10);
printf ("%4d", fraction);
gotoxy (57, 11);
printf ("---");
gotoxy (56, 12);
int lssc = fraction % 100 ? (fraction / 100 + 1) * 100 : fraction;
if (mode == 1 && lssc >= 200) lssc = 200;
if (mode == 2 && lssc >= 999) lssc = 900;
if (mode == 3 && lssc >= 1300) lssc = 1300;
printf ("%4d", lssc);
keytime = clock(); holdflag = 1;
if (clock () - addlineflag > addlinetime)
{
addlineflag = clock ();
addline ();
}
keydownflag = 0;
}
if (checkblock (now, positionX + 1, positionY))
while (checkblock (now, positionX + 1, positionY))
{
++positionX; updatetime ();
if (sleeptime)
{
printblock (now, positionY * 2 + 8, positionX + 1);
int sttime = clock (), timeover;
while ((timeover = (clock () - sttime < sleeptime)) && !kbhit());
clearblock (now, positionY * 2 + 8, positionX + 1);
if (timeover)
checkkey ();
}
checkkey ();
}
printblock (now, positionY * 2 + 8, positionX + 1);
Sleep (100);
clearblock (now, positionY * 2 + 8, positionX + 1);
checkkey ();
}
}
void gotoxy (int x, int y)
{
COORD pos;
pos.X = x; pos.Y = y;
SetConsoleCursorPosition (hOut, pos);
}
void welcomepage ()
{
puts (" ");
puts (" ■■■■■■■■■■ ");
puts (" ■■■■■■■■■■ ");
puts (" ■■ ");
puts (" ■■ ");
puts (" ■■ ");
puts (" ■■ ■■■■ ■ ■ ■ ■■■ ");
puts (" ■■ ■ ■ ■■■■ ■ ■■■ ■ ■ ");
puts (" ■■ ■■■■ ■ ■■ ■ ■ ");
puts (" ■■ ■ ■ ■ ■ ■■■ ");
puts (" ■■ ■■■■ ■ ■ ■ ■ ");
puts (" ■ ");
puts (" ■■■■ ");
puts (" ");
puts (" ------------------------------------------------------------------ ");
puts (" CHAMP&