Example #1
0
bool ScoreManager::SetOccupied(SmartPtr<Square> square)
{
	int coll = square->GetColl();
	int row = square->GetRow();

	if(row < 0 || row >= m_blockGrid.size())
	{ return false; }
	if(coll < 0 || coll >= m_blockGrid[0].size())
	{ return false; }

	m_blockGrid[row][coll] = square; 
	
	if(row == 0)
	{ m_gameOver = true; }

	return true;
}
Example #2
0
void ScoreManager::RepositionSquares(int bottomRow, int rowCount)
{
	for(int y = bottomRow; y > -1; y--)
	{
		for(unsigned int x = 0; x < m_blockGrid[0].size(); x++)
		{
			SmartPtr<Square> square = m_blockGrid[y][x];
			if(square == NULL)
			{ continue; }

			bool foundCollision = false;
			int coll = square->GetColl();
			int row = square->GetRow();
			int newY = row;

			while(!foundCollision)
			{
				if(newY == Settings::NoOfRows || (IsOccupied(coll, newY) && newY != row) || (newY - row) == rowCount + 1)
				{ 
					foundCollision = true;
					newY--;
					break;
				}

				newY++;
			}

			if(newY != row)
			{
				square->SetPosition(coll, newY);
				m_blockGrid[y][x] = NULL;
				m_blockGrid[newY][x] = square;
			}
		}
	}
}