打字游戏(C++)

本文介绍了一个使用C++编写的简单打字游戏,通过键盘监听功能,随机生成字母并计时玩家输入,旨在提高打字速度和准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 一个简单的打字游戏

#include<bits/stdc++.h>
#include<Windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
#define ll long long	
#define un unsigned
using namespace std;
void gotoxy(int y,int x){  
    COORD pos;  
    pos.X=x;  
    pos.Y=y;  
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos); 
} 
int getRand(ll min,ll max){
	return (rand()%(max-min+1))+min;
}
int main(){
	srand(time(0));
	system("color 2"); 
	cout<<"按A键开始游戏"; 
	while(1){
		if(KEY_DOWN('A')) break;
	}
	system("color 7"); 
	system("cls");
	for(int i=0;i<=113;i++){
		gotoxy(19,55);
		if(i>100) cout<<"100%";
		else cout<<i<<"%";
		gotoxy(20,i);
		cout<<".加载中";
		Sleep(50);
	}
	Sleep(100);
	system("cls");
	char c[15];
	for(int i=0;i<10;i++) c[i]=getRand('A','Z');
	for(int i=5;i>=1;i--){
		cout<<c<<endl<<i;
		Sleep(1000);
		system("cls");
	}
	cout<<"开始!"; 
	Sleep(500);
	system("cls");
	cout<<c;
	ll m=time(0);
	for(int i=0;i<10;i++){
		ll n=time(0);
		gotoxy(getRand(1,10),getRand(0,117));
		cout<<c[i];
		while(1){
			if(KEY_DOWN(c[i])){
				Beep(c[i]+500,250);
				break;	
			}
		}
		Sleep(10);
		if(i==9){
			gotoxy(0,100);
			cout<<"所用时间:"<<n-m<<"秒";
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值