Hi,
I’m trying to make a game similar to the likes of Puyo Puyo, where the player controls falling puzzle pieces of different colours and has to put them in groups of 4. I’ve managed to get most of the game working so far, but I’m struggling with searching to board to find matches.
At the minute each individual puzzle block has 4 colliders on each side to see if theirs a match to the immediate side of it, and if their is, it puts it in a list on that gameobject. My basic idea was that the script attached to the board would look at all the puzzle pieces (stored in a list on that script) and would look at that puzzle piece’s match list and add the length of that list to a int. It would then look at the lists of the puzzle pieces in the first puzzle piece’s match list and add that to the int, and would keep doing that until all the puzzle pieces in that group are accounted for. If their is more than 4 pieces in that group, they would all be destroyed.
My problem is that I can’t formulate that idea into a piece of code that works. It either doesn’t work at all, or works in a way it’s not supposed to. Below is my 3rd or 4th re-write of this code which, whilst doesn’t pull up any errors, doesn’t seem to do anything. I was wondering if someone could point me in the right direction or tell me a better way of doing this.
public void NextMove()
{
// check matches
foreach (PuyoPuyo puyo in puyosOnBoard)
{
CheckPuyo(puyo);
}
//check rubbish
next.AddPuyo();
}
void CheckPuyo(PuyoPuyo puyo)
{
int matchNumb = 0;
if(puyo.matchedPuyos != null)
{
matchNumb += puyo.matchedPuyos.Count;
if (puyo.matchedPuyos != null)
{
foreach (PuyoPuyo p in puyo.matchedPuyos)
{
Debug.Log("2.2");
if (p.matchedPuyos.Count > 0)
{
Debug.Log("3");
CheckPuyo2(p, matchNumb, puyo);
}
}
}
}
}
void CheckPuyo2(PuyoPuyo puyo, int matchNumb, PuyoPuyo originalPuyo)
{
matchNumb += puyo.matchedPuyos.Count - 1;
foreach (PuyoPuyo p in puyo.matchedPuyos)
{
if (p.matchedPuyos.Count > 1)
{
CheckPuyo2(p, matchNumb, originalPuyo);
}
else
{
if(matchNumb >= 4)
{
Destroy(originalPuyo.gameObject);
}
}
}
}
Thanks