//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