#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main() {
    // 设置随机数种子,确保每次运行游戏炸弹数字不同
    srand(time(0));
    
    // 生成1-100之间的随机数作为炸弹
    int bomb = rand() % 100 + 1;
    int guess;       // 玩家猜的数字
    int attempts = 0; // 记录猜测次数
    
    cout << "欢迎来到数字炸弹游戏!" << endl;
    cout << "游戏规则:我已经想好了一个1-100之间的数字作为炸弹" << endl;
    cout << "你需要猜出这个数字,我会提示你猜大了还是猜小了" << endl;
    cout << "准备好了吗?开始吧!" << endl << endl;
    
    // 游戏主循环,直到猜中炸弹
    do {
        cout << "请输入你猜的数字(1-100):";
        cin >> guess;
        attempts++; // 每猜一次,次数加1
        
        // 检查输入是否有效
        if (guess < 1 || guess > 100) {
            cout << "请输入1-100之间的数字!" << endl;
            continue;
        }
        
        // 判断猜测结果
        if (guess < bomb) {
            cout << "猜小了!再试试更大的数字。" << endl;
        } else if (guess > bomb) {
            cout << "猜大了!再试试更小的数字。" << endl;
        } else {
            cout << endl << "恭喜你!你猜中了炸弹数字:" << bomb << endl;
            cout << "你一共猜了" << attempts << "次" << endl;
        }
        
    } while (guess != bomb);
    
    cout << "游戏结束,谢谢参与!" << endl;
    return 0;
}