To know if I win

Hi there!!!
I’m making a simple puzzle. When I click on a piece, it moves to the next empty space. Looks like this:
Sin título-1

Here is a fraction of code where I move a piece (Pieza) to a empty space (Ficha), and I refresh object’s variables values:

It works very well, but I can’t verify when I win… I tried this:

But doesn´t work :frowning:
Any ideas, please?

I can see you’re iterating through all the pieces.

If the variable idPieza of the Pieza object is equal to the the variable idFicha then you add one (+1) to the correctas counter.

But if not, you return the counter to 0.

This means the counter is always returned to 0 if at least one piece is not in his place.

The other possible issue is related to how you’re updating the variables of the pieza objects.

Thx erdo…
I see the bug in the counter…
But, how can I check in real time if all the pieces are placed in the right holders (specially when a piece well placed can be wrong placed in the next move)?
Iteration apart, is there another way?
:frowning:

I would first create some empty (win placed) boxes and assign some var/Id to them like this:
Senzanome
Then i would check for each image id if the center point is the same of the center empty win boxes

Hello.
I think these two videos will help you with your problem. But the videos are in Spanish. You can activate the subtitles.

1 Like

Thx Olivers…
The second video helped me to simplify a lot my code!!!
I finally solved my question using a flag in the piece (not exactly like in the first video, but it lit me XD )
Here’s the code:

Thank you again!!

1 Like