c++编写打字游戏

//https://gitee.com/devcpp/cgames anbangli@foxmail.com GNU GPL v3
/https://gitee.com/devcpp/cgames anbangli@foxmail.com GNU GPL v3
//cgame2-2(type).cpp 字符横向移动的打字游戏
#include
#include
#include
#include <windows.h> //非标准库函数 Sleep 所需的头文件
#include <conio.h> //非标准库函数 kbhit 和 getch 所需的头文件
using namespace std;

int main() {
const int ESCKEY = 27; //定义整型常量ESCKEY,赋值为ESC键的ASCII编码
int pos, posmax = 72; //当前位置,右边界最大位置
int win = 0, loss = 0; //已赢局数和已输局数

cout << "打字游戏(按回车键开始,游戏过程中按 ESC 结束)" << endl;
getchar();
int ch = 0, key = 0; //随机字符,玩家键入字符
srand(time(0)); //设置随机数种子
while (key != ESCKEY) { //主循环。key 不是 ESC键时玩游戏
    ch = rand() % ('z' + 1 - 'a') + 'a'; //产生随机字符
    for (pos = 0; pos < posmax && key != 27; pos++) {
        cout
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值