本文整理汇总了C++中Coin类的典型用法代码示例。如果您正苦于以下问题:C++ Coin类的具体用法?C++ Coin怎么用?C++ Coin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Coin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printf
void SpawnShell::newCoinsItem(const dropCoinsStruct *c)
{
#ifdef SPAWNSHELL_DIAG
printf("SpawnShell::newCoinsItem(dropCoinsStruct*)\n");
#endif
// if zoning, then don't do anything
if (m_zoneMgr->isZoning())
return;
if (!c)
return;
Item* item = m_coins.find(c->dropId);
if (item != NULL)
{
Coin* coin = (Coin*)item;
coin->update(c);
updateFilterFlags(item);
item->updateLastChanged();
emit changeItem(item, tSpawnChangedALL);
}
else
{
item = new Coin(c);
updateFilterFlags(item);
m_coins.insert(c->dropId, item);
emit addItem(item);
}
if (item->filterFlags() & FILTER_FLAG_ALERT)
emit handleAlert(item, tNewSpawn);
}
示例2: while
//每一次地图重载,地图中的对象要回收
bool ObjectManager::recycleObjectOfMap(int map)
{
//清除金币
std::list<Coin*>::iterator it1 = m_vecCoinsList.begin();
std::list<Coin*>::iterator end1 = m_vecCoinsList.end();
#if 0
while (it1 != end1)
{
Coin *coin = *it1++;
if (coin->_map == map)
{
coin->removeFromParent();
delete coin;
break;
}
}
#else
for(;it1!=end1;++it1)
{
if((*it1)->_map == map)
{
(*it1)->removeFromParent();
m_vecCoinsList.erase(it1);
//delete *it1;
break;
//end1 = m_vecCoinsList.end();
}
}
#endif
//清除石头
std::list<Rock*>::iterator it2 = m_vecRocksList.begin();
std::list<Rock*>::iterator end2 = m_vecRocksList.end();
#if 0
while (it2 != end2)
{
Rock *rock = *it2++;
if (rock->_map == map)
{
rock->removeFromParent();
delete rock;
break;
}
}
#else
for(;it2!=end2;++it2)
{
if((*it2)->_map == map)
{
(*it2)->removeFromParent();
m_vecRocksList.erase(it2);
//delete *it2;
break;
//end1 = m_vecCoinsList.end();
}
}
#endif
return true;
}
示例3: main
int main(int argc,char **argv)
{
if(argc != 5)
{
fprintf(stderr,"%s <bank public info> <private coin request> <signed coin request> <coin>\n",
argv[0]);
exit(1);
}
const char *szBankFile=argv[1];
const char *szPrivateRequestFile=argv[2];
const char *szSignatureFile=argv[3];
const char *szCoinFile=argv[4];
SetDumper(stderr);
BIO *bioBank=BIO_new_file(szBankFile,"r");
BIO *bioPrivateRequest=BIO_new_file(szPrivateRequestFile,"r");
BIO *bioSignature=BIO_new_file(szSignatureFile,"r");
BIO *bioCoin=BIO_new_file(szCoinFile,"w");
PublicBank bank(bioBank);
CoinRequest req(bioPrivateRequest);
ReadNumber(bioSignature,"request=");
BIGNUM *bnSignature=ReadNumber(bioSignature,"signature=");
DumpNumber("signature=",bnSignature);
Coin coin;
req.ProcessResponse(&coin,bank,bnSignature);
coin.WriteBIO(bioCoin);
}
示例4: CashException
vector<unsigned> Arbiter::sellerResolveI(const ResolutionPair &keyMessagePair){
// first, store the keys
keys = keyMessagePair.first;
// now, unwrap and check the buyMessage, then store everything
BuyMessage* buyMessage = keyMessagePair.second;
Coin coinPrime = buyMessage->getCoinPrime();
VECiphertext escrow = *buyMessage->getEscrow();
// want to store the contract as well (for stage II)
contract = *buyMessage->getContract();
// check the timeout to make sure it hasn't passed
if(contract.checkTimeout(timeoutTolerance)) {
endorsement = verifiableDecrypter->decrypt(escrow.getCiphertext(),
saveString(contract), hashAlg);
// make sure the endorsement on the coin is valid
if(coinPrime.verifyEndorsement(endorsement)){
// construct verifiers based on the data in the contract and
// return a set of challenges
hash_t ptHash = contract.getPTHashB();
hash_t ctHash = contract.getCTHashB();
ptVerifier = shared_ptr<MerkleVerifier>(new MerkleVerifier(ptHash,
contract.getNumPTHashBlocksB(),
MerkleContract(ptHash.key,ptHash.alg)));
ctVerifier = shared_ptr<MerkleVerifier>(new MerkleVerifier(ctHash,
contract.getNumCTHashBlocksB(),
MerkleContract(ctHash.key,ctHash.alg)));
return ptVerifier->getChallenges();
} else {
throw CashException(CashException::CE_FE_ERROR,
"[Arbiter::sellerResolveI] invalid endorsement");
}
} else {
throw CashException(CashException::CE_FE_ERROR,
"[Arbiter::sellerResolveI] contract has expired");
}
}
示例5: decrypt
// receive coin
Coin<FIELD> decrypt(const SecretAddr<FIELD>& secretAddr,
const PublicAddr<FIELD>& publicAddr) const {
DECRYPTOR DEC(secretAddr.cryptoKey());
RANDPOOL RNG;
// recovered text length
const std::size_t rtextLen = DEC.MaxPlaintextLength(m_cipherText.size());
if (rtextLen) {
// recovered text bytes
std::vector<byte> rtext(rtextLen, 0xfb);
if (DEC.Decrypt(RNG,
m_cipherText.data(),
m_cipherText.size(),
rtext.data()).isValidCoding) {
// convert recovered text to stream
std::stringstream ss(std::string(rtext.begin(), rtext.end()));
Coin<FIELD> coin;
if (coin.marshal_in(ss, false)) { // false means omit public address
// set public address of recovered coin
coin.addr(publicAddr);
// must check:
// 1. cm matches pour transaction cm (coin exists in ledger)
// 2. serial number is not in ledger (not already spent)
if (coin.valid()) return coin;
}
}
}
return Coin<FIELD>(); // failed
}
示例6: hit
HitResponse
Block::collision(GameObject& other, const CollisionHit& )
{
Player* player = dynamic_cast<Player*> (&other);
if(player) {
if(player->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) {
hit(*player);
}
}
// only interact with other objects if...
// 1) we are bouncing
// and
// 2) the object is not portable (either never or not currently)
Portable* portable = dynamic_cast<Portable*> (&other);
if(bouncing && (portable == 0 || (!portable->is_portable()))) {
// Badguys get killed
BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
if(badguy) {
badguy->kill_fall();
}
// Coins get collected
Coin* coin = dynamic_cast<Coin*> (&other);
if(coin) {
coin->collect();
}
}
return SOLID;
}
示例7: abs
void Coin::compare(Coin B){
//Ideal coin struct initialization
double value[4] = {.75, .835, .705, .955};
string name[4] = {"penny","nickel","dime","quarter"};
for(int i = 0; i<16; i++){
Ideal[i].Ratio = value[i/4]/value[i%4];
Ideal[i].CoinA = name[i/4];
Ideal[i].CoinB = name[i%4];
Ideal[i].Difference = abs(value[i/4]-value[i%4]);
Ideal[i].ScaledDifference = Ideal[i].Difference/((value[i/4]+value[i%4])/2);
}
double dA = diameter;
double dB = B.getDiameter();
double ratio = dA/dB;
double scaledDifference = abs(dA-dB)/((dA+dB)/2);
double sProb, rProb, aProb;
for(int i = 0; i<16; i++){
if(Ideal[i].Ratio != 1){
rProb = 1 - abs(ratio - Ideal[i].Ratio);
sProb = 1 - abs(scaledDifference - Ideal[i].ScaledDifference);
aProb = abs((rProb + sProb)/2);
updateProbablities(Ideal[i].CoinA,aProb);
B.updateProbablities(Ideal[i].CoinB,aProb);
}
}
};
示例8: main
int main()
{
// Instantiate a coin and some dice
Coin c;
Die<6> d6;
Die<12> d12;
Die<20> d20;
// Now we test them!
std::cout << "Coin:";
for ( auto i = 0; i < 25; ++i )
std::cout << std::setw(3) << c.flip();
std::cout << "\n" "D6 :";
for ( auto i = 0; i < 25; ++i )
std::cout << std::setw(3) << d6.roll();
std::cout << "\n" "D12 :";
for ( auto i = 0; i < 25; ++i )
std::cout << std::setw(3) << d12.roll();
std::cout << "\n" "D20 :";
for ( auto i = 0; i < 25; ++i )
std::cout << std::setw(3) << d20.roll();
std::cout << std::endl;
return 0;
}
示例9: SetCoinsValue
static void SetCoinsValue(CAmount value, Coin& coin)
{
assert(value != ABSENT);
coin.Clear();
assert(coin.IsSpent());
if (value != PRUNED) {
coin.out.nValue = value;
coin.nHeight = 1;
assert(!coin.IsSpent());
}
}
示例10: Coin
//generateReward function
void Nonbreakable::generateReward(bool isLarge)
{
// if it is a question block decide which reward to give to mario
if (type_ == QUESTION) {
if (reward_ == COIN) {
// Create a coin above block it was in and adds drawable coin to the level
// uses the left and right of the block and the top and bottom plus 16
Coin *coin = new Coin();
coin->setLeft(this->left());
coin->setRight(this->right());
coin->setTop(this->top()+16);
coin->setBottom(this->top());
Level::sharedLevel()->addDrawable(coin);
}
else if (reward_ == MUSHROOM) {
if (isLarge != true) {
// Create a mushroom above block it was in and adds drawable coin to the level
// uses the left and right of the block and the top and bottom plus 16
Mushroom *mushroom = new Mushroom();
mushroom->setLeft(this->left());
mushroom->setRight(this->right());
mushroom->setTop(this->top()+16);
mushroom->setBottom(this->top());
Level::sharedLevel()->addMovable(mushroom);
}
else {
// Create a fireflower above block it was in and adds drawable coin to the level
// uses the left and right of the block and the top and bottom plus 16
FireFlower *fireFlower = new FireFlower();
fireFlower->setLeft(this->left());
fireFlower->setRight(this->right());
fireFlower->setTop(this->top()+16);
fireFlower->setBottom(this->top());
Level::sharedLevel()->addDrawable(fireFlower);
}
}
else {
// Create a star above block it was in and adds drawable coin to the level
// uses the left and right of the block and the top and bottom plus 16
Star *star = new Star();
star->setLeft(this->left());
star->setRight(this->right());
star->setTop(this->top()+16);
star->setBottom(this->top());
Level::sharedLevel()->addDrawable(star);
}
// once the block has been hit by mario and the reward generated change type to regular from question
type_ = OFFQUESTION;
}
}
示例11: CashException
bool BankTool::isCoinDoubleSpent(const Coin &coin1, const Coin &coin2) const {
// throw an exception if these coins do not share the same S value
if(coin1.getSPrime() != coin2.getSPrime())
{
throw CashException(CashException::CE_UNKNOWN_ERROR,
"[BankTool::checkIfCoinDoubleSpent] Coins do not share same serial "
"coin point and are not valid candidates for checking double "
"spending.");
}
// if contract hashes are same, then both coins were spent in the same
// transaction so the coin was not double spent
return (coin1.getR() != coin2.getR());
}
示例12: main
int main() {
Coin coin;
const int TURNS = 20;
cout << "The initial side is: " << coin.getSideUp() << endl;
for (int i = 0; i < TURNS; i++) {
coin.toss();
cout << "For turn #" << i + 1 << " the side is: " << coin.getSideUp() << endl;
}
return 0;
}
示例13: Coin
Coin * Coin::create(Vec2 position, GameStates & gameState)
{
std::shared_ptr<GameData> ptr = GameData::sharedGameData();
auto spritecache = SpriteFrameCache::getInstance();
spritecache->addSpriteFramesWithFile(ptr->m_textureAtlasPlistFile);
Coin* pSprite = new Coin(gameState);
if (pSprite->initWithSpriteFrameName(ptr->m_coinFile))
{
pSprite->autorelease();
pSprite->initOptions(position);
pSprite->addEvents();
pSprite->setTag(30);
auto towerBody = PhysicsBody::createBox(pSprite->getContentSize());
towerBody->setCollisionBitmask(0x000003);
towerBody->setContactTestBitmask(true);
towerBody->setTag(30);
//towerBody->setDynamic(false);
pSprite->setPhysicsBody(towerBody);
return pSprite;
}
CC_SAFE_DELETE(pSprite);
return NULL;
}
示例14: CoinFlip
int CoinFlip() {
Coin coin;
int numTosses;
int expectedHeads;
int expectedTails;
int numSimulations = 100;
int numHeads = 0;
int numTails = 0;
int count = 0;
cout << "Enter the number of tosses for each simulation:" << endl;
cin >> numTosses;
cout << "Enter Expected Return of Heads. Number must be less than " << numTosses << endl;
cin >> expectedHeads;
expectedTails = numTosses - expectedHeads;
cout << "Monte Carlo Simulation" << endl;
cout << "----------------------" << endl;
cout << "Number of coin tosses: " << numTosses << endl;
cout << "Expected Number of Heads: " << expectedHeads << endl;
cout << "Expected Number of Tails: " << expectedTails << endl;
cout << "Number of simulations to be run: " << numSimulations << endl;
cout << "Press any key to start runnig simulations:" << endl;
system("pause");
for (int i = 0; i<numSimulations; i++)
{
numHeads = 0;
numTails = 0;
for (int j = 0; j<numTosses; j++) {
if (coin.toss().compare("Heads")) numHeads++; else numTails++;
}
cout << "Heads: " << numHeads << " Tails: " << numTails << endl;
if (numHeads>expectedHeads) count++;
}
cout << "-------------------" << endl;
cout << "Simulation Complete" << endl;
cout << "-------------------" << endl;
cout << "Total number of simulations that resulted in Head values greater than the expected result of " << expectedHeads << " is " << count << endl;
cout << "Now compare the simulated probability to the binomial distribution calculated probability" << endl;
cout << "Simulated probability: " << ((double)count / numSimulations) << endl;
system("pause");
return 0;
}
示例15: EncryptedCoin
// pour new coin
EncryptedCoin(const Coin<FIELD>& coin) {
ENCRYPTOR ENC(coin.addr().cryptoKey());
RANDPOOL RNG;
std::stringstream ss;
coin.marshal_out(ss, false); // false means omit public address
const std::string& ptext = ss.str();
const std::size_t ptextLen = ptext.length() + 1;
// encrypt message
m_cipherText = std::vector<byte>(ENC.CiphertextLength(ptextLen), 0xfb);
ENC.Encrypt(RNG,
reinterpret_cast<const byte*>(ptext.data()),
ptextLen,
m_cipherText.data());
}