void CardOverview::loadFromList(const QList<const Card*> &list){ int i, n = list.length(); ui->tableWidget->setRowCount(n); for(i=0; i<n; i++) addCard(i, list.at(i)); if(n>0) ui->tableWidget->setCurrentItem(ui->tableWidget->item(0,0)); }
void Hand::dealNewHand(Deck &deck) { clearHand(); for (int i=0;i<5;i++) { addCard(deck.dealCard()); _drawCard.push_back(true); //new hand set draw to no for each new card } }
void PlayerMonsterBook::load() { mysqlpp::Query query = Database::getCharDB().query(); query << "SELECT cardid, level FROM monsterbook WHERE charid = " << m_player->getId() << " ORDER BY cardid ASC"; mysqlpp::StoreQueryResult res = query.store(); for (size_t i = 0; i < res.num_rows(); ++i) { addCard(res[i][0], (uint8_t) res[i][1], true); } calculateLevel(); }
void CardOverview::loadFromAll(){ int i, n = Sanguosha->getCardCount(); ui->tableWidget->setRowCount(n); for(i=0; i<n ;i++){ const Card *card = Sanguosha->getCard(i); addCard(i, card); } if(n>0) ui->tableWidget->setCurrentItem(ui->tableWidget->item(0,0)); }
TablePile::TablePile (int xl, int yl, int c, DeckPile *a): CardPile(xl, yl) { // then initialize our pile of cards for (int i = 0; i < c; i++) { addCard(a->top()); a->pop(); } // flip topmost card face up this->thePile.top()->flip(); }
void CardOverview::loadFromList(const QList<const Card *> &list) { int n = list.length(); ui->tableWidget->setRowCount(n); for (int i = 0; i < n; i++) addCard(i, list.at(i)); if (n > 0) { ui->tableWidget->setCurrentItem(ui->tableWidget->item(0, 0)); const Card *card = list.first(); ui->playAudioEffectButton->show(); ui->illustratorLineEdit->setText(getIllustratorInfo(card->objectName())); } }
/// ///Performs square quest /// void ValleyOfFire::execute(AdventureCardDeck* d, SpellDeck* s, PurchaseDeck* p, Character* c, QTextEdit* txtLog){ if(c->getTalisman() == -1){ txtLog->append("\nYou have already gotten the Talisman and defeated the Guardian. You may proceed to the Crown of Command and face your destiny."); } else if (c->getTalisman() == 1){ txtLog->append("\nYour perilous journey through the Valley of Fire brings you endless hardship costing you all but your last life.\nAs you approach the endless steps, you see the Talisman in your grasp.\nAs you take it for your own, you are confronted with the last Guardian of the Crown of Command.\nDefeat it to continue onward."); c->setLifePoints(1); c->setTalisman(-1); addCard(*(new Enemy("Guardian of the Crown", "Enemy", "The last Guardian of the Crown of Command.", 1, "Godlike", 14, "Strength"))); } else{ txtLog->append("\nYou have not yet found the Talisman. You must continue your search across the world before you can challenge the Guardian"); } }
void CardOverview::loadFromAll() { int n = Sanguosha->getCardCount(); ui->tableWidget->setRowCount(n); for (int i = 0; i < n ;i++) { const Card *card = Sanguosha->getEngineCard(i); addCard(i, card); } if (n > 0) { ui->tableWidget->setCurrentItem(ui->tableWidget->item(0, 0)); const Card *card = Sanguosha->getEngineCard(0); ui->playAudioEffectButton->show(); ui->illustratorLineEdit->setText(getIllustratorInfo(card->objectName())); } }
void ZoneViewZone::initializeCards(const QList<const ServerInfo_Card *> &cardList) { if (!cardList.isEmpty()) { for (int i = 0; i < cardList.size(); ++i) addCard(new CardItem(player, QString::fromStdString(cardList[i]->name()), cardList[i]->id(), revealZone, this), false, i); reorganizeCards(); } else if (!origZone->contentsKnown()) { Command_DumpZone cmd; cmd.set_player_id(player->getId()); cmd.set_zone_name(name.toStdString()); cmd.set_number_cards(numberCards); PendingCommand *pend = player->prepareGameCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(zoneDumpReceived(const Response &))); player->sendGameCommand(pend); } else {
void playBlackJack(){ if(compTotal < 16){ addCompCard(); } char check; char nothing; char nothing1; char play; while(userTotal <=21){ printf("\n\nWould you like to stay or hit:"); printf("\n Hit- 'h'"); nothing = getchar(); printf("\n Stay- 's'"); check = getchar(); if(check == 'h'){ addCard(); } if(check == 's'){ checkWhenNo(); break; } } nothing1 = getchar(); printf("\n\n If you would like to play again enter a 'y'. If not enter a 'n'"); play = getchar(); if(play == 'y'){ userTotal =0; compTotal =0; playAgain(); } }
void CardOverview::loadFromList(const QList<const Card *> &list) { int n = list.length(); ui->tableWidget->setRowCount(n); for (int i = 0; i < n; i++) addCard(i, list.at(i)); if (n > 0) { ui->tableWidget->setCurrentItem(ui->tableWidget->item(0, 0)); const Card *card = list.first(); if (card->getTypeId() == Card::TypeEquip) { ui->playAudioEffectButton->show(); ui->malePlayButton->hide(); ui->femalePlayButton->hide(); } else { ui->playAudioEffectButton->hide(); ui->malePlayButton->show(); ui->femalePlayButton->show(); } } }
void runTests() { Deck testDeck; testDeck.length = 0; if(!isEmpty(testDeck)) { printf("isEmpty test 1 failed!\n"); } testDeck.length = 1; if(isEmpty(testDeck)) { printf("isEmpty test 2 failed!\n"); } testDeck.length = 0; Card testCard; testCard.suit = Hearts; testCard.value = 13; addCard(&testDeck, testCard); printCard(testDeck.cards[0]); printf("\n======\n"); if(isEmpty(testDeck)) { printf("addCard test 1 failed!\n"); } //Card yourmom = removeCard(&testDeck); //printCard(yourmom); }
void CardOverview::loadFromAll() { int n = Sanguosha->getCardCount(); ui->tableWidget->setRowCount(n); for (int i = 0; i < n ; i++) { const Card *card = Sanguosha->getEngineCard(i); addCard(i, card); } if (n > 0) { ui->tableWidget->setCurrentItem(ui->tableWidget->item(0, 0)); const Card *card = Sanguosha->getEngineCard(0); if (card->getTypeId() == Card::TypeEquip) { ui->playAudioEffectButton->show(); ui->malePlayButton->hide(); ui->femalePlayButton->hide(); } else { ui->playAudioEffectButton->hide(); ui->malePlayButton->show(); ui->femalePlayButton->show(); } } }
bool CardPlayer::checkTing() { MJCard card; int i; int j; bool ret = false; for(i = MJTYPE_TIAO; i < MJTYPE_BAIDA; i++) { for(j = 1; j < 10; j++) { card.type = i; card.value = j; if(!isBaida(card)) { addCard(card); bool tmp = checkHu(); rmCard(card); if(tmp) { if(ret == false) { printf("====================================================================\n"); } addTmpCard(card); dump(); rmTmpCard(); printf("mode: "); showHu(); printf("====================================================================\n"); } ret |= tmp; } } } return ret; }
// Validate Values on change connect(ui.tableResources, SIGNAL(itemChanged( QTableWidgetItem* )), this, SLOT(validateValues())); connect(ui.tableModifiers, SIGNAL(itemChanged( QTableWidgetItem* )), this, SLOT(validateValues())); // Connect Change Listener connect(ui.editCardName, SIGNAL(editingFinished()), this, SLOT(somethingChanged())); connect(ui.spinDamageOpponent, SIGNAL(valueChanged(int)), this, SLOT(somethingChanged())); connect(ui.spinDamageSelf, SIGNAL(valueChanged(int)), this, SLOT(somethingChanged())); connect(ui.checkAddTurn, SIGNAL(clicked()), this, SLOT(somethingChanged())); connect(ui.checkDiscard, SIGNAL(clicked()), this, SLOT(somethingChanged())); connect(ui.checkNotDiscardable, SIGNAL(clicked()), this, SLOT(somethingChanged())); connect(ui.tableResources, SIGNAL(itemDoubleClicked( QTableWidgetItem* )), this, SLOT(somethingChanged())); connect(ui.tableModifiers, SIGNAL(itemDoubleClicked( QTableWidgetItem* )), this, SLOT(somethingChanged())); connect(ui.buttonRemoveCard, SIGNAL(clicked()), this, SLOT(removeCard())); connect(ui.buttonAddCard, SIGNAL(clicked()), this, SLOT(addCard())); connect(ui.buttonOpenImage, SIGNAL(clicked()), this, SLOT(selectImage())); } // ----------------------------------------------------------------------------- void CardEditor::populateTree() { // If we're simply loading a new Project, refresh the view if(!ui.cardList->size().isEmpty()) { ui.cardList->clear(); reset(); } // Populate List int i = 0; foreach(Arcomage::Card* c, cards) { addCardToList(c, i);
void Player::addCardToHand(Card* card) { addCard(card, &hand); std::clog << "Added card: " << card->getCardTemplate()->getName() << " to player's hand\n"; }
bool Deck::importFromXml(QString fileName) { QDomDocument domDocument; QString errorStr; int errorLine; int errorColumn; QFile file(fileName); file.open(QIODevice::ReadOnly | QIODevice::Text); if(!file.isOpen()) return false; if (!domDocument.setContent(&file, true, &errorStr, &errorLine, &errorColumn)) { qDebug() << QString("Parse error at line %1, column %2:\n%3") .arg(errorLine) .arg(errorColumn) .arg(errorStr); return false; } QDomElement root = domDocument.documentElement(); if (root.tagName().toLower() != XML_TAG_ROOT) { qDebug() << "root node is mismatched."; return false; } QDomElement nodeDeck; QDomElement nodeCards; QDomElement elnode; nodeDeck = root.firstChildElement(XML_TAG_DECK); if(nodeDeck.isNull()) { qDebug() << "deck node is mismatched."; return false; } elnode = nodeDeck.firstChildElement(XML_TAG_NAME); if(!elnode.isNull()) { name=elnode.text(); } elnode = nodeDeck.firstChildElement(XML_TAG_DESC); if(!elnode.isNull()) { desc=elnode.text(); } elnode = nodeDeck.firstChildElement(XML_TAG_ICON); if(!elnode.isNull()) { } elnode = nodeDeck.firstChildElement(XML_TAG_GUID); if(!elnode.isNull()) { guid=QUuid(elnode.text()); } elnode = nodeDeck.firstChildElement(XML_TAG_CREATED); if(!elnode.isNull()) { createdTime=QDateTime::fromString(elnode.text()); } elnode = nodeDeck.firstChildElement(XML_TAG_UPDATED); if(!elnode.isNull()) { updatedTime=QDateTime::fromString(elnode.text()); } elnode = nodeDeck.firstChildElement(XML_TAG_AUTHOR); if(!elnode.isNull()) { author=elnode.text(); } elnode = nodeDeck.firstChildElement(XML_TAG_TAGS); if(!elnode.isNull()) { tags=elnode.text(); } elnode = nodeDeck.firstChildElement(XML_TAG_FLAGS); if(!elnode.isNull()) { flags=elnode.text().toUInt(); } elnode = nodeDeck.firstChildElement(XML_TAG_INHAND); if(!elnode.isNull()) { inhand=elnode.text().toInt(); } elnode = nodeDeck.firstChildElement(XML_TAG_FORMAT); if(!elnode.isNull()) { //// Converting QDomElement to QString //// http://qt-project.org/doc/qt-5/qdomnode.html#save QString str; QTextStream stream(&str); elnode.save(stream, 4); format.fromString(str); } nodeCards = nodeDeck.firstChildElement(XML_TAG_CARDS); if(!elnode.isNull()) { QDomNodeList nodes = root.elementsByTagName(XML_TAG_CARD); QDomNode nodeCard; QString front, back; int flags = 0; int count = nodes.count(); for(int no = 0; no < count; no++) { nodeCard = nodes.at(no); flags = 0; front.clear(); back.clear(); elnode = nodeCard.firstChildElement(XML_TAG_FRONT); if(!elnode.isNull()) { front = elnode.text(); } elnode = nodeCard.firstChildElement(XML_TAG_BACK); if(!elnode.isNull()) { back = elnode.text(); } elnode = nodeCard.firstChildElement(XML_TAG_FLAGS); if(!elnode.isNull()) { flags = elnode.text().toInt(); } if(!front.isEmpty()) { Card *card = new Card; card->updateFront(front); card->updateBack(back); card->setFlags(flags); addCard(card); } } } file.close(); return true; }
bool Deck::importMnemosyne(QString fileName) { QFileInfo fi(fileName); QString baseName = fi.baseName().toLower(); QString tempFolder = utils::combinePaths(tempPath(), baseName); QString metadataPath = utils::combinePaths(tempFolder, "METADATA"); QString cardsPath = utils::combinePaths(tempFolder, "cards.xml"); utils::createDirectory(tempFolder); Compressor c; if(!c.decompressFolder(fileName, tempFolder)) { return false; } /// import metadata /// QTextStream s; QFile metadataFile(metadataPath); metadataFile.open(QIODevice::ReadOnly | QIODevice::Text); if(!metadataFile.isOpen()) return false; s.setDevice(&metadataFile); s.setCodec("UTF-8"); QStringList sl; QString l = s.readLine(); while (!s.atEnd()) { sl = l.split(":"); if(sl.size()>1) { if(sl[0]=="tags") setTags(sl[1]); else if(sl[0]=="notes") setDesc(sl[1]); else if(sl[0]=="author_name") setAuthor(sl[1]); else if(sl[0]=="card_set_name") setName(sl[1]); } l = s.readLine(); } /// read cards QDomDocument domDocument; QString errorStr; int errorLine; int errorColumn; QString front, back, level; QFile cardsFile(cardsPath); cardsFile.open(QIODevice::ReadOnly | QIODevice::Text); if(!cardsFile.isOpen()) return false; if (!domDocument.setContent(&cardsFile, true, &errorStr, &errorLine, &errorColumn)) { qDebug() << QString("Parse error at line %1, column %2:\n%3") .arg(errorLine) .arg(errorColumn) .arg(errorStr); return false; } QDomElement root = domDocument.documentElement(); QString rootName = root.tagName().toLower(); if (rootName == "opensm2sync") { QDomNodeList nodes = root.elementsByTagName("log"); QDomNode node; QDomElement elnode; int count = nodes.count(); for(int no = 0; no < count; no++) { node = nodes.at(no); if(node.attributes().namedItem("type").nodeValue()=="16") { elnode = node.firstChildElement("f"); front = elnode.text(); elnode = node.firstChildElement("b"); back = elnode.text(); if(!front.isEmpty()) { Card *card = new Card(); card->updateFront(front); card->updateBack(back); addCard(card); } } } } metadataFile.close(); cardsFile.close(); utils::removeFile(metadataPath); utils::removeFile(cardsPath); utils::copyDirectory(getDeckPath(), tempFolder); return true; }
void Deck::Merge(Deck *dst, int option, int *stats) { /// first of all, open the deck! if(!openDeck()) return; int rightCount = dst->getCardsNo(); int leftCount = this->getCardsNo(); Card *rightCard=0; Card *leftCard=0; bool hasMerged = false; if(stats) *stats = 0; QList<Card*> cards; for(int i=0; i < rightCount; i++) { rightCard = dst->getCardAt(i); hasMerged = false; for(int j=0; j < leftCount; j++) { leftCard = this->getCardAt(j); if(leftCard->compare(*rightCard)) { hasMerged = true; switch(option) { case AcceptSource: break; case AcceptTarget: leftCard->updateBack(rightCard->getBack()); break; case AutoMerge: hasMerged = false; break; } break; } } if(!hasMerged) { if(stats) (*stats)++; Card *card = new Card(*rightCard); cards.append(card); } } /// flush list to deck for(int index = 0; index < cards.size(); index++) { addCard(cards[index]); } /// update deck info if(option!=AcceptSource) { name = dst->getName(); desc = dst->getDesc(); author = dst->getAuthor(); tags = dst->getTags(); pixmap = dst->getPixmap(); format = dst->getFormat(); flags = dst->getFlags(); } utils::copyDirectory(getDeckPath(), dst->getDeckPath()); saveDeck(); }
int main(int argc, char **argv) { int res; nfc_connstring devices[8]; size_t device_count; nfc_context *nfcctx; char *uid = NULL; init_crypto_state(); nfc_init(&nfcctx); device_count = nfc_list_devices(nfcctx,devices,8); if (device_count <= 0) { std::cerr << "No device found" << std::endl; } device = nfc_open(nfcctx, devices[0]); tags = freefare_get_tags(device); if (tags[0] == NULL) { std::cerr << "No tag on device" << std::endl; exit(1); } for (int i = 0; tags[i]; i++) { if (freefare_get_tag_type(tags[i]) == CLASSIC_1K) { tag = tags[i]; res = mifare_classic_connect(tag); if (res != 0) { std::cout << "Error connecting to MiFare Classic" << std::endl; exit(1); } std::cout << "Connected to MiFare Classic" << std::endl; uid = freefare_get_tag_uid(tag); break; } } std::cout << "UID: " << uid << std::endl; MifareClassicKey *keyA = (MifareClassicKey *)get_random_bytes(6); std::cout << "Key A: "; print_hex(*keyA,6); char *b64KeyA = getBase64String((char *)keyA,6); std::cout << b64KeyA << std::endl; std::cout << "Key B: "; MifareClassicKey *keyB = (MifareClassicKey *)get_random_bytes(6); print_hex(*keyB,6); char *b64KeyB = getBase64String((char *)keyB,6); bool addedToServer = addCard(uid,b64KeyA,b64KeyB); if (!addedToServer) { printf("Not added to server\n"); } // Authenticate with default key to make changes MifareClassicBlockNumber lastTrailer = mifare_classic_sector_last_block(15); res = mifare_classic_authenticate(tag,lastTrailer,defaultKey,MFC_KEY_A); if (res != 0) { printf("Could not authenticate with default key.. card already formatted?\n"); return -1; } MifareClassicBlockNumber firstBlock = mifare_classic_sector_first_block(15); res = mifare_classic_init_value(tag,firstBlock,SECTOR_15_BLOCK_0_INIT,firstBlock); if (res != 0) { printf("Could not init value block %d\n",firstBlock); } MifareClassicBlock trailerBlock; mifare_classic_trailer_block(&trailerBlock,*keyA,0x03,0x00,0x00,0x04,0x00, *keyB); print_hex(trailerBlock, sizeof(MifareClassicBlock)); res = mifare_classic_write(tag,lastTrailer,trailerBlock); if (res != 0) { printf("Could not write sector 15 trailer. STOP\n"); return -1; } MifareClassicBlock normalTrailerBlock; mifare_classic_trailer_block(&normalTrailerBlock,*keyA,0x00,0x00,0x00,0x04,0x00,*keyB); printf("Writing normal trailer block "); print_hex(&normalTrailerBlock[0], sizeof(MifareClassicBlock)); MifareClassicSectorNumber sector; for(sector=0; sector<15;sector++) { MifareClassicBlockNumber trailerBlockNumber = mifare_classic_sector_last_block(sector); res = mifare_classic_authenticate(tag,trailerBlockNumber,defaultKey,MFC_KEY_A); if (res != 0) { printf("Could not authenticate with default key.. card already formatted?\n"); return -1; } res = mifare_classic_write(tag,trailerBlockNumber,normalTrailerBlock); if (res != 0) { printf("Could not write trailer block for sector %d\n",sector); return -1; } else { printf("Wrote trailer block for sector %d\n",sector); } } free(keyA); free(keyB); free(b64KeyA); free(b64KeyB); free(uid); freefare_free_tags(tags); nfc_close(device); }
/// ///Performs square quest /// void PlainOfPeril::execute(AdventureCardDeck* d, SpellDeck* s, PurchaseDeck* p, Character* c, QTextEdit* txtLog){ AdventureCard* a = d->drawCard(); static_cast<Enemy*>(a)->setAttackPoints(static_cast<Enemy*>(a)->getAttackPoints() + 2); addCard(*a); }
void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens) { while (!xml.atEnd()) { if (xml.readNext() == QXmlStreamReader::EndElement) break; if (xml.name() == "card") { QString name, manacost, cmc, type, pt, text; QStringList colors; QStringMap customPicURLs, customPicURLsHq; MuidMap muids; SetList sets; int tableRow = 0; int loyalty = 0; bool cipt = false; bool isToken = false; while (!xml.atEnd()) { if (xml.readNext() == QXmlStreamReader::EndElement) break; if (xml.name() == "name") name = xml.readElementText(); else if (xml.name() == "manacost") manacost = xml.readElementText(); else if (xml.name() == "cmc") cmc = xml.readElementText(); else if (xml.name() == "type") type = xml.readElementText(); else if (xml.name() == "pt") pt = xml.readElementText(); else if (xml.name() == "text") text = xml.readElementText(); else if (xml.name() == "set") { QXmlStreamAttributes attrs = xml.attributes(); QString setName = xml.readElementText(); sets.append(getSet(setName)); if (attrs.hasAttribute("muId")) { muids[setName] = attrs.value("muId").toString().toInt(); } if (attrs.hasAttribute("picURL")) { customPicURLs[setName] = attrs.value("picURL").toString(); } if (attrs.hasAttribute("picURLHq")) { customPicURLsHq[setName] = attrs.value("picURLHq").toString(); } } else if (xml.name() == "color") colors << xml.readElementText(); else if (xml.name() == "tablerow") tableRow = xml.readElementText().toInt(); else if (xml.name() == "cipt") cipt = (xml.readElementText() == "1"); else if (xml.name() == "loyalty") loyalty = xml.readElementText().toInt(); else if (xml.name() == "token") isToken = xml.readElementText().toInt(); } if (isToken == tokens) { addCard(new CardInfo(this, name, isToken, manacost, cmc, type, pt, text, colors, loyalty, cipt, tableRow, sets, customPicURLs, customPicURLsHq, muids)); } } } }
int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) { int cards = 0; QListIterator<QVariant> it(data.toList()); QVariantMap map; QString cardName; QString cardCost; QString cardType; QString cardPT; QString cardText; int cardId; int cardLoyalty; QMap<int, QVariantMap> splitCards; while (it.hasNext()) { map = it.next().toMap(); if(0 == QString::compare(map.value("layout").toString(), QString("split"), Qt::CaseInsensitive)) { // Split card handling cardId = map.contains("multiverseid") ? map.value("multiverseid").toInt() : 0; if(splitCards.contains(cardId)) { // merge two split cards QVariantMap tmpMap = splitCards.take(cardId); QVariantMap * card1 = 0, * card2 = 0; // same cardid cardId = map.contains("multiverseid") ? map.value("multiverseid").toInt() : 0; // this is currently an integer; can't accept 2 values cardLoyalty = 0; // determine which subcard is the first one in the split QStringList names=map.contains("names") ? map.value("names").toStringList() : QStringList(""); if(names.count()>0 && map.contains("name") && 0 == QString::compare(map.value("name").toString(), names.at(0))) { // map is the left part of the split card, tmpMap is right part card1 = ↦ card2 = &tmpMap; } else { //tmpMap is the left part of the split card, map is right part card1 = &tmpMap; card2 = ↦ } // add first card's data cardName = card1->contains("name") ? card1->value("name").toString() : QString(""); cardCost = card1->contains("manaCost") ? card1->value("manaCost").toString() : QString(""); cardType = card1->contains("type") ? card1->value("type").toString() : QString(""); cardPT = card1->contains("power") || card1->contains("toughness") ? card1->value("power").toString() + QString('/') + card1->value("toughness").toString() : QString(""); cardText = card1->contains("text") ? card1->value("text").toString() : QString(""); // add second card's data cardName += card2->contains("name") ? QString(" // ") + card2->value("name").toString() : QString(""); cardCost += card2->contains("manaCost") ? QString(" // ") + card2->value("manaCost").toString() : QString(""); cardType += card2->contains("type") ? QString(" // ") + card2->value("type").toString() : QString(""); cardPT += card2->contains("power") || card2->contains("toughness") ? QString(" // ") + card2->value("power").toString() + QString('/') + card2->value("toughness").toString() : QString(""); cardText += card2->contains("text") ? QString("\n\n---\n\n") + card2->value("text").toString() : QString(""); } else { // first card od a pair; enqueue for later merging splitCards.insert(cardId, map); continue; } } else { // normal cards handling cardName = map.contains("name") ? map.value("name").toString() : QString(""); cardCost = map.contains("manaCost") ? map.value("manaCost").toString() : QString(""); cardType = map.contains("type") ? map.value("type").toString() : QString(""); cardPT = map.contains("power") || map.contains("toughness") ? map.value("power").toString() + QString('/') + map.value("toughness").toString() : QString(""); cardText = map.contains("text") ? map.value("text").toString() : QString(""); cardId = map.contains("multiverseid") ? map.value("multiverseid").toInt() : 0; cardLoyalty = map.contains("loyalty") ? map.value("loyalty").toInt() : 0; } CardInfo *card = addCard(set->getShortName(), cardName, false, cardId, cardCost, cardType, cardPT, cardLoyalty, cardText.split("\n")); if (!set->contains(card)) { card->addToSet(set); cards++; } } return cards; }
void Player::addCardToDeck(Card* card) { addCard(card, &deck); std::clog << "Added card: " << card->getCardTemplate()->getName() << " to player's deck\n"; }
void CardPile::addCard(int val, Suits suit) { Card c(val, suit); addCard(c); }
void qjackctlInterfaceComboBox::populateModel (void) { bool bBlockSignals = QComboBox::blockSignals(true); QComboBox::setUpdatesEnabled(false); QComboBox::setDuplicatesEnabled(false); QLineEdit *pLineEdit = QComboBox::lineEdit(); // FIXME: Only valid for ALSA, Sun and OSS devices, // for the time being... and also CoreAudio ones too. const QString& sDriver = m_pDriverComboBox->currentText(); bool bAlsa = (sDriver == "alsa"); bool bSun = (sDriver == "sun"); bool bOss = (sDriver == "oss"); #ifdef CONFIG_COREAUDIO bool bCoreaudio = (sDriver == "coreaudio"); std::map<QString, AudioDeviceID> coreaudioIdMap; #endif #ifdef CONFIG_PORTAUDIO bool bPortaudio = (sDriver == "portaudio"); #endif QString sCurName = pLineEdit->text(); QString sName, sSubName; int iCards = 0; clearCards(); int iCurCard = -1; if (bAlsa) { #ifdef CONFIG_ALSA_SEQ // Enumerate the ALSA cards and PCM harfware devices... snd_ctl_t *handle; snd_ctl_card_info_t *info; snd_pcm_info_t *pcminfo; snd_ctl_card_info_alloca(&info); snd_pcm_info_alloca(&pcminfo); const QString sPrefix("hw:%1"); const QString sSuffix(" (%1)"); const QString sSubSuffix("%1,%2"); QString sName2, sSubName2; bool bCapture, bPlayback; int iCard = -1; while (snd_card_next(&iCard) >= 0 && iCard >= 0) { sName = sPrefix.arg(iCard); if (snd_ctl_open(&handle, sName.toUtf8().constData(), 0) >= 0 && snd_ctl_card_info(handle, info) >= 0) { sName2 = sPrefix.arg(snd_ctl_card_info_get_id(info)); addCard(sName2, snd_ctl_card_info_get_name(info) + sSuffix.arg(sName)); if (sCurName == sName || sCurName == sName2) iCurCard = iCards; ++iCards; int iDevice = -1; while (snd_ctl_pcm_next_device(handle, &iDevice) >= 0 && iDevice >= 0) { // Capture devices.. bCapture = false; if (m_iAudio == QJACKCTL_CAPTURE || m_iAudio == QJACKCTL_DUPLEX) { snd_pcm_info_set_device(pcminfo, iDevice); snd_pcm_info_set_subdevice(pcminfo, 0); snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_CAPTURE); bCapture = (snd_ctl_pcm_info(handle, pcminfo) >= 0); } // Playback devices.. bPlayback = false; if (m_iAudio == QJACKCTL_PLAYBACK || m_iAudio == QJACKCTL_DUPLEX) { snd_pcm_info_set_device(pcminfo, iDevice); snd_pcm_info_set_subdevice(pcminfo, 0); snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK); bPlayback = (snd_ctl_pcm_info(handle, pcminfo) >= 0); } // List iif compliant with the audio mode criteria... if ((m_iAudio == QJACKCTL_CAPTURE && bCapture && !bPlayback) || (m_iAudio == QJACKCTL_PLAYBACK && !bCapture && bPlayback) || (m_iAudio == QJACKCTL_DUPLEX && bCapture && bPlayback)) { sSubName = sSubSuffix.arg(sName).arg(iDevice); sSubName2 = sSubSuffix.arg(sName2).arg(iDevice); addCard(sSubName2, snd_pcm_info_get_name(pcminfo) + sSuffix.arg(sSubName)); if (sCurName == sSubName || sCurName == sSubName2) iCurCard = iCards; ++iCards; } } snd_ctl_close(handle); } } #endif // CONFIG_ALSA_SEQ } else if (bSun) { QFile file("/var/run/dmesg.boot"); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); QString sLine; QRegExp rxDevice("audio([0-9]) at (.*)"); while (!stream.atEnd()) { sLine = stream.readLine(); if (rxDevice.exactMatch(sLine)) { sName = "/dev/audio" + rxDevice.cap(1); addCard(sName, rxDevice.cap(2)); if (sCurName == sName) iCurCard = iCards; ++iCards; } } file.close(); } } else if (bOss) { // Enumerate the OSS Audio devices... QFile file("/dev/sndstat"); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); QString sLine; bool bAudioDevices = false; QRegExp rxHeader("Audio devices.*", Qt::CaseInsensitive); QRegExp rxDevice("([0-9]+):[ ]+(.*)"); while (!stream.atEnd()) { sLine = stream.readLine(); if (bAudioDevices) { if (rxDevice.exactMatch(sLine)) { sName = "/dev/dsp" + rxDevice.cap(1); addCard(sName, rxDevice.cap(2)); if (sCurName == sName) iCurCard = iCards; ++iCards; } else break; } else if (rxHeader.exactMatch(sLine)) bAudioDevices = true; } file.close(); } } #ifdef CONFIG_COREAUDIO else if (bCoreaudio) { // Find out how many Core Audio devices are there, if any... // (code snippet gently "borrowed" from Stephane Letz jackdmp;) OSStatus err; Boolean isWritable; UInt32 outSize = sizeof(isWritable); err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &outSize, &isWritable); if (err == noErr) { // Calculate the number of device available... int numCoreDevices = outSize / sizeof(AudioDeviceID); // Make space for the devices we are about to get... AudioDeviceID *coreDeviceIDs = new AudioDeviceID [numCoreDevices]; err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &outSize, (void *) coreDeviceIDs); if (err == noErr) { // Look for the CoreAudio device name... char coreDeviceName[256]; UInt32 nameSize = 256; for (int i = 0; i < numCoreDevices; i++) { err = AudioDeviceGetPropertyInfo(coreDeviceIDs[i], 0, true, kAudioDevicePropertyDeviceName, &outSize, &isWritable); if (err == noErr) { err = AudioDeviceGetProperty(coreDeviceIDs[i], 0, true, kAudioDevicePropertyDeviceName, &nameSize, (void *) coreDeviceName); if (err == noErr) { char drivername[128]; UInt32 dnsize = 128; // this returns the unique id for the device // that must be used on the commandline for jack if (getDeviceUIDFromID(coreDeviceIDs[i], drivername, dnsize) == noErr) { sName = drivername; } else { sName = "Error"; } coreaudioIdMap[sName] = coreDeviceIDs[i]; // TODO: hide this ugly ID from the user, // only show human readable name // humanreadable \t UID sSubName = QString(coreDeviceName); addCard(sSubName, sName); if (sCurName == sName || sCurName == sSubName) iCurCard = iCards; ++iCards; } } } } delete [] coreDeviceIDs; } } #endif // CONFIG_COREAUDIO #ifdef CONFIG_PORTAUDIO else if (bPortaudio) { if (Pa_Initialize() == paNoError) { // Fill hostapi info... PaHostApiIndex iNumHostApi = Pa_GetHostApiCount(); QString *pHostName = new QString[iNumHostApi]; for (PaHostApiIndex i = 0; i < iNumHostApi; ++i) pHostName[i] = QString(Pa_GetHostApiInfo(i)->name); // Fill device info... PaDeviceIndex iNumDevice = Pa_GetDeviceCount(); PaDeviceInfo **ppDeviceInfo = new PaDeviceInfo * [iNumDevice]; for (PaDeviceIndex i = 0; i < iNumDevice; ++i) { ppDeviceInfo[i] = const_cast<PaDeviceInfo *> (Pa_GetDeviceInfo(i)); sName = pHostName[ppDeviceInfo[i]->hostApi] + "::" + QString(ppDeviceInfo[i]->name); addCard(sName, QString()); if (sCurName == sName) iCurCard = iCards; ++iCards; } Pa_Terminate(); } } #endif // CONFIG_PORTAUDIO addCard(m_sDefName, QString()); if (sCurName == m_sDefName || sCurName.isEmpty()) iCurCard = iCards; ++iCards; QTreeView *pTreeView = static_cast<QTreeView *> (QComboBox::view()); pTreeView->setMinimumWidth( pTreeView->sizeHint().width() + QComboBox::iconSize().width()); QComboBox::setCurrentIndex(iCurCard); pLineEdit->setText(sCurName); QComboBox::setUpdatesEnabled(true); QComboBox::blockSignals(bBlockSignals); }
int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data) { int cards = 0; QString bufferContents(data); // Workaround for ampersand bug in text spoilers int index = -1; while ((index = bufferContents.indexOf('&', index + 1)) != -1) { int semicolonIndex = bufferContents.indexOf(';', index); if (semicolonIndex > 5) { bufferContents.insert(index + 1, "amp;"); index += 4; } } QDomDocument doc; QString errorMsg; int errorLine, errorColumn; if (!doc.setContent(bufferContents, &errorMsg, &errorLine, &errorColumn)) qDebug() << "error:" << errorMsg << "line:" << errorLine << "column:" << errorColumn; QDomNodeList divs = doc.elementsByTagName("div"); for (int i = 0; i < divs.size(); ++i) { QDomElement div = divs.at(i).toElement(); QDomNode divClass = div.attributes().namedItem("class"); if (divClass.nodeValue() == "textspoiler") { QString cardName, cardCost, cardType, cardPT, cardText; int cardId = 0; int cardLoyalty = 0; QDomNodeList trs = div.elementsByTagName("tr"); for (int j = 0; j < trs.size(); ++j) { QDomElement tr = trs.at(j).toElement(); QDomNodeList tds = tr.elementsByTagName("td"); if (tds.size() != 2) { QStringList cardTextSplit = cardText.split("\n"); for (int i = 0; i < cardTextSplit.size(); ++i) cardTextSplit[i] = cardTextSplit[i].trimmed(); CardInfo *card = addCard(set->getShortName(), cardName, false, cardId, cardCost, cardType, cardPT, cardLoyalty, cardTextSplit); if (!set->contains(card)) { card->addToSet(set); cards++; } cardName = cardCost = cardType = cardPT = cardText = QString(); } else { QString v1 = tds.at(0).toElement().text().simplified(); QString v2 = tds.at(1).toElement().text().replace(trUtf8("—"), "-"); if (v1 == "Name") { QDomElement a = tds.at(1).toElement().elementsByTagName("a").at(0).toElement(); QString href = a.attributes().namedItem("href").nodeValue(); cardId = href.mid(href.indexOf("multiverseid=") + 13).toInt(); cardName = v2.simplified(); } else if (v1 == "Cost:") cardCost = v2.simplified(); else if (v1 == "Type:") cardType = v2.simplified(); else if (v1 == "Pow/Tgh:") cardPT = v2.simplified().remove('(').remove(')'); else if (v1 == "Rules Text:") cardText = v2.trimmed(); else if (v1 == "Loyalty:") cardLoyalty = v2.trimmed().remove('(').remove(')').toInt(); } } break; } } return cards; }
/// ///Performs square quest /// void WerewolfDen::execute(AdventureCardDeck* d, SpellDeck* s, PurchaseDeck* p, Character* c, QTextEdit* txtLog){ int num = rand() % 6 + 6; addCard(*(new Enemy("Werewolf", "Enemy", "An unusually powerful Werefwolf.", 1, "Wolf", num, "Strength"))); }
bool MTGGameZone::parseLine(const string& ss) { bool result = false; string s = ss; for (int i = 0; i < nb_cards; i++) { SAFE_DELETE( cards[i] ); } cards.clear(); cardsMap.clear(); nb_cards = 0; while(s.size()) { size_t limiter = s.find(","); MTGCard * card = 0; string toFind; if (limiter != string::npos) { toFind = trim(s.substr(0, limiter)); s = s.substr(limiter + 1); } else { toFind = trim(s); s = ""; } card = MTGCollection()->getCardByName(toFind); int id = Rules::getMTGId(toFind); if (card) { /* For the moment we add the card directly in the final zone. This is not the normal way and this prevents to resolve spells. We'll need a fusion operation afterward to cast relevant spells */ MTGCardInstance * newCard = NEW MTGCardInstance(card, owner->game); addCard(newCard); result = true; } else { if(toFind == "*") nb_cards++; else if ( id < 0 ) { // For the moment, we create a dummy Token to please the testsuite Token* myToken = new Token(id); addCard(myToken); result = true; } else { DebugTrace("Card unfound " << toFind << " " << id); } } } return result; }
/** \brief Imprime o html correspondente a uma carta @param path O URL correspondente à pasta que contém todas as cartas @param x A coordenada x da carta @param y A coordenada y da carta @param suit O naipe da carta (inteiro entre 0 e 3) @param value O valor da carta (inteiro entre 0 e 12) @param gameState O estado de jogo atual (para determinar urls após cliques nas cartas) @param cardPosition Usado para a rotação. 0 - cima, 1 - direita, 2 - baixo, 3 - esquerda */ void printCard (char *path, int x, int y, int suit, int value, state gameState, int cardPosition) { /* Criar um estado que será usado se o utilizador clicar nesta carta */ state stateAfterClick = gameState; /* Se a carta pertence ao utilizador */ bool isUserCard = cardExists(gameState.hands[0], suit, value); /* Classes html desta carta */ char cardElementClasses[256] = "card"; /* Classe de rotação da carta */ char cardRotationClass[32]; if (cardPosition == 0) { strcpy(cardRotationClass, "card-top"); } else if (cardPosition == 1) { strcpy(cardRotationClass, "card-right"); } else if (cardPosition == 2) { strcpy(cardRotationClass, "card-bottom"); } else if (cardPosition == 3) { strcpy(cardRotationClass, "card-left"); } /* Classe que desativa cliques na carta */ char cardDisableClass[32] = "disabled"; /* Se a carta for do utilizador */ if (isUserCard) { /* Não adicionar à carta a classe que a desativa */ cardDisableClass[0] = '\0'; /* Mudar as classes html desta carta (para aplicar estilos personalizados) */ strcpy(cardElementClasses, "card user-card"); /* Se a carta já está selecionada */ if (cardExists(gameState.selection, suit, value)) { /* Ao clicar nela será descelecionada */ stateAfterClick.selection = removeCard(stateAfterClick.selection, suit, value); } else { /* Ao clicar nela será selecionada */ stateAfterClick.selection = addCard(stateAfterClick.selection, suit, value); } } /* Else, clicar na carta não faz nada */ /* Criar url que será usado se esta carta for clicada, usando o estado que já foi criado acima */ char onClickUrl[10240]; sprintf(onClickUrl, "%s?q=%s", SCRIPT, stateToString(stateAfterClick)); printf("<a href=\"%s\"><img src=\"%s/%c%c.svg\" class=\"%s %s %s\" style=\"position: absolute; left:%dpx; top: %dpx; height: 110px; width: 76px;\"></a>\n", onClickUrl, path, VALUES[value], SUITS[suit], cardElementClasses, cardRotationClass, cardDisableClass, x, y); }