Logic behind a bejeweled-like game
- by Joe
In a prototype I am doing, there is a minigame similar to bejeweled. Using a grid that is a 2d array (int[,]) how can I go about know when the user formed a match? I only care about horizontally and vertically.
Off the top of my head I was thinking I would just look each direction. Something like:
int item = grid[x,y];
if(grid[x-1,y]==item)
{
int step=x;
int matches =2;
while(grid[step-1,y]==item)
{
step++;
matches++
}
if(matches>2)
//remove all matching items
}
else if(grid[x+1,y]==item
//....
else if(grid[x,y-1==item)
//...
else if(grid[x,y+1]==item)
//...
It seems like there should be a better way. Is there?