当前位置: 首页>>代码示例>>C++>>正文


C++ Dice类代码示例

本文整理汇总了C++中Dice的典型用法代码示例。如果您正苦于以下问题:C++ Dice类的具体用法?C++ Dice怎么用?C++ Dice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Dice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TEST

TEST (Dice, CanInjectRangeAfterInstantiaton)
{
    Dice dice;
    dice.Ranged (Range(1,2));
    EXPECT_LE (1, dice.Roll());
    EXPECT_GE (2, dice.Roll());
}
开发者ID:zinark,项目名称:MechSG,代码行数:7,代码来源:DiceTests.cpp

示例2: RollDiceBeforeThrowingDoublet

bool Game::RollDiceBeforeThrowingDoublet(Player* activePlayer, Dice& firstDice, Dice& secondDice, ButtonText& button, bool ShownCard)
{
	int firstRollDice = firstDice.RollDice();
	int secondRollDice = secondDice.RollDice();
	if (!activePlayer->IsBlocked())
	{
		if (activePlayer->GetPawn().move(firstRollDice + secondRollDice))
			activePlayer->AddMoney(200);
		activePlayer->SetActiveField(true);
		ShownCard = false;

		if (firstRollDice == secondRollDice)
		{
			activePlayer->SetDoublet(true);
			button.GetText().setString(L"Wyrzuciłeś dublet!\nRzuć kostkami jeszcze raz!");
		}
		else
			activePlayer->SetActiveMovement(false);
	}
	else
	{
		if (firstRollDice == secondRollDice)
		{
			activePlayer->SetDoublet(true);
			button.GetText().setString(L"Wyrzuciłeś dublet!\nRzuć kostkami jeszcze raz!");
		}
		else
		{
			button.GetText().setString(L"Nie udało się wyrzucić dubletu!\nOddaj ruch kolejnemu graczowi!");
			activePlayer->SetActiveMovement(false);
		}
		--(*activePlayer);
	}
	return ShownCard;
}
开发者ID:mobetkal,项目名称:Game,代码行数:35,代码来源:game.cpp

示例3: GetShipIndicesWeakestFirst

ShipBattle::Hits ShipBattle::GetHitsToDestroy(const Group& group, Dice& dice, int toHit) const
{
	const auto shipIndices = GetShipIndicesWeakestFirst(group);

	Hits hits;
	for (int shipIndex : shipIndices)
	{
		int lives = group.lifeCounts[shipIndex];
		Dice used = dice.Remove(lives, toHit);
		if (used.empty())
			break; // Can't destroy any more ships in this group. 

		// We can destroy this ship. 
		int damage = used.GetDamage();
		if (damage > lives) // Don't want to waste damage. Can we destroy a healthier ship? 
		{
			for (int shipIndex2 : shipIndices)
				if (group.lifeCounts[shipIndex2] == damage)
				{
					// We can destroy this one with no waste. 
					shipIndex = shipIndex2;
					lives = damage;
					break;
				}
		}

		hits.push_back(Hit(group.shipType, shipIndex, used));
	}
	return hits;
}
开发者ID:molip,项目名称:Eclipsoid,代码行数:30,代码来源:ShipBattle.cpp

示例4: 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;
}
开发者ID:Pakaree,项目名称:Tut3-Dice,代码行数:33,代码来源:Source.cpp

示例5: main

int main()
{
    const int start=1;
    const int stop=12;

    int storeroll[13]; // this is an array declaration for an array of 12 integers
    //storeroll[0]=0; // this will remain unused, but we can initialize it.

    int loopcount =1;

    Dice cube;              // make a six-sided die

    cube.Roll();  //For debugging purposes, the same number will be generated by EVERY SINGLE first roll.
    //So, unless you want the same number for each first roll, we must throw away the first roll.
    //which we do by ignoring the first roll and not storing it or printing it out.
    storeroll[0] = cube.Roll();
    cout << storeroll[0] << endl;

    cout << "This loop displays "<<stop-start+1 <<" rolls of a 6-sided dice:\n" << endl;
    for (loopcount=start; loopcount<=stop; loopcount++)
    {
        storeroll[loopcount]=cube.Roll(); // put the roll into the array
        cout << "Roll " <<loopcount<< " is " << storeroll[loopcount] << "."<< endl;
    }
    cout << "\nRolled the six-sided dice " << cube.NumRolls()-1 << " times.\n" << endl;

    return 0;
}
开发者ID:Hellrungj,项目名称:Undergraduate-Code,代码行数:28,代码来源:diceroll.c

示例6: main

int main(int argc, char** argv) {
    
    Dice dice;
    std::string fileName = "C:\\Users\\mike8\\Desktop\\diceData.txt";
    dice.runProgram(fileName);

    return 0;
}
开发者ID:MFowler85,项目名称:CodeInterviewQuestions,代码行数:8,代码来源:main.cpp

