Beispiel #1
0
/* returns -1 when card cannot be purchased, number of coins remaining after
 * purchase if buys remain, or zero otherwise.
 */
int Player::buyCard(Card card) {
    // try to buy card
    if (card.getCost() < coins && buys > 0) {
        coins -= card.getCost();
        buys--;
        discard_pile.push_back(card);
    }
    else {
        cout << "Player could not afford card: " << card;
        return -1;
    }
    if (buys > 0) {
        return coins;
    } else {
        return 0;
    }
}