// game_cards.cpp // #include "precompiled.h" #pragma hdrstop #include "prey_local.h" static char cardnames[] = { '2','3','4','5','6','7','8','9','T','J','Q','K','A' }; static char suitnames[] = { 'D','H','S','C' }; //============================================================== // hhCard utility class //============================================================== hhCard::hhCard() { suit = SUIT_SPADES; value = CARD_ACE; } hhCard::hhCard(int value, int suit) { this->suit = suit; this->value = value; } int hhCard::operator==(const hhCard &other) const { return value==other.Value() && suit==other.Suit(); } int hhCard::Value() const { return value; } int hhCard::Suit() const { return suit; } char hhCard::ValueName() { return cardnames[value]; } char hhCard::SuitName() { return suitnames[suit]; } //============================================================== // hhDeck utility class //============================================================== CLASS_DECLARATION(idClass, hhDeck) END_CLASS hhDeck::hhDeck() { Generate(); Shuffle(); } void hhDeck::Save(idSaveGame *savefile) const { int i; savefile->WriteInt( cards.Num() ); // hhStack for (i=0; iWrite(&cards[i], sizeof(hhCard)); } } void hhDeck::Restore( idRestoreGame *savefile ) { int i, num; hhCard card; cards.Clear(); // hhStack savefile->ReadInt( num ); cards.SetNum( num ); for (i=0; iRead(&card, sizeof(hhCard)); cards[i] = card; } } void hhDeck::Generate() { int value, suit; cards.Clear(); for (value=0; value