Example #1
0
void Grid::SelectCheker(Checker::CheckerColor clr)
{
	Checker* checker;
	for(int i = 0; i < _cells.size(); i++)
	{
		if(checker = GetChecker(_cells[i]))
		{
			if(checker->GetColor()==clr)
			{
				checker->GetCell()->AddComponent(new CheckerFlushCellComponent);
			}
			else if(checker->GetColor()!=clr)
			{
				checker->GetCell()->EraseComponent(new CheckerFlushCellComponent);
			}
		}
		else _cells[i]->EraseComponent(new CheckerFlushCellComponent);
	}
}
Example #2
0
bool Grid::UpdateCell(GameCell* cell, Checker::CheckerColor clr)
{

	for(int i = 0; i < _specCells.size(); i++)
	{
	if(_specCells[i].first)
	  {
		if(cell&&_specCells[i].first->Equals(cell))
		{
			if(_selectedChecker)
			{
				
			   bool val = _selectedChecker->CreateMove(_specCells[i].second)._sucsessful;
			   _selectedChecker = nullptr;
			  for(int i = 0; i < _specCells.size(); i++)
			  {
				  if(_specCells[i].first)
				  {
				    if(GetChecker(_specCells[i].first))
			        {
					   // _specCells[i].first->EraseComponent(new CheckerFlushCellComponent);
				    }
				     else   _specCells[i].first->EraseComponent(new MoveCellComponent); 
				    }
			  }
			  _specCells.clear();
			  return val;
			}
		}
	  }
	}

	Checker* checker;

	if((checker = GetChecker(cell)))
	{
		if(checker->GetColor()==clr)
		{
			for(int i = 0; i < _specCells.size(); i++)
			{
				if(_specCells[i].first) 
				{
					_specCells[i].first->EraseComponent(new MoveCellComponent);
					Checker* hasChecker;
					if((hasChecker = GetChecker(_specCells[i].first))&&hasChecker->GetColor()==clr)
						_specCells[i].first->AddComponent(new CheckerFlushCellComponent);
				}
			}
		  _specCells.clear();
		  _specCells = checker->GetSteps();
		  for(int i = 0; i < _specCells.size(); i++)
		  {
			  if(_specCells[i].first)
				 if(!GetChecker(_specCells[i].first)) _specCells[i].first->AddComponent(new MoveCellComponent);
		  }
		  _selectedChecker = checker;
		}
	}

	return false;

}