How to make a match three game like Puzzle Bobble.

I can figure out all the mechanics of the game but the problem is that how can I check if there are three same-colored balls are adjacent to each other. I’ve thought all the ways but couldn’t get a reasonable solution. Can someone solve me this problem?

I did this about 5 years ago in GameMaker, so my memory is rusty, and my approach may not have been the best. There’s probably a lot more efficient ways of doing this. So this is just one answer. Sorry, my answer will be a bit abstract here…

What I did was had set up basically a matrix indicating all the positions on my “game board” (For lack of better description), and then populated them with the instance in each. Then I just iterated through them one row at a time (two loops, loop through each row, and within loop through each column), checking the neighbors of the block I was processing. **(edit: as mentioned in my followup post, you actually don’t have to look left or up) Look to the left and right in your array/matrix for a horizontal match-3, just checking if the color of the neighbor is the same. Check the left to see if neighbor matches… if it does, then you add your object to some sort of collection of objects to destroy (which you may not do), and add 1 to some counter saying how many matches you have, and keep checking to the right. Then once you’re doing looking to the left, look to the right, doing the same thing. If you have 3 matches, you can destroy horizontally, if you don’t, you just clear out your objects from that temporary list of things to destroy.

Then, do the same thing vertically, look above, look below.

Like I said, the way I did it was probably horribly inefficient, but it worked for me, and the game actually ran quickly, even in GameMaker. Although rather than destroying, i’d probably using pooling with these blocks (activate/deactivate them).

Anyways, again, one approach, likely not the best, but it works. I’d say this is probably the brute-force, easy to understand, cave man approach, but again it works. lol!

I will also say that there are a tonne of match-3 games out there. As such, I think there’s several tutorials out there too. Have you tried looking for any?

Edit: Oh, and thinking back on it, I’m pretty sure you only have to check to the right and down, because your left/up will be covered already by a previous iteration through the check (looking at previous blocks)…if you get what I mean.

There’s like a million tutorials out there…
Unity specific one (uses Raycasts):

Generally after a swap, you search horizontal and vertically at the swap location until you hit a non-match or you match-3 (img src: https://www.raywenderlich.com/66877/how-to-make-a-game-like-candy-crush-part-1)

Idea I came up last night was to check if the object next to another object is of same color. If so, then add it in a list. After that check the list if is larger than three. If so then destroy each Gameobject in it and also empty the list.
How is this idea?

Try it :slight_smile: It really depends on how you’re doing this list. If you initialize / repopulate the list for each square on your game board as you process row by row / col by col, then that would work for sure. If you have one list for the whole game board, then I guess it depends on how you handle things, because what happens if you have two objects matching in one spot, but two somewhere else? If whatever you’re doing makes sense in your head, give it a try!

Every GameObject will have a script and in that script, a list will store that gameobject and its adjacent GameObjects of the same type. Then if List.Count equals or greater than three, each gameobject will be destroyed or disabled (if I pooled).

Sounds like that should work, I think. If I’m not mistaken, that will handle situations where you have a match-3, but if there’s 4, that 4th might get “orphaned”, so to speak, as objects further down the chain might not realize there was a 3+ match since those objects are gone now… unless of course you ensure that your destroy part doesn’t happen until after the whole game board has built its lists (I could be wrong on that, but this is how it seems, in my head). And then in which case, of course, only destroy the objects if they exist (since each game object will appear in multiple lists).

I’m sure you’ve thought this out well enough anyways and probably come with your own solution to that potential problem… just saying this to ensure you’ve considered that.

There’s obviously more than one way of doing this, but I know when I did my match-3 game, I had sort of a state-machine concept. There was a state for finding matches, a state for destroying stuff, and a state for things moving into the gaps afterwards, and the player couldn’t do anything when these states were happening and these states didn’t act while another was happening, as well. So keep in mind how you’ll handle that when building this too.

I did pretty much a complete Match-3 game from scratch, just was lacking enough polish, and I got bored. So I had some sort of answer for pretty much every concept needed, although not necessarily the best answer… although again… more than one way of doing things. There’s a lot of info out there already too.