// cppHearts, Copyright 2001 Michael W. Godfrey, email: migod@uwaterloo.ca // See copyright.txt for details. #include "Player.h" #include "Globals.h" #include Player::Player (string newName) : name(newName), numOfSuit(Card::numSuits), playerToMyLeft(NULL), points(0), iHaveTwoOfClubs(false) { hand = new CardPile; tricks = new CardPile; } Player::~Player (){ // return storage here delete hand; delete tricks; } // Return my name. string Player::getName() const { return name; } // Set who the player to my left is. Can't do this in the constructor // as the list is circular. // ***** NUKE FOR STUDENT VERSION **** void Player::setPlayerToMyLeft (Player *who) { playerToMyLeft = who; } // Return a reference to the player to my left. Player* Player::getPlayerToMyLeft () const { return playerToMyLeft; } bool Player::hasTwoOfClubs() const { return iHaveTwoOfClubs; } // Return the number of points I have. int Player::getPoints () const { return points; } // The round is over. Nuke what's appropriate and reset. void Player::resetHand () { hand->clear(); tricks->clear(); for (int i=0; iprint(); } // I've just been dealt this card; add it to my hand. // Might want to "precompute" some stuff here too ... // [Do I now have the two of clubs? How many of this suit do I have // now?] // ***** NUKE FOR STUDENT VERSION **** void Player::addCard (Card* card) { hand->add (card); if (card->getSuit() == Card::Clubs && card->getRank() == Card::Two) { iHaveTwoOfClubs = true; } numOfSuit [card->getSuit()] += 1; } // Lump this trick in with the other cards I've "won" this round. void Player::addTrick (CardPile* trick) { cout << " " << name << " won the trick and added the following cards:" << endl; trick-> print(); tricks-> add (trick); } // Count up how many points I've earned in my tricks this round and add // it to my running total. void Player::countAndAddPoints () { int numPointsThisRound = 0; for (CardPile::const_iterator viter=tricks->begin(); viter!=tricks->end(); viter++){ numPointsThisRound += (*viter)->heartsValue(); } points += numPointsThisRound; }