本文整理汇总了C++中CardList::add方法的典型用法代码示例。如果您正苦于以下问题:C++ CardList::add方法的具体用法?C++ CardList::add怎么用?C++ CardList::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CardList
的用法示例。
在下文中一共展示了CardList::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: legalMoves
//Given the cards already played by all players and a player's hand, determines the legal cards which can be played by the player
CardList GameLogic::legalMoves(const CardList& table, const CardList& hand) {
CardList legalMoves; // used to store legal cards
// In the case the table is empty, this means this play has 7 of spades, so he has to be forced to play it
if(table.size() == 0) {
// finds the 7S card, so we only got one instance of it
int index = hand.find(Card(SPADE, SEVEN));
const Card* sevenSpades = hand[index];
legalMoves.add(sevenSpades);
return legalMoves;
}
// loops through hand to determine which ones are legal to play
for (int index = 0; index < hand.size(); index++) {
const Card * card = hand[index];
// Stores the index of lower rank and higher rank card to determine whether it exists or not
int lowerRankIndex = -1;
int higherRankIndex = -1;
// Determines whether a lower rank or higher rank card exists
if (card->getRank() != ACE) {
Card lowerRank = Card(card->getSuit(), (Rank) (card->getRank() - 1));
lowerRankIndex = table.find(lowerRank);
}
if (card->getRank() != KING) {
Card higherRank = Card(card->getSuit(), (Rank)(card->getRank() + 1));
higherRankIndex = table.find(higherRank);
}
// Determines whether the current card is legal to play
if (card->getRank() == SEVEN || lowerRankIndex !=-1 || higherRankIndex != -1) {
legalMoves.add(card);
}
}
return legalMoves;
}
示例2: dealPlayerHand
// returns a vector of 13 cards for a player to use
CardList Deck::dealPlayerHand() {
CardList hand;
// grab next 13 cards and copy them to hand vector
for (int i = 0; i < HAND_SIZE; i++) {
int index = CARD_COUNT - cards_left_ + i;
if (index >= 0) {
hand.add(cards_[index]);
}
}
// mark those 13 cards as used
cards_left_ -= HAND_SIZE;
return hand;
}