Ejemplo n.º 1
0
// ---
QGAMES::Board* QGAMES::BasicBoardAddsOn::createBoard 
	(const QGAMES::BoardBuilder::BoardDefinition& def, const std::string& bP)
{
	TiXmlDocument doc (def._fileDefinition.c_str ());
	int e = doc.LoadFile ();
	assert (e); // Is it a valid doc?

	TiXmlElement* rootElement = doc.RootElement ();
	assert (rootElement); // One element minimum...

	// Read all parts of the file defining the 
	QGAMES::BoardResources resources; QGAMES::BoardSquares squares;
	std::list <QGAMES::BasicBoardAddsOn::SquareConnectionDefinition> connections;
	for (TiXmlElement* groupElement = rootElement -> FirstChildElement ();
		groupElement != NULL; groupElement = groupElement -> NextSiblingElement ())
	{
		if (strcmp (groupElement -> Value (), __QGAMES_BOARDRESOURCESTAG__) == 0)
			resources = createBoardResources (readResources (groupElement));
		if (strcmp (groupElement -> Value (), __QGAMES_BOARDSQUARESTAG__) == 0)
			squares = createBoardSquares (readSquares (groupElement));
		if (strcmp (groupElement -> Value (), __QGAMES_BOARDSQUARECONNECTIONSTAG__) == 0)
			connections = readConnections (groupElement);
	}

	// Once everything has been read, the instance is created...
	// and then the squares connected.
	QGAMES::Board* result = createBoardInstance (def._id, squares, resources); 
	setConnections (squares, connections);
	return (result); // The result is returned!
}
GameBoard::GameBoard()
{
	createBoardSquares();
	createSnakes();
	createLadders();
}