示例7: 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]);
  }
}
开发者ID:dtbinh,项目名称:AOJ,代码行数:55,代码来源:1181_Biased_Dice.cpp

示例8: returnStr

// Returns a string representation of the event
string MonopolyEvent::str()
{
    string returnStr("The following event occured:\n");
    returnStr += player->str() + " with cash : " + itos(player->cash()) + " ";
    switch (kind)
    {
        case DICE_EVENT:
            {
                returnStr += "rolled the dice with value:\n";
                // Gets the current dice
                Dice *d = static_cast<Dice*>(other);
                // Tells user about the dice actions
                returnStr += itos(d->get_total_value());
                if (d->all_same())
                    returnStr += "\nDice match! Player moves.";
                break;
            }
        case PASS_EVENT:
            {
                returnStr += "passed the following tile:\n";
                // Gets the current tile
                Tile *t = static_cast<Tile*>(other);
                // Tells user about the tile
                returnStr += t->str();
                break;
            }
        case LAND_EVENT:
            {
                returnStr += "landed on the following tile:\n";
                // Gets the current tile
                Tile *t = static_cast<Tile*>(other);
                // Tells user about the tile
                returnStr += t->str();
                break;
            }
        case MOVE_EVENT:
            {
                returnStr += "is moving.";
                break;
            }
        case TRANSACTION_EVENT:
            {
                // Gets cash
                int *cash = static_cast<int*>(other);
                // Tells the player of the transaction
                returnStr += "made a transaction worth: " + itos(*cash);
                break;
            }
        default:
            returnStr += "an unrecognised move.";
    }
    returnStr += "\n";
    return returnStr;
}
开发者ID:TimurKiyivinski,项目名称:massive-happiness,代码行数:55,代码来源:MonopolyEvent.cpp

示例9: main

int main()
{
	Dice diceObj;
	int rolls;
	cout << "Enter Number of rolls max 12" << endl;
	cin >> rolls;

	diceObj.setRolls(rolls);
	cout << "Average Using Object " << diceObj.Average(diceObj, rolls) << endl;

	return 0;
};
开发者ID:jonathankellermann,项目名称:Tut3-Dice,代码行数:12,代码来源:Main.cpp

示例10: allState

 vector<Dice> allState() const {
     vector<Dice> Ret;
     Dice d = *this;
     for (int i = 0; i < 6; i++) {
         if (i % 2 == 0) d.rollX();
         else            d.rollY();
         for (int j = 0; j < 4; j++) {
             d.rollZ();
             Ret.push_back(d);
         }
     }
     return Ret;
 }
开发者ID:iduru,项目名称:Practice,代码行数:13,代码来源:main.cpp

示例11: 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;
}
开发者ID:LedditDotCom,项目名称:Tut3-Dice,代码行数:13,代码来源:source.cpp

示例12: main

int main(int argc, char* argv[])
{
	// Print a message...
	std::cout << "hello world" << std::endl;

	// Set a random seed.
	Rand::getInstance().seed(500);

	for (int i=0; i<10; ++i) {
		Dice d;
		std::cout << "Rolled: " << d.get1() << ", " << d.get2() << ".\n";
	}
	return 0;
}
开发者ID:ronhandler,项目名称:gitroot,代码行数:14,代码来源:main.cpp

示例13: main

int main()
{
    int loop;
    while(cin >> loop && loop != 0)
    {
        Dice dice;
        int sum = 1;
        string command;
        for(int i = 0; i < loop; ++i)
        {
            cin >> command;
            if(command == "South")
                dice.to_south();
            else if(command == "North")
                dice.to_north();
            else if(command == "East")
                dice.to_east();
            else if(command == "West")
                dice.to_west();
            else if(command == "Right")
                dice.turn_right();
            else if(command == "Left")
                dice.turn_left();
            sum += dice.get_top();
        }
        cout << sum << endl;
    }
}
开发者ID:fordream,项目名称:OnlineJudge,代码行数:28,代码来源:aizu0502.cpp

示例14: checkCreateInstance

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;
}
开发者ID:markromedia,项目名称:gameplay-words,代码行数:14,代码来源:dice_manager.cpp

示例15: main

int main()
{
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        if (n == 0)
            break;

        int ans = 1;
        Dice dice;
        for (int i = 0; i < n; ++i) {
            string op;
            cin >> op;
            if (op == "North")
                dice.rotateY(1);
            else if (op == "East")
                dice.rotateX(1);
            else if (op == "South")
                dice.rotateY(-1);
            else if (op == "West")
                dice.rotateX(-1);
            else if (op == "Right")
                dice.rotateZ(1);
            else
                dice.rotateZ(-1);
            ans += dice.get(Dice::TOP);
        }
        cout << ans << endl;
    }
    return 0;
}
开发者ID:yuta1024,项目名称:aoj,代码行数:31,代码来源:0502.cpp


注:本文中的Dice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。