用c++一个投骰子的游戏

两点玩家掷骰子。 骰子决定了他们得到多少分。 第一个获得 100 点的玩家获胜。 规则如下:
每一轮,主动玩家面临一个决定(投掷或持有):
掷骰子。
Roll: 如果是点数1:你失去了你的回合,没有回合总分加到你的累计。换另一个玩家掷骰子。
如果点数是2-6:您掷出的数字将添加到您的回合总数中。
Hold:您的回合总数将添加到您的总计中。 现在是
轮到下一个玩家。
Quit: 退出游戏。

回答不易,请采纳一下,讨个赏:

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int rollDice() {
    return rand() % 6 + 1;
}

int main() {
    srand(time(0));

    int player1Score = 0, player2Score = 0;
    int currentPlayer = 1;

    while (true) {
        cout << "Player " << currentPlayer << ": " << endl;
        cout << "1. Roll" << endl;
        cout << "2. Hold" << endl;
        cout << "3. Quit" &#8203;`oaicite:{"index":0,"invalid_reason":"Malformed citation << endl;\n\n        int choice;\n        cin >>"}`&#8203; choice;

        if (choice == 1) {
            int roll = rollDice();
            if (roll == 1) {
                cout << "You rolled a 1! Your turn is over and you don't earn any points." << endl;
                currentPlayer = (currentPlayer == 1) ? 2 : 1;
            } else {
                cout << "You rolled a " << roll << "!" << endl;
                if (currentPlayer == 1) {
                    player1Score += roll;
                } else {
                    player2Score += roll;
                }
            }
        } else if (choice == 2) {
            if (currentPlayer == 1) {
                player1Score += player1Score;
                currentPlayer = 2;
            } else {
                player2Score += player2Score;
                currentPlayer = 1;
            }
        } else if (choice == 3) {
            break;
        }

        if (player1Score >= 100) {
            cout << "Player 1 wins!" << endl;
            break;
        } else if (player2Score >= 100) {
            cout << "Player 2 wins!" << endl;
            break;
        }
    }

    return 0;
}

你的思路是什么? 你搜索了 CSDN 的文章了么?

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^