void FloodSeedFill(int x, int y, int old_color, int new_color)
{
    if(GetPixelColor(x, y) == old_color)
    {
        SetPixelColor(x, y, new_color);
        for(int i = 0; i < COUNT_OF(direction_8); i++)
        {
            FloodSeedFill(x + direction_8[i].x_offset,
                          y + direction_8[i].y_offset, old_color, new_color);
        }
    }
}
Esempio n. 2
0
void PlayLayer::checkAndRemoveChain()
{
	//log("checkAndRemoveChain");
		SushiSprite *sushi = m_srcSushi;
		if (!sushi)
		{
			return;
		}
		std::list<SushiSprite*> sameList;
		FloodSeedFill(sushi->getRow(),sushi->getCol(),sushi);

		for (int i = 0; i < m_width*m_height; i++)
		{
			if (m_matrix[i]->getIgnoreCheck())
			{
				sameList.push_back(m_matrix[i]);
			}
		}
		m_srcSushi = nullptr;//不然有上个源结点的bug 可以弄个新的功能
		if (sameList.size()>2)
		{

			removeSushi(sameList);
		}
		return;
		/*		// start count chain
		std::list<SushiSprite *> colChainList;
		getColChain(sushi, colChainList);

		std::list<SushiSprite *> rowChainList;
		getRowChain(sushi, rowChainList);

		std::list<SushiSprite *> &longerList = colChainList.size() > rowChainList.size() ? colChainList : rowChainList;
		if (longerList.size() == 3)
		{
			removeSushi(longerList);
			return;
		}
		if (longerList.size() > 3)
		{
			//TODO: make a special sushi can clean a line, and remove others
			removeSushi(longerList);
			return;
		}*/

	
}
Esempio n. 3
0
/*void PlayLayer::checkAndRemoveChain()
{
	//log("checkAndRemoveChain");
	for (int i = 0; i < m_height * m_width; i++) 
	{
		SushiSprite *sushi = m_matrix[i];
		if (!sushi) 
		{
			continue;
		}

		// start count chain
		std::list<SushiSprite *> colChainList;
		getColChain(sushi, colChainList);

		std::list<SushiSprite *> rowChainList;
		getRowChain(sushi, rowChainList);

		std::list<SushiSprite *> &longerList = colChainList.size() > rowChainList.size() ? colChainList : rowChainList;
		if (longerList.size() == 3) 
		{
			removeSushi(longerList);
			return;
		}
		if (longerList.size() > 3) 
		{
			//TODO: make a special sushi can clean a line, and remove others
			removeSushi(longerList);
			return;
		}
	}
}*/
void PlayLayer::FloodSeedFill(int x, int y, SushiSprite* sushi)
{
	if (x >= 0 && x < m_height && y >= 0 && y < m_width)
	{
		SushiSprite *neighborSushi = m_matrix[x * m_width + y];
		if (neighborSushi->getImgIndex() == sushi->getImgIndex())
		{
			if (neighborSushi->getIgnoreCheck())return;
			for (int i = 0; i < 4; i++)
			{
				neighborSushi->setIgnoreCheck(true);
				FloodSeedFill(x + direction_4[i].x_offset, y + direction_4[i].y_offset, sushi);
			}
		}
	}

}