if slideTo: slideAnimation(mainBoard, slideTo, 'Click tile or press arrow keys to slide.', 8) # show slide on screen makeMove(mainBoard, slideTo) allMoves.append(slideTo) # record the slide pygame.display.update() FPSCLOCK.tick(FPS)
Now that the events have all been handled, we should update the variables of the game state and display the new state on the screen. If
slideTo has been set (either by the mouse event or keyboard event handling code) then we can call
slideAnimation() to perform the sliding animation. The parameters are the board data structure, the direction of the slide, a message to display while sliding the tile, and the speed of the sliding.
After it returns, we need to update the actual board data structure (which is done by the
makeMove() function) and then add the slide to the
allMoves list of all the slides made so far. This is done so that if the player clicks on the "Reset" button, we know how to undo all the player’s slides.