www.pudn.com > 黑客帝国屏保.zip > MatrixColumn.cpp


// MatrixColumn.cpp: implementation of the CMatrixColumn class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "MatrixColumn.h" 
#include "Matrix.h" 
#include "MatrixString.h" 
#include "constants.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CMatrixColumn::CMatrixColumn(int y) 
{ 
	int nStrs = rand() % STR_PERCOL; 
	if (nStrs < STR_PERCOL_MIN)  
		nStrs = STR_PERCOL_MIN; 
	int n; 
	CMatrixString *pStr; 
 
	for (n = 0; n < nStrs; n++) { 
		pStr = new CMatrixString; 
		m_aArray.Add(pStr); 
	} 
	m_y = y; 
 
} 
 
CMatrixColumn::~CMatrixColumn() 
{ 
	int n; 
	CMatrixString *pStr; 
 
	for (n = 0; n < m_aArray.GetSize(); n++) { 
		pStr = (CMatrixString*)m_aArray[n]; 
		delete pStr; 
	} 
} 
 
void CMatrixColumn::Fall(CDC *pDC) 
{ 
 
	CRect rect; 
	rect = theMatrix.GetBorder(); 
 
	CMatrixString *pStr = (CMatrixString*)m_aArray[0]; 
	 
	int nLen2 = pStr->GetLength(pDC); 
	int nSep = nLen2 / pStr->GetString().GetLength(); 
 
	m_y += nSep * 2; 
	if (m_y - nLen2 > rect.bottom) { 
 
		delete pStr; 
		m_aArray.RemoveAt(0); 
		pStr = new CMatrixString; 
		m_aArray.Add(pStr); 
		pStr = (CMatrixString*)m_aArray[0]; 
		m_y -= nLen2; 
	}  
 
} 
 
int CMatrixColumn::GetPos() 
{ 
	return m_y; 
} 
 
CPtrArray* CMatrixColumn::GetArray() 
{ 
	return &m_aArray; 
}