别踩白块儿(C++)
演示视频
调用EasyX图形库,电脑没有安装图形库的话,无法运行
EasyX下载
源码下载
//主要代码,源码请下载源码文件
//游戏开始
void Begin()
{
MOUSEMSG m;
Show_Rectangle();
while (true)
{
m = GetMouseMsg();
if (m.mkLButton)
{
g_block[m.y / HIGH + 1][m.x / WIDE] = LIGHTGRAY_BLOCK;
break;
}
}
}
//随机颜色
void Random_Color()
{
int x = rand() % COLUMN;
for (int i = 0; i < COLUMN; i++)
g_block[0][i] = (i == x) ? BLACK_BLOCK : WHITE_BLOCK;
}
//交换数据
void Swap_Data()
{
for (int i = COLUMN - 1; i >= 0; i--)
for (int j = 0; j < COLUMN; j++)
g_block[i + 1][j] = g_block[i][j];
}
//方块移动
void Rectangle_Move()
{
if (HIGH < g_circulation)
Process_Data();
else
g_circulation += 3;//方块每次移动的距离
}
//处理数据
void Process_Data()
{
g_circulation = 0;
Swap_Data();
Random_Color();
}
//显示矩形
void Show_Rectangle()
{
for (int i = 0; i < LINE; i++)
for (int j = 0; j < 4; j++)
{
if (g_block[i][j] == BLACK_BLOCK)
setfillcolor(BLACK);
if (g_block[i][j] == WHITE_BLOCK)
setfillcolor(WHITE);
if (g_block[i][j] == LIGHTGRAY_BLOCK)
setfillcolor(LIGHTGRAY);
fillrectangle(WIDE * j, g_circulation - HIGH + HIGH * i, WIDE * (j + 1), g_circulation + HIGH * i);
}
}
//失败闪烁
void Blink_RED(int i, int j)
{
for (int index = 0; index < 50; index++)
{
Sleep(30);
setfillcolor(((index % 6 > 3) ? RED : WHITE));
//-3是调整高度,把前面g_circulation +3调整回来
fillrectangle(WIDE * j, g_circulation + HIGH * i - 3, WIDE * (j + 1), g_circulation + HIGH * (i + 1) - 3);
}
}
//鼠标消息
bool Mouse()
{
bool ret = true;
MOUSEMSG m;
m = GetMouseMsg();
if (m.mkLButton)
{
if (g_LV_num++ % 20 == 0)
g_LV--;
if (Process_MMSG(m.x, m.y))
ret = false;
FlushMouseMsgBuffer();//清空鼠标缓冲区
}
else
{
ret = false;
}
return ret;
}
//判断失败
bool Is_Lose()
{
bool ret = false;
for (int i = 0; i < 4; i++)
{
if (g_block[4][i] == BLACK_BLOCK && g_circulation >= 110)
ret = true;
}
return ret;
}