< Previous | Contents | Next >

The House Class

The House class represents the house. Its derived from GenericPlayer.

class House : public GenericPlayer

{

public:

House(const string& name = "House"); virtual ~House();

//indicates whether house is hitting - will always hit on 16 or less virtual bool IsHitting() const;


//flips over first card void FlipFirstCard();

};

370 Chapter 10 n Inheritance and Polymorphism: Blackjack


House::House(const string& name): GenericPlayer(name)

{}


House::~House()

{}


bool House::IsHitting() const

{

return (GetTotal() <= 16);

}


void House::FlipFirstCard()

{

if (!(m_Cards.empty()))

{

m_Cards[0]->Flip();

}

else

{

cout << "No card to flip!\n";

}

}

The class implements the IsHitting() member function that it inherits from GenericPlayer. Therefore, House isnt abstract. The class implements the member function by calling GetTotal(). If the returned total value is less than or equal to 16, the member function returns true, indicating that the house is still hitting. Otherwise, it returns false, indicating that the house is no longer hitting.

FlipFirstCard() flips the houses first card. This member function is necessary because the house hides its first card at the beginning of the round and then reveals it after all of the players have taken all of their additional cards.