From 69dada550b2edb6623495354632b9dcf4a1bdad4 Mon Sep 17 00:00:00 2001 From: Antoine Fraboulet Date: Fri, 11 Aug 2006 22:14:21 +0000 Subject: [PATCH] - add "load" in game_factory --- game/game_factory.cpp | 15 +++++++++++++++ game/game_factory.h | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/game/game_factory.cpp b/game/game_factory.cpp index 8558295..7a490a0 100644 --- a/game/game_factory.cpp +++ b/game/game_factory.cpp @@ -18,6 +18,7 @@ *****************************************************************************/ #include +#include #include "config.h" #include "dic.h" @@ -184,6 +185,20 @@ Game *GameFactory::createFromCmdLine(int argc, char **argv) return game; } +Game* GameFactory::load(string filename, const Dictionary &iDic) +{ + Game* game; + FILE* fin; + if ((fin = fopen(filename.c_str(), "r")) == NULL) + { + printf("impossible d'ouvrir %s\n", + filename.c_str()); + return NULL; + } + game = Game::load(fin,iDic); + fclose(fin); + return game; +} void GameFactory::releaseGame(Game &iGame) { diff --git a/game/game_factory.h b/game/game_factory.h index 9f93fd6..72d38ab 100644 --- a/game/game_factory.h +++ b/game/game_factory.h @@ -46,7 +46,13 @@ public: Training *createTraining(const Dictionary &iDic); FreeGame *createFreeGame(const Dictionary &iDic); Duplicate *createDuplicate(const Dictionary &iDic); - //Game *loadGame(FILE *fin, const Dictionary &iDic); + + /** + * load() returns the loaded game, or NULL if there was a problem + * load() might need some more work to be robust enough to + * handle "hand written" files + */ + Game *load(string filename, const Dictionary &iDic); Game *createFromCmdLine(int argc, char **argv);