小编Tyl*_*con的帖子

为什么我的srand会返回所有结果?

这是一个简单的文字游戏的开始.在游戏中,你应该四处寻找地下城并收集文物.我习惯srand(time(0))做一些事情,比如找到要进入的阶段,攻击,以及你找到的项目,我已经在编程中走得很远,但我已经遇到了问题.我的rand()返回所有结果.当我运行游戏时(这不是完整的代码,顺便说一句),它会返回"你进入了一个地牢!","哦不,敌人已经到了!",并且"你找到了一件神器!

void mainScreen()
{
    srand(time(0));
    cout << "Health: \n";
    cout << health;
    cout << endl;
    _sleep(500);
    cout << "Inventory: \n";
    cout << inventory;
    cout << endl;
    _sleep(500);
    cout << "Gold: \n";
    cout << gold;
    cout << endl;
    _sleep(500);
    cout << "Artifacts: \n";
    cout << artifacts;
    cout << endl;
    _sleep(500);
    cout << "Rolling the dice of fate... \n";
    int diceRoll = 1 + (rand() % 10);
    if (diceRoll = 1, 2, 3, 4, 5, 6) {
        cout << "You …
Run Code Online (Sandbox Code Playgroud)

c++ random srand

-7
推荐指数
1
解决办法
44
查看次数

标签 统计

c++ ×1

random ×1

srand ×1