Wednesday, 8 July 2009

Refactoring for Persistance

Saving and Loading Games would be nice, but before I even attempt to implement that, I need to do a codebase-wide refactor. Currently I have numerous global variables that I have used to store various state data, e.g. the number of turns that have passed, the current level depth, and so on. I really need to store all these in a "game-state" object that is instantiated on starting a game (and this is one of the nice things about C# - that everthing is an object). If I do this, it will make saving and loading a heck of a lot easier to implement. In fact, it would make it decidedly trivial.

Additionally, this gets rid of all those nasty global variables that currently litter my code, and in itself this is a good thing, as they are (and I agree with this) "considered harmful".

(N.B. when I talk about saving and loading, I don't mean in the style of the old Kharne, where you could freely reload saved games, but rather in the traditional roguelike sense of "saving a game and then restarting it within the framework of permadeath")

No comments: