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

📄 cgamemanager.cpp

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


extern CGameState		theGameState;
extern CBlockFollowing	theBlockFollowing;
extern CBlockPool		theBlockPool;
extern CBlockFactory	theBlockFactory;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGameManager::CGameManager()
{

}

CGameManager::~CGameManager()
{

}

//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
bool CGameManager::Init()
{
	bool re = true;
	re &= theGameState.Init();
	re &= theBlockFactory.Init();
	re &= theBlockFollowing.Init();
	re &= theBlockPool.Init( theGameState.GetHalfRow() * 2,
							 theGameState.GetHalfCol() * 2 );
	iTickReadyDrop		= 0;
	iTickBlockDrop		= 0;
	iTickCheckFullLine	= 0;
	iTickAdjustPool		= 0;

	iInterval_ReadyDrop		= 200;
	iInterval_BlockDrop		= 500;
	iInterval_CheckFullLine	= 300;
	iInterval_AdjustPool	= 300;
	return re;
}

//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void CGameManager::Free()
{
	theGameState.Free();
	theBlockFactory.Free();
	theBlockFollowing.Free();
	theBlockPool.Free();
}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
bool CGameManager::ReStart()
{
	Free();
	if ( Init() == false )
	{
		theGameState.SetGameState( GAME_OVER );
		return false;
	}

	return true;
}


//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
bool CGameManager::UpdateTime( int &iLastTick, int iInterval )
{
	int iThisTick = timeGetTime();
	if ( iThisTick - iLastTick >= iInterval )
	{
		iLastTick = iThisTick;
		return true;
	}

	return false;
}

//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void CGameManager::OnGameRun()
{
	GAMESTATE state = theGameState.GetGameState();
	if ( (int)state > 3 )
		return;

	if ( UpdateTime( iTickArray[state], iIntervalArray[state] ) == false )
		return;

	int i;
	switch ( state )
	{

	case READY_DROP:

		if ( theBlockPool.IsPoolFull() )
			theGameState.SetGameState( GAME_OVER );
		else
			theBlockFactory.CreateBlockFollowing();
		break;

	case BLOCK_DROP:

		theBlockFollowing.Drop();
		break;

	case CHECK_FULL_LINE:

		theBlockPool.CheckFullLine();

		i = theGameState.GetScore() / 100;
		iInterval_BlockDrop -= i;
		if ( iInterval_BlockDrop < 200 )
			iInterval_BlockDrop = 400;

		break;

	case ADJUST_POOL:

		theBlockPool.AdjustPool();
		break;
	}
}

⌨️ 快捷键说明

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