0
我目前正在制作一个2人骰子游戏,我需要创建一个函数来检查您掷骰子组合的值。例如:我滚3-4-2,我需要检查是否有支付3-4-2的功能,例如滚动和他们的支出+代码如下如何编写一个检查3个数字组合的函数?
//Rolling 1-1-1 would give you 5x your wager
//Rolling 3 of the same number (except 1-1-1) would give you 2x wager
//Rolling 3 different numbers (ex 1-4-6) would give you 1x your wager
//Rolling 1-2-3 makes the player automatically lose a round and pay opposing Player 2x wager
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
void roll_3_dice(int &dice1, int &dice2, int &dice3)
{
srand(time(NULL));
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
dice3 = rand() % 6 + 1;
return;
}
int main()
{
int cash = 90000;
int wager;
int r;
//dealer's die
int dealer1;
int dealer2;
int dealer3;
// your die
int mdice1;
int mdice2;
int mdice3;
while (cash > 100 || round < 10)
{
cout << "Set your wager: "<< endl;
cin >> wager;
while (wager < 100 || wager > 90000)
{
cout << "Minimum wager is 100; Maximum wager is 90000 ";
cin >> wager;
}
cout << "You wagered: " << wager << endl;
cout << "You have " << cash - wager << " remaining" << endl;
cash = cash - wager;
cout << endl;
cout << "Dealer will now roll the dice" << endl;
roll_3_dice(dealer1, dealer2, dealer3);
cout << "Dealer rolled the following: " << endl;
cout << dealer1 << "-" << dealer2 << "-" << dealer3 << endl;
cout << "It's your turn to roll the dice." << endl;
cout << endl;
cout << "Press any key to roll the dice" << endl;
cin >> r;
roll_3_dice(mdice1, mdice2, mdice3);
cout << "You rolled the following: " << endl;
cout << mdice1 << "-" << mdice2 << "-" << mdice3 << endl;
system ("pause`enter code here`");
}
}
你只需要写很多if语句,比如'if(dice1 == 1 && dice2 == 1 && dice3 == 1)result = 5 * wager;'。等。 –
滚动后,按升序对骰子进行排序。这样可以更容易地检测1,2,3等序列,因为您不必检查例如3,2,1或2,1,3 –
@JasonLang你能帮我整理一下吗?我真的不知道如何排序... – elburatski