Esempio n. 1
0
//bool flag = false; // this flag is used to indicate whether the first card has face down for house
 // this flag has to be global variable. If it is local, it will flip every cards of house to face down.
 // why this flag does not reset back to false when a new Deck is generated ? The life time of global variable is the whole program starting and ending.
void Deck::Deal(Hand& aHand)
{   
    // how to know whether aHand is house or player ? after the below test : dynamic_cast<Type >  works.
    //Hand * anoHand = &aHand;
    /*
    Player* player = dynamic_cast<Player*> (anoHand);
    if (player != NULL) {
         //  just do something for testing
         player-> Win();
         std::cout << "I am a player \n";
    }
    House* house = dynamic_cast<House*>(anoHand);
    if (house != NULL) {
         std::cout <<"house is hitting or not : " << house ->IsHitting() << "\n";
    }
   */
    //int num = aHand.m_Cards.size();  // compilation error: Hand::m_Cards is protected 
    
    if (m_Cards.size() > 0 ) {
        
         //House * house2 = dynamic_cast<House*> (anoHand);
        
         //if (house2 != NULL && flag == false) {
              //  m_Cards.back()-> Flip(); 
               // flag = true;      
                
         // }
          aHand.Add(m_Cards.back());  // we could not write "aHand.Add(m_Cards.end());" // because m_Cards.end() return an interator, not an   element or element reference
          m_Cards.pop_back();
         //std::cout << "newly added in hand: " << *(aHand.m_Cards[num-1]) <<std::endl; //  compilation error: Hand::m_Cards is protected 
    }
    else {
          std::cout<< "Out of cards. Unable to deal" << std::endl;
    }
}
void Deck::Deal(Hand& aHand)
{
  if (!m_Cards.empty())
  {
    aHand.Add(m_Cards.back());
    m_Cards.pop_back();
  }

  else
  {
    cout << "Out of cards, Unable to deal.\n";
  }
}