Logic behind a bejeweled-like game
Posted
by
Joe
on Game Development
See other posts from Game Development
or by Joe
Published on 2011-07-17T05:00:32Z
Indexed on
2012/03/28
11:43 UTC
Read the original article
Hit count: 426
algorithm
|game-mechanics
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?
© Game Development or respective owner