⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cblockfactory.cpp

📁 俄罗斯方块3D 程序+源码俄罗斯方块3D(程序+源码
💻 CPP
字号:
#include "CBlockFactory.h"
#include "CGameState.h"
#include "CBlockFollowing.h"
#include <windows.h>

extern CBlockFollowing	theBlockFollowing;
extern CGameState		theGameState;


//方块的各种形状:
POSITION CBlockFactory::s_BlockFactory[10][8] = {
	{ { 2, 2 }, { 2, 1 }, { 1, 1 }, { 1, 2 } },
	{ { 2, 2 } },
	{ { 2, 2 }, { 2, 1 }, { 2, 3 }, { 1, 2 } },
	{ { 2, 2 }, { 2, 1 }, { 2, 0 }, { 1, 2 } },
	{ { 2, 0 }, { 2, 1 }, { 2, 2 }, { 1, 0 } },
	{ { 2, 2 }, { 2, 1 }, { 1, 3 }, { 1, 2 } },
	{ { 2, 1 }, { 2, 2 }, { 1, 1 }, { 1, 0 } },
	{ { 2, 3 }, { 2, 2 }, { 2, 0 }, { 2, 1 } },
	{ { 2, 2 }, { 2, 1 } },
	{ { 2, 2 }, { 2, 1 }, { 1, 2 } },
};
	
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBlockFactory::CBlockFactory()
{
}

CBlockFactory::~CBlockFactory()
{

}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
bool CBlockFactory::Init()
{
	return true;
}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void CBlockFactory::Free()
{

}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void CBlockFactory::CreateBlockFollowing()
{
	srand( timeGetTime() );
	int iShape = rand() % 10;					//随机生成形状

	int iColor;
	int row, col;
	CBlock block;

	theBlockFollowing.OnCreateBlock();

	row = s_BlockFactory[iShape][0].row;
	col = s_BlockFactory[iShape][0].col;

	row = (row - 3) + theGameState.GetHalfRow() * 2;
	col = (col - 2) + theGameState.GetHalfCol();
	theBlockFollowing.SetPos( row, col );


	iColor = ( rand() % 6 ) + 1;						//随机生成颜色

	for ( int i = 0; i < 8; ++i )
	{
		row = s_BlockFactory[iShape][i].row;
		col = s_BlockFactory[iShape][i].col;

		if ( row == 0 && col == 0 )
			break;


		row = (row - 3) + theGameState.GetHalfRow() * 2;
		col = (col - 2) + theGameState.GetHalfCol();

		block.SetCol( col );
		block.SetRow( row );
		block.SetMaterialIndex( iColor );
	
		theBlockFollowing.AddBlocks( block );
	}

	theGameState.SetGameState( BLOCK_DROP );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -