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


C++ CardList::add方法代码示例

本文整理汇总了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;
}
开发者ID:manodasanW,项目名称:straights,代码行数:40,代码来源:Role.cpp

示例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;
}
开发者ID:manodasanW,项目名称:straights,代码行数:17,代码来源:Deck.cpp


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