c# - Modifying flood fill algorithm for specific task -


i trying make tile based game tiles filled random colors , if user clicks on tile disappears. have accomplished.

enter image description here

now, want tile disappears if 2 or more adjacent tiles have same color. have used flood fill algorithm destroy tiles. how modify code works if count value greater 2.

this code destroys tile :

 private void destroy(int x,int y,int old_value,int new_value)     {         if (gamearr[x,y].blockvalue == old_value)         {             //if count > 2             gamearr[x, y].blockvalue = 0;              destroy(x + 1, y, old_value, new_value);             destroy(x - 1, y, old_value, new_value);             destroy(x, y + 1, old_value, new_value);             destroy(x, y - 1, old_value, new_value);          }     } 

how count value?

  • if pass count variable in method , check if value exceeds 2 , destroy, won't destroy first 2 tiles.
  • if make method check if tiles destroyable, set blockvalues 0 while counting.

how go doing this. appreciated.

well found answer.

the count value checked before call destroy method

if (gamearr[i - 1, j].blockvalue == old_value) count++;        if (gamearr[i, j - 1].blockvalue == old_value) count++;        if (gamearr[i + 1, j].blockvalue == old_value) count++;        if (gamearr[i, j + 1].blockvalue == old_value) count++;         if(count>2)             destroy(i, j,gamearr[i,j].blockvalue,0); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -