Try to complete the puzzle so the numbers are in order 1-8 or the letters A-H with the space in the bottom right. To move a piece. click on any piece near the space to slide it into the space. The arrow in the bottom left corner changes the piece set. The speaker in the bottom right corner mutes or unmutes the volume.
This was a challenge with my friend @_TotallyNotAnApple_ to see who could come up with a project in a 30 minute challenge: https://scratch.mit.edu/projects/877405525 I failed disatrously in the time limit due to messing up the coordinates without proper planning, but in fact the final code is quite neat and not to hard to understand. The main part of the game is in the BoardLogic sprite. The puzzle state is just a single list called puzzle order which represents the 9 squares containing the numbers 1-8 and the letter S for the space. Hence, when the puzzle is solved the puzzle order list has the values in order of "12345678S". The numbers are 8 clones of the glow number sprite with a clone count variable we incremented before each clone to set the costume. So we can use the clone number to know what was clicked on with the sprite clicked event. The original number sprite isn't used, just the clones which makes the handling of them consistent. We need the fixed X and Y coordinates of the 9 squares and we put those in two lists (one for square X and one for square Y positions) so we can anchor where the number sprites start and can move to. This is contained in the BoardLayout sprite. When we click the green button, GameLogic first tells BoardLogic to scramble the puzzle, inside BoardLogic, we simply randomise the first 8 elements of the puzzle state list, ensuring the 9th element is the S. GameLogic then broadcasts the PlacePiece event so that the number sprite clones all move to the correct X and Y position of BoardLayout's lists based on their item number in the now scrambled puzzle order list. Finally, when we click on any number to try and switch squares, we must first check that it's a valid move. We do this by setting the piece clicked variable to the clone count and sending a message to MoveLogic. MoveLogic can tell the "from square" of the piece by it's index in the puzzle order list and also the value of "empty square" which is the index of "S" in the puzzle order list. Both "from square" and "empty square" simply have the values 1-9. The ValidMove method checks that for each value of the empty square which values of from square is OK. That's it ! So using those two things, we may now have a valid move and if so, inside the 9 element puzzle order list, we simply swap the position of the piece we clicked on and the letter S. MoveLogic then broadcasts first the MovePiece event first to the Numbers sprites, waits and then broadcasts the PieceMoved event to the BoardLogic sprite. Handling MovePiece, the Number sprite simply glides the correct clone to the empty square X and Y position. BoardLogic handles the PieceMoved event and converts the new value of the puzzle order list to a string. It can simply detect that the converted string is equal to the value "12345678S" which means the puzzle is solved. If so, we can set the puzzle is solved variable and then the GameLogic sprite ends the main loop and tells the Win sprite to animate the winning graphics.