www.pudn.com > goodchessGame.zip > Deck.cpp


#include "StdAfx.h" 
#include "Deck.h" 
#include "FiveInOne.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
 
CDeck::CDeck() 
{ 
} 
 
CDeck::~CDeck() 
{ 
	POSITION pos = m_CardList.GetHeadPosition(); 
	 
	while (pos != NULL) 
	{ 
		CCard* pCard = m_CardList.GetNext(pos); 
		pCard->DestroyWindow(); 
		delete pCard; 
	} 
	m_CardList.RemoveAll(); 
} 
 
IMPLEMENT_DYNCREATE(CDeck, CBitmapButton) 
 
BEGIN_MESSAGE_MAP(CDeck, CBitmapButton) 
END_MESSAGE_MAP() 
 
 
BOOL CDeck::DrawCard(CPlayer *pPlayer, BOOL bVisible) 
{ 
	if(!m_CardList.IsEmpty()) 
	{ 
		CCard *pCard = m_CardList.RemoveTail(); 
		if(bVisible) 
			pCard->ShowWindow(SW_SHOW); 
		pPlayer->m_CardArray.Add(pCard); 
		return TRUE; 
	} 
	else 
		return FALSE; 
} 
 
void CDeck::InitializationAndDrawing(CWnd *pParentWnd, int nNumOfDecks, int *TotalCards) 
{ 
	CCard *pCard; 
	CPoint Point(-200,-200); 
	 
	POSITION pos = m_CardList.GetHeadPosition(); 
	 
	while (pos != NULL) 
	{ 
		CCard* pCard = m_CardList.GetNext(pos); 
		pCard->DestroyWindow(); 
		delete pCard; 
	} 
	m_CardList.RemoveAll(); 
 
	for(int i = 0; i <= ((52*nNumOfDecks)-1); i++) 
	{ 
		pCard = new CCard; 
		pCard->SetStartingPoint(Point); 
		pCard->SetBitmapIndex(*TotalCards); 
		pCard->Creation(pParentWnd, pCard->GetBitmapIndex(), FALSE); 
		m_CardList.AddHead(pCard); 
		TotalCards++; 
	} 
 
 
	DestroyWindow(); 
    CBitmapButton::Create(NULL, WS_VISIBLE | WS_CHILD | WS_DISABLED | BS_PUSHBUTTON | BS_OWNERDRAW, CRect(0, 0, 71, 96), pParentWnd, 0); 
	LoadBitmaps(FIVEINONE_APP->m_ImageDialog.m_DeckID); 
	CenterWindow(); 
}