?? cgamemanager.cpp
字號(hào):
#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;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -