C++跳高高小游戏初级版,带详细注释,简单易懂

C++跳高高小游戏初级版,带详细注释,简单易懂,第1张

C++跳高高小游戏初级版,带详细注释,简单易懂
#include 
#include 
#include 

using namespace std;
bool gameOver;//判断游戏开始结束
int  score,m;
//声明函数
void Setup();
void Draw();
void Input();
void Logic();
地图范围///
const int width = 40;
const int height = 10;


//主角坐标///
int x = 8;
int y = 6;
int n = 38;//地图横向坐标
int up = 0;

/主函数
int main1(void)
{
	Setup();
	while (!gameOver)
	{
		Draw();
		Input();
		Logic();
		Sleep(20);

	}
	return 0;
}

///初始化程序///
void Setup()
{
	
	gameOver = false;
	//m = rand() % height;//暂时没用到;
	score = 0;
}
//游戏逻辑/
void Logic()
{
	
	n--;
	if (n == 0)
		n = 38;
	if (n == 6)
		score = score + 1;
	if (x == 8 && y == n)
		gameOver = true;
	if (x == 6 && y == n)
		gameOver = true;
	if (x == 7 && y == n)
		gameOver = true;
	
///主角跳跃实现代码	
	if (up == 1&&x>4)
	{
		x--;
		if (x == 4)
			up = 2;
	}
	if (up == 2)
	{
		x++;
		if (x == 8)
			up = 0;
	}
}

绘制背景板
void Draw()
{
	system("cls");
	for (int i = 0; i < width + 2; i++)//画顶部边界
		cout << "*";
	cout << endl;
	for (int i = 0; i < height; i++)//画内部图像
	{
		for (int j = 0; j <= width; j++)
		{
			if (j == 0)
				cout << "*";
			if (i == x && j == y)
				cout << "O";
		    else if (i == 8 && j == n)
				cout << "#";
			else if (i == 7 && j == n)
				cout << "#";
			else if (i == 6 && j == n)
				cout << "#";
			else if (i == 8 && j < width)
				cout << "_";
			else if (j == width)
				cout << "*";
			else
				cout << " ";
		}
		cout << endl;
	}
	for (int i = 0; i < width + 2; i++)//画底部边界
		cout << "*";
	cout << endl;
	//cout << up << endl;
	cout << "score: " << score << endl;
}

/输入///
void Input()
{
	
	if (_kbhit())
	{
		switch (_getch())
		{
		case 72://小键盘↑键,控制跳跃
			up = 1;
			break;
		case 'x'://x键退出游戏
			gameOver = true;
			break;

		}
	}
}

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5116167.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存