www.pudn.com > Tetris.rar > TBlock.cpp


#include  
 
 
#include "TBlock.h" 
 
 
const TUint16 bl_types[4][BLOCKNUM]= 
//  #       ##      ###     ##     ####     ###      ###     ##     ##      ##      ###       #     # #     ##       # # 
//							 #		          #      #      ##       ##     ##       #      ##      # #       ##    # # 
{ {0x0400, 0x0600, 0x0700, 0x0620, 0x4444, 0x0e20, 0x0740, 0x06c0, 0x0c60, 0x6600, 0xe400, 0x02c0, 0x0550, 0x0c30, 0x05a0}, 
  {0x0400, 0x0440, 0x2220, 0x0260, 0x0f00, 0x0644, 0x4460, 0x08c4, 0x04c8, 0x6600, 0x8c80, 0x0422, 0x0606, 0x2244, 0x4242}, 
  {0x0400, 0x0c00, 0x0700, 0x0460, 0x4444, 0x0470, 0x02e0, 0x06c0, 0x0c60, 0x6600, 0x04e0, 0x0340, 0x0550, 0x0c30, 0x05a0}, 
  {0x0400, 0x4400, 0x2220, 0x0640, 0x0f00, 0x2260, 0x0622, 0x08c4, 0x04c8, 0x6600, 0x2620, 0x4420, 0x0606, 0x2244, 0x4242},	 
}; 
 
 
TBlock TBlock::Block(TUint8 aType) 
{ 
	return TBlock(aType, 0); 
} 
 
TBlock TBlock::RandomBlock(TInt64 &seed, const TUint8 aClassify) 
{ 
	TUint8 type; 
	if(aClassify == 0) 
		// forward 11 
		type = static_cast (Math::Rand(seed) % (BLOCKNUM-4)); 
	else if(aClassify == 1) 
		// all type 
		type = static_cast (Math::Rand(seed) % BLOCKNUM); 
	else 
		// last 11 
		type = static_cast ((Math::Rand(seed) % (BLOCKNUM-4)) + 4); 
 
	return Block(type); 
} 
 
void TBlock::Rotate(TInt8 aDir) 
{ 
	if (aDir > 0) // deasil 
		iRot++; 
	if (aDir < 0) // anticlockwise 
		iRot += 3; 
 
	iRot %= 4; 
} 
 
// get a row of the block 
TUint16 TBlock::RowMask(TInt nr) const 
{ 
	return static_cast ((bl_types[iRot][iType] >> (4*nr)) & 0xf); 
} 
 
 
// Type()   return the block's type 
TUint8 TBlock::Type() const 
{ 
	return static_cast (iType + 1); 
}