Extra credit assignments
The app now looks good and works as expected, but there are several things you can do to make it even better.
First, you could make tiltTriggerDegrees depend on puzzle board size. Current fixed value is acceptable for a 4x4 board setup, because the biggest tilt you need to make to move a tile is 62.5°. By enlarging the board to just 5x5, the required tilt for the last tile in a row or a column becomes 104°! At this point the game is not comfortable to play anymore.
Second, you could use the swapHistory property to quite easily add "Undo" functionality. All you'd need to do is figure out how to make movements opposite of what's in swapHistory. An even cooler use of swapHistory would be a "Replay" functionality, where you could replicate the user's entire game upon successfully solving the puzzle (maybe with some fancy animations?).
Thirdly, if you're planning to use swapHistory, you will also need to make sure that you clear the history if the "Shuffle" button is pressed. Right now you're saving history for all the games played until the app is killed, which is not a problem in itself (it could even turn into a feature), until you start using swapHistory for different purposes.
And finally, you can make tilting animations for each subsequent tile in a row or a column feel more natural by including the new, higher tilt requirements while calculating xTilt and yTilt. This could make swapping multiple tiles in a same row or column feel more natural.
You've reached the end of this tutorial!
If everything went right, you should now have a fun, playable puzzle app that is cool because of functionality that you added yourself! Congratulations! 🎉
Here are some key skills I hope you took from this tutorial:
- examining architecture and extending it without awkwardly forcing new functionality into existing classes
- approaching the problem in a step-by-step manner, and testing your solution early and often (even though in this case testing was just visual inspection)
- some enjoyment from interacting with your phone not in the usual 'swipe-finger-on-touchscreen', but in a more direct, physical way
Next up, in the spirit of Flutter's cross-platform nature, I will look into how to extend the fun features we added here to desktop platforms. Desktop platforms generally lack both gyroscope and accelerometer sensors, and are not as easy to physically move around, so we will have to think of a different way of controlling the game.