本文整理汇总了C++中Dice::roll方法的典型用法代码示例。如果您正苦于以下问题:C++ Dice::roll方法的具体用法?C++ Dice::roll怎么用?C++ Dice::roll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dice
的用法示例。
在下文中一共展示了Dice::roll方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dfs
void dfs(Dice dice,int sx,int sy){
//check stage
//1 2
// 0
//3 4
bool isok = false;
for(int num=6;num>=4;num--){
if(dice.surface[FRONT] == num){
int dx = sx;
int dy = sy - 1;
if(stage[dy][dx].size() < stage[sy][sx].size()){
dice.pitch(3);
dfs(dice,dx,dy);
isok = true;
goto found;
}
}
else if(dice.surface[REAR] == num){
int dx = sx;
int dy = sy + 1;
if(stage[dy][dx].size() < stage[sy][sx].size()){
dice.pitch(1);
dfs(dice,dx,dy);
isok = true;
goto found;
}
}
else if(dice.surface[LEFT] == num){
int dx = sx - 1;
int dy = sy;
if(stage[dy][dx].size() < stage[sy][sx].size()){
dice.roll(3);
dfs(dice,dx,dy);
isok = true;
goto found;
}
}
else if(dice.surface[RIGHT] == num){
int dx = sx + 1;
int dy = sy;
if(stage[dy][dx].size() < stage[sy][sx].size()){
dice.roll(1);
dfs(dice,dx,dy);
isok = true;
goto found;
}
}
}
found:;
if(!isok){
stage[sy][sx].push_back(dice.surface[TOP]);
}
}
示例2: equals
bool equals(Dice rhs) const {
for (int i = 0; i < 4; i++) {
rhs.roll(NORTH);
if (num[TOP] == rhs.getTop()) break;
rhs.roll(WEST);
if (num[TOP] == rhs.getTop()) break;
}
for (int i = 0; i < 4; i++) {
if (check(rhs))
return true;
else
rhs.rightHandedRoll();
}
return false;
}
示例3: main
int main()
{
int i, n;
float r;
Dice dice;
cout << "Enter how many times you wish to roll the dice:";
cin >> n;
for (i = 1; i <= n; i++)
{
r = dice.roll();
dice.setsumrollvals(r);
cout << "Roll " << i << ": " << (int)r << endl;
}
cout.precision(4);
cout << "The average value rolled out of " << n << " rolls is: " << fixed << average(dice, n) << endl;
const int size = 10;
int arr[size];
cout << endl << "Enter the 10 values to put into your array: " << endl;
for (i = 0; i < size; i++)
{
cin >> arr[i];
}
cout << "The average value of the array is: " << fixed << average(arr, size) << endl;
return 0;
}
示例4: average
float Dice::average(Dice dice, int numRolls)
{
int sum = 0;
int i = 0;
for (i = 1; i <= numRolls; i++)
{
sum += dice.roll();
}
return sum / numRolls;
}
示例5: average
float Dice::average(Dice obj, int num) //Gets the value of each roll from getSum and then sums + averages
{//First use of the average function
float av;
int sum = 0;
for (int i = 1; i < num; i++)
{
sum = sum + obj.roll();
}
av = sum / num; //num argument from user
return av;
}
示例6: main
int main()
{
// Create a die
Dice die;
// Roll the die and print the result
cout << "Die rolls a " << die.roll() << endl;
// Print the average of 4 rolls
cout << "4 roll avg: " << die.average(die, 4) << endl;
// Declare an array of integers
int rolls[5] = { 2,4,6,1,3 };
// Find the average of the values in the array
cout << "5 int avg: " << die.average(rolls, 5) << endl;
}
示例7: GetRandomDie
Dice* DiceManager::GetRandomDie()
{
checkCreateInstance();
//grab die
int dice_idx = std::rand() % instance->available_dice.size();
Dice* dice = instance->available_dice[dice_idx];
dice->roll();
//make sure this is marked as unavailable
instance->available_dice.erase(instance->available_dice.begin() + dice_idx);
return dice;
}
示例8: payRent
//-----------------------------------------------------------------------------
void Utility::payRent(
PlayerManager & i_players
)
{
Dice dice;
dice.roll();
const unsigned int amountTobePaid = dice.getTotal() *m_rentPrices[0];
if(i_players.takeBalance(amountTobePaid))
{
std::cout << "You have paid " << amountTobePaid << " rent.\n";
i_players.addBalance(amountTobePaid,m_owner);
}
else
{
std::cout << "You do not have enough money to pay!\n";
i_players.withdrawGame();
}
}
示例9: main
int main()
{ //testing the functions
int arr[3], i;
Dice d;
Dice acess1, acess;
float average1, average2;
cout << "this is only testing the functionality of the roll(),the average not calculated based on this values," << endl;
cout << "the generated random numbers are:" << endl;
srand(time(NULL));
for (i = 1; i <= 3; i++) {
cout << "random number is:" << d.roll() << endl;
}
average1 = acess1.average(acess1, 3);
average2 = acess.average(arr, 3);
cout << "avarage1:" << average1 << endl;
cout << "average2:" << average2 << endl;
return 0;
}
示例10: play
void Colosseum::play(Pokemon& p1, Pokemon& p2) //function that determines who goes first, when game is over, and constraints the game to 10 rounds
{
int hp;
Dice d;
int j=d.roll();
string position;
if(j==1)
{
position="first";
}
else
{
position="second";
}
cout << p1.get_name() << " rolls a " << j << " and goes " << position << endl;
if(position=="first")
{
for(int i=1; i<11; i++)
{
cout << "Round " << i << "!" << endl;
if(attack(p1,p2)==true)
{
cout << p2.get_name() << " has been defeated!" << endl;
break;
}
if(attack(p2,p1)==true)
{
cout << p1.get_name() << " has been defeated!" << endl;
break;
}
if(i==10)
{
cout << "Game Over. It's a draw!" << endl;
}
}
}
else
{
for(int i=1; i<11; i++)
{
cout << "Round " << i << "!" << endl;
if(attack(p2,p1)==true)
{
cout << p1.get_name() << " has been defeated!" << endl;
break;
}
if(attack(p1,p2)==true)
{
cout << p2.get_name() << " has been defeated!" << endl;
break;
}
if(i==10)
{
cout << "Game Over. It's a draw!" << endl;
}
}
}
}
示例11: rollDice
void rollDice() {d1.roll();} //roll the dice