2048: Saving Game State in the URL
Brian Muramatsu
Hello folks, Brian here.
Have you played 2048? It’s a game where you combine tiles and try to reach 2048.
Recently, I made a new version that saves the state of the game in the URL. You can check it out: https://btmura.github.io/2048
The official version lets you play multiple games at a time, but if Windows or Chrome restarts for a pesky update, then all your tabs are restored with the last game you were playing… In this new version, you can see that the games in each tab are restored!
To create this new version, I first forked the official version on GitHub.
Then I tweaked the code in local_storage_manager.js to save the game in the URL rather than using local storage which is per domain. I simply joined the score, game state, and tile values with periods and pushed it on the history stack. For the tile values, I took the idea of using logarithms from Scott Torborg’s fork. I left the saving of the best score in local storage, since that is a single value to be saved across all games. Also, I added a clone button to open up a new tab with the current URL, so a user can go back to a previous state.
Finally, I took advantage of GitHub pages to host the game. GitHub pages allows you to serve content straight from your Git repository, and it seems to be free as far as I can tell!
Anyway, if you have any feature suggestions, feel free to let me know in the comments. Thanks for watching. See you later. Bye! ... https://www.youtube.com/watch?v=95FQ3JoAmQA
21250300 Bytes