控制台之打字母游戏

控制台之打字母游戏

视频链接:

https://edu.csdn.net/course/play/3397/57829


环境:

windows+vs+控制台程序


游戏介绍:

游戏开始后,落下一个字母,在掉到底部之前输出相应字母,加分;输出其他字母,扣分;无输入,当作错误输入,扣分。
继续落下字母,直到游戏结束

升级:分数增加,游戏变难,下降速度变快
升级:字母曲线下落
升级:界面

截图

在这里插入图片描述
在这里插入图片描述


代码

#include <iostream>
#include <time.h>
#include <Windows.h>
#include <conio.h>
using namespace std;

void menu(int);

inline void print(int n, char c) {
	for (int i = 0; i < n; ++i) cout << c;
}

int main()
{
	srand((unsigned)time(NULL));

	print(10, '\n');
	cout << "\t\t\t按下任意键开始游戏\n";
	getchar();

	char c, c2;
	int col, r, max_r = 30;
	int score = 0;
	
	int s = 500;

	bool b = true;
	while (b) {
		system("cls");
		menu(score);

		//随机字母,及其坐标(col,0)
		c = (rand() % 26) + 'a';
		col= rand() % 50;
		
		for (r = 0; r < max_r; ++r) {
			
			print(col, ' ');
			cout << c;
			
			if (_kbhit()) {
				c2 = _getch();
				if (c2 == '0')	b = false;
				else if (c2 == c)	score += 10 * (score / 100 + 1);
				else			score -= 20;
				break;
			}
			else {
				Sleep((int)(s*(1 - (score / 100)*0.1)));
				cout << "\b \n";// \b 回退掉输出的字母c,然后换行,减少cls刷新
				continue;
			}
		}
		if (r == max_r) score -= 10;
	}
	
	return 0;
}

void menu(int score) {
	cout << "Level:" << (score / 100 + 1) << endl;
	cout << "Score:" << score << endl;
	cout << "Exit:" << 0 << endl;
	cout << "______________________________________________\n";
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值