2005-02-24 09:06:24 +01:00
|
|
|
/*****************************************************************************
|
2008-01-08 14:52:32 +01:00
|
|
|
* Eliot
|
|
|
|
* Copyright (C) 2005-2007 Olivier Teulière
|
|
|
|
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
2005-02-24 09:06:24 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-23 16:53:42 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-02-24 09:06:24 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _GAME_FACTORY_H_
|
|
|
|
#define _GAME_FACTORY_H_
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
#include <string>
|
2008-01-19 20:33:08 +01:00
|
|
|
#include <vector>
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
|
|
using std::string;
|
2008-01-19 20:33:08 +01:00
|
|
|
using std::wstring;
|
|
|
|
using std::vector;
|
|
|
|
using std::pair;
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
|
|
class Dictionary;
|
|
|
|
class Game;
|
|
|
|
class Training;
|
|
|
|
class FreeGame;
|
|
|
|
class Duplicate;
|
2005-02-24 09:06:24 +01:00
|
|
|
|
|
|
|
|
2005-03-27 19:30:48 +02:00
|
|
|
/**
|
|
|
|
* This class is the entry point to create Game objects, either directly or
|
|
|
|
* using command-line parameters. It also offers a method to destroy Game
|
|
|
|
* objects.
|
|
|
|
* This class implements the Singleton pattern.
|
|
|
|
*/
|
2005-02-24 09:06:24 +01:00
|
|
|
class GameFactory
|
|
|
|
{
|
|
|
|
public:
|
2005-03-03 23:14:41 +01:00
|
|
|
static GameFactory *Instance();
|
|
|
|
static void Destroy();
|
|
|
|
|
2005-02-24 09:06:24 +01:00
|
|
|
/*************************
|
|
|
|
* Functions to create and destroy a game
|
|
|
|
* The dictionary does not belong to the
|
|
|
|
* game (ie: it won't be destroyed by ~Game)
|
|
|
|
*************************/
|
|
|
|
Training *createTraining(const Dictionary &iDic);
|
|
|
|
FreeGame *createFreeGame(const Dictionary &iDic);
|
|
|
|
Duplicate *createDuplicate(const Dictionary &iDic);
|
2006-08-12 00:14:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2008-01-08 14:52:32 +01:00
|
|
|
Game *load(const string &iFileName, const Dictionary &iDic);
|
2005-02-24 09:06:24 +01:00
|
|
|
|
2005-03-03 23:14:41 +01:00
|
|
|
Game *createFromCmdLine(int argc, char **argv);
|
|
|
|
|
2005-03-27 19:30:48 +02:00
|
|
|
/// Destroy a Game object, created by any of the createXXX methods above
|
2005-02-24 09:06:24 +01:00
|
|
|
void releaseGame(Game &iGame);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2005-03-03 23:14:41 +01:00
|
|
|
GameFactory();
|
2008-01-08 14:52:32 +01:00
|
|
|
~GameFactory();
|
2005-02-24 09:06:24 +01:00
|
|
|
|
2005-03-03 23:14:41 +01:00
|
|
|
/// The unique instance of the class
|
2005-02-24 09:06:24 +01:00
|
|
|
static GameFactory *m_factory;
|
2005-03-03 23:14:41 +01:00
|
|
|
|
|
|
|
/// Initial dictionary (it could be changed later)
|
2008-01-08 14:52:32 +01:00
|
|
|
Dictionary *m_dic;
|
2005-03-03 23:14:41 +01:00
|
|
|
|
|
|
|
/** Parameters specified on the command-line */
|
|
|
|
//@{
|
|
|
|
|
|
|
|
/// Dictionary
|
|
|
|
string m_dicStr;
|
|
|
|
|
|
|
|
/// Game mode
|
|
|
|
string m_modeStr;
|
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/// Variant of the game
|
|
|
|
bool m_joker;
|
|
|
|
|
2008-01-19 20:33:08 +01:00
|
|
|
typedef pair<bool, wstring> PlayerDesc;
|
|
|
|
vector<PlayerDesc> m_players;
|
|
|
|
|
2005-03-03 23:14:41 +01:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/// Print command-line usage
|
|
|
|
void printUsage(const string &iBinaryName) const;
|
|
|
|
|
|
|
|
/// Print version
|
|
|
|
void printVersion() const;
|
|
|
|
|
2005-02-24 09:06:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _GAME_FACTORY_H_
|
2006-01-01 20:49:35 +01:00
|
|
|
|