Пример #1
0
// method for making move at Left Mouse Button
void Game::OnLButtonDown(D2D1_POINT_2F ptMouse)
{
	float Start_x = m_pRenderGame->GetStart_x();
	float Start_y = m_pRenderGame->GetStart_y();
	float SquareWidth = m_pRenderGame->GetSquareWidth();
	// compute the corresponding square indices
	if (GetPlayer(m_iTurn) == Human && ptMouse.x > Start_x && ptMouse.y > Start_y)
	{
		int i = int((ptMouse.x - Start_x) / SquareWidth);
		int j = int((ptMouse.y - Start_y) / SquareWidth);
		SMOVE Move = { i,j,m_iTurn };
		if (MakeMove(Move))
		{
			InvalidateRect(m_hwnd, NULL, FALSE);
			m_pRenderGame->OnPaint(this);
			if (CheckEndGame())
			{
				InvalidateRect(m_hwnd, NULL, FALSE);
				m_pRenderGame->OnPaint(this);
				PostMessage(m_hwnd, WM_ENDGAME, 0, 0);
			}
			else if (GetPlayer(m_iTurn) == AI)
				PostMessage(m_hwnd, WM_AIMOVE, 0, 0);
		}
	}
}
Пример #2
0
// method on AI move
void Game::OnAIMove()
{
	if (GetPlayer(m_iTurn) == AI)
	{
		AIMove();
		InvalidateRect(m_hwnd, NULL, FALSE);
		m_pRenderGame->OnPaint(this);
		if (CheckEndGame())
		{
			InvalidateRect(m_hwnd, NULL, FALSE);
			m_pRenderGame->OnPaint(this);
			PostMessage(m_hwnd, WM_ENDGAME, 0, 0);
		}
		else if (GetPlayer(m_iTurn) == AI)
		{
			MSG msg;

			// check for urgent messages during lengthy calculation
			while (m_iMoveCounter > 2 && PeekMessage(&msg, m_hwnd, 0, 0, PM_REMOVE))
			{
//				if(msg.hwnd == m_hwnd)
					DefMDIChildProc(m_hwnd, msg.message, msg.wParam, msg.lParam);
//				else if (msg.hwnd == g_hWndFrame)
//					DefFrameProc(g_hWndFrame, g_hWndMDIClient, msg.message, msg.wParam, msg.lParam);
			}

			PostMessage(m_hwnd, WM_AIMOVE, 0, 0);
		}
	}	
}
Пример #3
0
void GGameScene::Update(float fDeltaTime)
{
	if( CheckEndGame() )
		return;
	
	for ( gtuint i = 0 ; i < MAX_LAYER ; i++)
	{
		mLayers[i]->Update( fDeltaTime );
	}
	if( mpsEnemyCastle )
		mpsEnemyCastle->Update( fDeltaTime );
	if( mpsForcesCastle )
		mpsForcesCastle->Update( fDeltaTime );
	
	for ( gtuint i = 0 ; i < MAX_CTLRMANAGER ; i++)
	{
		for( gtuint j = 0 ; j < MAX_CTLRMANAGER ; j++)
		{
			if( i == j || ( i == USER_CTLRMANAGER && j == FORCES_CTLRMANAGER )
			   || ( j == USER_CTLRMANAGER && i == FORCES_CTLRMANAGER ) )
				continue;
			mpsActorManages[i]->ProcessAttack( mpsActorManages[j] );
			
		}
	}
	for ( gtuint i = 0 ; i < MAX_CTLRMANAGER ; i++)
	{
		mpsActorManages[i]->Update( fDeltaTime );
	}
}
Пример #4
0
// ctor
Game::Game(HWND hwnd, GameMode Mode) : m_hwnd(hwnd), m_Mode(Mode), m_iTurn(WHITE), m_iMoveCounter(0),
			m_iWinner(EMPTY), m_LastMove({0,0,0}), m_WinnerRowFirst({ 0,0,0 }), m_WinnerRowLast({ 0,0,0 })
{
	// intialize empty initial position
	m_GamePosition.assign(EMPTY);
	m_EmptySquareMask.assign(TRUE);

	// check first for fast (hidden) AI game mode
	if (m_Mode == TwoAIsFast)
	{
		m_Players.assign(AI);
		m_AIBrains.push_back(AIBrain());
		m_AIBrains.push_back(AIBrain());

		while (!CheckEndGame())
			AIMove();
		// destroy AI brains
		Destroy();
	}
	else
	{
		// create rendering unit
		m_pRenderGame = new RenderGame(hwnd);
		m_pRenderGame->Create();

		// assign players depending on the mode
		switch (m_Mode)
		{
		case TwoAIs:
			m_Players.assign(AI);
			m_AIBrains.push_back(AIBrain());
			m_AIBrains.push_back(AIBrain());
			break;
		case TwoHumans:
			m_Players.assign(Human);
			break;
		case HumanAI:
			m_Players.at(0) = Human;
			m_Players.at(1) = AI;
			m_AIBrains.push_back(AIBrain());
			break;
		case AIHuman:
			m_Players.at(0) = AI;
			m_Players.at(1) = Human;
			m_AIBrains.push_back(AIBrain());
			break;
		}
		if (GetPlayer(m_iTurn) == AI)
			PostMessage(m_hwnd, WM_AIMOVE, 0, 0);

	} //end if
}