1
I’m trying to make a puzzle in which the image comes scrambled into pieces, and by clicking on two different pieces they change position, if the drawing is correct it goes to the next.
But the problem is when I checked if the puzzle was solved, the solution I tried to implement was to create a list that contained identifiers sprites
in their respective places if the image had already been reassembled listaSolucao
and one with the current positions of the identifiers of sprites
matrizResDesenho
, then when I change two sprites
from place on the list desenho
their respective identifiers also change places on the list matrizResDesenho
at the end if you are correct both lists will be identical and will exit the loop.
At first it works after some changes of sprites
the identifiers begin to swap randomly between themselves or else simply do not change, visually works perfectly, but because of this error the list matrizResDesenho
does not fulfill its function in being compared with the solution, although the drawing is right on the screen.
I wonder where this my mistake in the following code, and if there is another better method to be able to do that I want.
I tried to compare sprites
but always returns false so it is not a viable method.
I thank those who read everything and help me.
while(puzzleAtivo):
deltaClique += deltatime
for x in range(4):
for y in range(4):
if (mouse.is_over_object(desenho[x][y])): # se o mouse estiver em cima da imagem
if (mouse.is_button_pressed(1) and deltaClique > 1): # se o mouse clicar na imagem
deltaClique = 0 # limite de tempo para clicar novamente
if(segurando): # checa se há um sprite sendo "segurado"
atualX, atualY = desenho[x][y].x, desenho[x][y].y #armazena as posicoes atuais do sprite
# inverte as posições dos sprites em si na tela
desenho[x][y].x = desenho[seguradoX][seguradoY].x
desenho[x][y].y = desenho[seguradoX][seguradoY].y
desenho[seguradoX][seguradoY].x = atualX
desenho[seguradoX][seguradoY].y = atualY
auxRes = matrizResDesenho[seguradoX][seguradoY] #armazena o index do identificador do sprite que ja estava sendo "segurado"
# inverte os identificadores do sprite que acaba de ser clicado com o que ja estava sendo "segurado"
matrizResDesenho[seguradoX][seguradoY] = matrizResDesenho[x][y]
matrizResDesenho[x][y] = auxRes
segurando = False
else:
seguradoX , seguradoY = x,y #se ao clicar em uma imagem ainda nao houver sprite sendo segurado armazena o index desta que acaba de ser clicada
segurando = True
if checaSolucao(solucao, matrizResDesenho):
break ```