www.pudn.com > TetrisWang.zip > Teris.cpp


// Teris.cpp: implementation of the CTetris class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Tetris.h" 
#include "Teris.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
char CTetris::BLOCK_TYPE[MAX_TETRIS_TYPE][17] =  
						{" *  "				// basic block count: 7 
                         " *  " 
                         " *  " 
                         " *  ", 
                         " ** " 
                         " *  " 
                         " *  " 
                         "    ", 
                         "**  " 
                         " *  " 
                         " *  " 
                         "    ", 
                         " *  " 
                         "*** " 
                         "    " 
                         "    ", 
                         "**  " 
                         " ** " 
                         "    " 
                         "    ", 
                         " ** " 
                         "**  " 
                         "    " 
                         "    ", 
                         "**  " 
                         "**  " 
                         "    " 
                         "    ", 
                         " *  "					// extend block count: 11 
                         "*** " 
                         " *  " 
                         "    ", 
                         "* * " 
                         "*** " 
                         "    " 
                         "    ", 
                         " ** " 
                         " *  " 
                         "**  " 
                         "    ", 
                         "**  " 
                         " *  " 
                         " ** " 
                         "    ", 
                         " *  " 
                         " ** " 
                         "**  " 
                         "    ", 
                         " *  " 
                         "**  " 
                         " ** " 
                         "    ", 
                         " *  " 
                         " ** " 
                         " *  " 
                         " *  ", 
                         " *  " 
                         " *  " 
                         " ** " 
                         " *  ", 
                         " *  " 
                         " *  " 
                         " *  " 
                         " ** ", 
                         " *  " 
                         " *  " 
                         " *  " 
                         "**  ", 
                         " *  " 
                         " *  " 
                         "*** " 
                         "    ", 
                         "*   "					// easy bolck count: 4 
                         "    " 
                         "    " 
                         "    ", 
                         " *  " 
                         " *  " 
                         "    " 
                         "    ", 
						 "**  " 
                         " *  " 
                         "    " 
                         "    ", 
                         " *  " 
                         " *  " 
                         " *  " 
                         "    "}; 
 
COLORREF CTetris::COLOR_TYPE[MAX_COLORS] =  
		{RGB(51, 204, 102),			// ÂÌ	Default color, or extend block color 
		 RGB(233, 121, 118),		// שºì 
		 RGB(200, 200, 102),		// Ȯ 
		 RGB(0, 143, 224),			// ˦ 
		 RGB(153, 153, 204),		// Çà 
		 RGB(204, 204, 204),		// »Ò 
		 RGB(232, 123,  20),		// ³È 
		 RGB(235,  88, 235),		// ·Û 
		 RGB(220,  39,  75), 		// ºì	sample block color 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102),			// ÂÌ 
		 RGB(51, 204, 102)};		// ÂÌ 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CTetris::CTetris() 
{ 
 
} 
 
CTetris::CTetris(CTetris &t) 
{ 
	m_Blocks.RemoveAll(); 
	for (int i=0; im_Blocks[i].GetXPos() ? size : m_Blocks[i].GetXPos(); 
		size = size>m_Blocks[i].GetYPos() ? size : m_Blocks[i].GetYPos(); 
	} 
	m_nSize = size; 
} 
 
void CTetris::Roate(void) 
{ 
	if (m_nSize == 0) return; 
	for (int i=0; inMaxX) nMaxX = m_Blocks[nIndex].GetXPos(); 
			if (m_Blocks[nIndex].GetYPos()>nMaxY) nMaxY = m_Blocks[nIndex].GetYPos(); 
		} 
		ptStart = pt + CSize((3-nMaxX)*nSize/2, (3-nMaxY)*nSize/2); 
	} 
	for (int i=0; i=0; i--) 
	{ 
		int x = m_Blocks[i].GetXPos(); 
		int y = m_Blocks[i].GetYPos(); 
		if (y == 0) 
		{ 
			m_Blocks.RemoveAt(i); 
		} 
		else 
		{ 
			m_Blocks[i].SetXPos(x); 
			m_Blocks[i].SetYPos(y-1); 
		} 
	} 
}