class hgame.HGame(object)

In a Humerus-based game there is exactly one instance of HGame or one of its subclasses. This object acts as a central junction point between the internal state of the game and the user interface, implemented by an HShell.

The HGame keeps track of the game state, and provides facilites to help with saving the state of progress of the game in a file, and restoring it from a previously saved file.

Game States

The game state is kept in a state object attached to the state attribute of the HGame. This object can be of any class, although if you want to take advantage of the default game saving machinery, it must be pickleable. You will need to provide a new_state() method that creates and returns a new state object of the appropriate type.

Saved Game Files

By default, HGame writes the following information to a saved game file:
The filename suffixes, magic numbers and version numbers can all be customized using class attributes. You can also provide information about which data formats are understood by earlier versions of the game, so that if a user tries to open a saved game file with the wrong version of the game, he can be given an error message indicating which version he needs to use.

Class Attributes

app_version = (1, 0, 0)
Version number of the game application.
app_magic = "????"
Magic "number" identifying the game application. Traditionally a 4-character string, but this is not a requirement.
save_file_version = 1
Version number of the saved-game data format written by this version of the application (an integer).
save_min_version = 1
Minimum data format version understood by this version of the application.
save_app_version = (1, 0, 0)
Earliest application version that understands the saved-game data format written by this version of the application.
save_version_ranges = {}
Information about application versions that understand saved-game data versions earlier than save_min_version. A mapping from data versions to pairs of application versions (min_app_version, max_app_version).
save_file_magic = "SAVE"
Magic "number" identifying the file as a saved-game file. You probably won't need to change this.
save_file_default_name = "SavedGame"
Default filename for saved-game files.
save_file_suffix = ".gam"
Filename suffix for saved-game files.
default_save_dir_name = "Saves"
Default directory for saved-game files, within the directory two levels up from the Albow Resources directory.


Directory of the saved-game file last loaded or saved.
Filename (last pathname component) of the saved-game file last loaded or saved.
True if there is game progress that has not been saved. You will need to set this flag to true whenever something happens in the game that warrants saving.
Object holding state to be saved in a saved-game file.

Abstract Methods

Should create and return a new object holding the state to be saved in a saved-game file, initialised as for a new game.

Should return a true value if the game is completed. The value returned will be passed to the game_completed() method of the HShell, and can be used to distinguish between different completion states, such as winning or losing. The default implentation always returns false.

Called once per frame from the HShell when the playing screen, or some other screen that should run the game, is active. Whether a given screen runs the game is determined by the HShell's screen_runs_game() method.


You will probably not need to call any of these methods yourself, as they are called at the appropriate time from the HShell. They are documented here in case you want to know about them for customization purposes.
Returns true if a game has been started and not yet completed. HShell uses this to determine whether it makes sense to execute the Save Game or Save Game As command.

Returns true if it is appropriate to show the playing screen. (For HShell this is the same as game_in_progress(), but HLShell defines them differently.)
Starts a new game by creating a fresh state object.
Restores a game from the specified saved-game file.
Saves the state of the current game in the specified saved-game file.
Returns the full pathname of the directory last used to load or save a game.

Returns the default pathname that should be used for saving a game.