猜单词(弱化版)-c++小游戏源码

#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
int main(){
srand(time(NULL));
int n;
char a[n];
string chop;
string qp;
int life;
bool p[26] = {false};
cout << "欢迎来到猜词游戏!(虽然电脑给的不是真的词)" << endl;
cout << "选择模式 (1P / 2P)" << endl;
cin >> chop;
if(chop == "2P"){
    cout << "1号玩家,请输入目标词" << endl;
    cin >> qp;
    n = qp.size();
    cout << "请输入您想给对方的机会数" << endl;
    cin >> life;
    for(int i = 0; i < n; i++){
        a[i] = qp[i];
    }
}else{
    cout << "请输入你想猜的单词的长度 " << endl;
    cin >> n;
    cout << "请输入你想要的机会数 " << endl;
    cin >> life;
}
system("cls");
bool rev[n] = {false};
if(chop == "1P"){
    for(int i = 0; i < n; i++){
        a[i] = char(rand() % 26 + 97);
    }
}
int cnt = 0;
char ch;
while(life > 0){
    cout << "猜词状态:" << endl;
    for(int i = 0; i < n; i++){
        if(rev[i]){
            cout << a[i];
            cnt++;
        }else{
            cout << "-";
        }
    }
    cout << endl;
    cout << "猜出" << cnt << "个字母" << endl;
    if(cnt == n){
        cout << "你赢了!" << endl;
        return 0;
    }
    cout << "剩余机会数: " << life << endl;
    cout << "选择你要猜的字母: ";
    cnt = 0;
    cin >> ch;
    while(1){
        if(p[int(ch) - 97] == true){
            cout << endl;
            cout << "猜过了!";
            cin >> ch;
        }else{
            p[int(ch) - 97] = true;
            cout << "检测中..." << endl;
            Sleep(300);
            for(int i = 0; i < n; i++){
                if(a[i] == ch){
                    rev[i] = true;
                    cnt++;
                }
            }
            if(cnt == 0){
                cout << "你失去了一次机会!" << endl;
                life--;
            }
            cout << "本轮猜出" << cnt << "个字母" << endl;
            cnt = 0;
            system("pause");
            system("cls");
            break;
        }
    }
}
cout << "你输了。" << endl;
return 0;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SKCQTGZX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值