栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++弹球2.0

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++弹球2.0

解决了闪屏的BUG

可以在任意Windows系统上编译

可以在任意c++编译器上编译

分数固定在了底下

修了很多小BUG

球和挡板的移动速度会慢慢变快

方向键也可以控制挡板

添加了很多细节

#include
#include
#include
#include
#include
#include
using namespace std;
string q = "o", db = "-----", kk[31] = {
	"",
	" |---------------------------------------------------------------------------------------------------|",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |                                                                                                   |",
	" |---------------------------------------------------------------------------------------------------|"
};
long long x, y, dx, dy, hb = 95, fs = 0, y_x, y_y, y_hb;
long double sd;
bool f = 1;
void csh();//初始化 
void in();//输入
void out();//输出
void qgx();//球坐标的更新
void pd();//判断结束
void gx();//更新 
void color(int c)
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
	return;
}
void gb()
{
	CONSOLE_CURSOR_INFO cursor;
	cursor.bVisible = FALSE;
	cursor.dwSize = sizeof(cursor);
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorInfo(handle, &cursor);
	return;
}
void ydgb(long long x, long long y)
{
	COORD pos = { y,x };
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOut, pos);
	return;
}
int main()
{
	gb();
	color(11);
	csh();
	out();
	for (long long i = 1; f; i++)
	{
		in();
		if (i % 5 == 0)
		{
			qgx();
			if (sd > 6)
				sd -= 0.2;
		}
		pd();
		Sleep(long(sd));
		gx();
		if (i == 1)
		{
			system("cls");
			out();
		}
	}
	color(11);
	system("cls");
	printf("你得了%d分n按空格退出", fs);
	char t = _getch();
	while (t != ' ')t = _getch();
	return 0;
}
void csh()
{
	system("mode con cols=102 lines=31");
	srand(time(0));
	x = 4;
	y = rand() % 99 + 2;
	dx = 1;
	dy = 1;
	y_x = x, y_y = y;
	sd = 70;
	return;
}
void in()
{
	if (GetKeyState('A') < 0 || GetKeyState(37) < 0)
	{
		if (hb > 2)
		{
			hb -= 1;
		}
	}
	if (GetKeyState('D') < 0 || GetKeyState(39) < 0)
	{
		if (hb < 99 - 4)
		{
			hb += 1;
		}
	}
	return;
}
void out()
{
	system("cls");
	for (long long i = 1; i <= 30; i++)
	{
		for (long long j = 1; j <= 101; j++)
		{
			color(11);
			cout << kk[i][j];
		}
		if (i != 30)
			cout << "n";
	}
	return;
}
void qgx()
{
	if (x == 3 || (x == 28 && (hb == y || y + dy == hb + 1 || y + dy == hb + 2 || y + dy == hb + 3 || y + dy == hb + 4 || y == hb + 5)))dx *= -1;
	if (y == 2 || y == 100)dy *= -1;
	x += dx;
	y += dy;
	if (x == 28 && (hb == y || y == hb + 1 || y == hb + 2 || y == hb + 3 || y == hb + 4 || y == hb + 5))fs++;
	return;
}
void pd()
{
	if (x == 31)
		f = 0;
	return;
}
void gx()
{
	ydgb(y_x - 2, y_y);
	cout << "b" << " ";
	ydgb(x - 2, y);
	color(10);
	cout << "b" << "o";
	color(14);
	ydgb(27, y_hb + 5);
	for (long long i = 1; i <= 6; i++)
		cout << "b";
	cout << "      ";
	ydgb(27, hb + 5);
	for (long long i = 1; i <= 6; i++)
		cout << "b";
	cout << "------";
	y_x = x, y_y = y;
	y_hb = hb;
	ydgb(30, 1);
	cout << "分数:" << fs;
	return;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/289413.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号