当前位置: 首页>>代码示例>>C++>>正文


C++ House::getFrontDoor方法代码示例

本文整理汇总了C++中House::getFrontDoor方法的典型用法代码示例。如果您正苦于以下问题:C++ House::getFrontDoor方法的具体用法?C++ House::getFrontDoor怎么用?C++ House::getFrontDoor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在House的用法示例。


在下文中一共展示了House::getFrontDoor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Load

bool Houses::Load(Game* game)
{
	if (!LoadHouseItems(game))
		return false;

	std::string file = g_config.DATA_DIR + "houses.xml";
	xmlDocPtr doc;
	doc = xmlParseFile(file.c_str());

	if (doc)
	{
		xmlNodePtr root, houseNode, tileNode;
		root = xmlDocGetRootElement(doc);
		if (xmlStrcmp(root->name, (const xmlChar*)"houses")) 
		{
			xmlFreeDoc(doc);
			return false;
		}

		houseNode = root->children;
		while (houseNode)
		{
			if (strcmp((char*) houseNode->name, "house") == 0)
			{
				std::string name = (const char*)xmlGetProp(houseNode, (const xmlChar *) "name");
				House* house = new House(name);

				if (!house->load())
				{
					xmlFreeDoc(doc);
					return false;
				}

				houses.push_back(house);
				tileNode = houseNode->children;

				while (tileNode)
				{            
					if (strcmp((const char*) tileNode->name, "tile") == 0)
					{          
						int tx = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "x"));
						int ty = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "y"));
						int tz = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "z"));	

						if (!AddHouseTile(game, house, Position(tx, ty, tz)))
						{
							xmlFreeDoc(doc);
							return false;
						}
					}
					else if (strcmp((const char*) tileNode->name, "tiles") == 0)
					{
						int fromx = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "fromx"));
						int fromy = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "fromy"));
						int fromz = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "fromz"));
						int tox = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "tox"));
						int toy = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "toy"));
						int toz = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "toz"));

						if (fromx > tox) std::swap(fromx, tox);
						if (fromy > toy) std::swap(fromy, toy);
						if (fromz > toz) std::swap(fromz, toz);

						for (int x = fromx; x <= tox; x++)
							for (int y = fromy; y <= toy; y++)
								for (int z = fromz; z <= toz; z++)
									if (!AddHouseTile(game, house, Position(x,y,z)))
									{
										xmlFreeDoc(doc);
										return false;
									}								
					}
					tileNode = tileNode->next;
				}

				Tile* doorTile = game->getTile(house->getFrontDoor());		// include front door
				if (doorTile && !doorTile->isHouse())
					doorTile->setHouse(house);
			}
			houseNode = houseNode->next;
		}
		xmlFreeDoc(doc);
		return true;
	}

	return false;
}
开发者ID:divinity76,项目名称:YurOTS,代码行数:87,代码来源:houses.cpp


注:本文中的House::getFrontDoor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。