4 ms·
I wrote a game in that style, once: http://emilhernvall.github.io/bubblespinner/bubblespinner.html http://emilhernvall.github.io/bubblespinner/bubblespinner.ht.
by oxymoron 6y ago
I wrote a game in that style, once: http://emilhernvall.github.io/bubblespinner/bubblespinner.html http://emilhernvall.github.io/bubblespinner/bubblespinner.ht... (repo at https://github.com/emilhernvall/bubblespinner https://github.com/emilhernvall/bubblespinner)
It’s in Javascript, so not all of it is functionally pure, but the core game logic follows that pattern. The code is heavily commented, and hopefully somewhat readable. I think the main benefit I found was that it was trivial to snapshot states and replay as needed. That made debugging easier, and might have simplified something like a save/reload feature. Although I didn’t go there for this toy project, I’d argue that testability might be another consideration.
More generally, I’ve seen over the years that global state tends to be painful in unforseen ways. At one point, I was considering a fork of putty to add support for tabs. It has a lot of global state, so I had to abandon that idea. If the same state had been wrapped up in a state struct and passed around, it’d have been easy.