// Check horizontals
for (int y = 0; y < sGridHeight; y++)
{
Shape* groupShape = nullptr;
int groupSize = 0;
for (int x = 0; x < sGridWidth; x++)
{
GridItem* gridItem = GetItem(x, y);
Shape* shape = gridItem->GetShape();
if (shape == groupShape)
{
groupSize++;
if (groupSize == m_MatchSize)
{
g_Audio->PlaySound(m_GemDestroyedSound.c_str());
m_Score += shape->GetScore();
for (int tx = x - m_MatchSize + 1; tx <= x; tx++)
{
RANDOMIZE(GetItem(tx, y))
}
return;
}
}
else
{
groupSize = 1;
groupShape = shape;
}
}
}
// Check verticals
for (int x = 0; x < sGridWidth; x++)
{
Shape* groupShape = nullptr;
int groupSize = 0;
for (int y = 0; y < sGridHeight; y++)
{
GridItem* gridItem = GetItem(x, y);
Shape* shape = gridItem->GetShape();
if (shape == groupShape)
{
groupSize++;
if (groupSize == m_MatchSize)
{
g_Audio->PlaySound(m_GemDestroyedSound.c_str());
m_Score += shape->GetScore();
for (int ty = y - m_MatchSize + 1; ty <= y; ty++)
{
RANDOMIZE(GetItem(x, ty))
}
return;
}
}
else
{
groupSize = 1;
groupShape = shape;
}
}
}
Is there an easy way to clean this up? It seems like a lot of code duplication.
I have no qualms about using #define
s, and I cannot use C++11.
nullptr
is in C++11. \$\endgroup\$