别踩白块儿 开源免费(C++)

3 篇文章 1 订阅

别踩白块儿(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;
}

  • 6
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值