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


C++ ItemInstance::setCoords方法代码示例

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


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

示例1: initializeFromFile

void Room::initializeFromFile(std::ifstream& fin, std::vector<Monster>& temp, std::vector<Items>& temp2, int level) {
	initialized = true;
	fin >> width;
	fin >> height;

	int nMonsters;
	fin >> nMonsters;
	for (int i = 0; i < nMonsters; i++) {
		std::string name;
		fin >> name;
		MonsterInstance* m = 0;
		for (int i = 0; i < temp.size(); i++) {
			if (!name.compare(temp[i].getName()))
				m = new MonsterInstance(temp[i]);
		}
		if (m == 0) throw "bad monster name";
		int x, y;
		fin >> x;
		fin >> y;
		m->setCoords(x, y);
		monsters.push_back(*m);
	}

	int nItems;
	fin >> nItems;
	for (int i = 0; i < nItems; i++) {
		std::string name;
		fin >> name;
		ItemInstance* m = 0;
		for (int i = 0; i < temp2.size(); i++) {
			if (!name.compare(temp2[i].getName()))
				m = new ItemInstance(temp2[i]);
		}
		if (m == 0) throw "bad item name";
		int x, y;
		fin >> x;
		fin >> y;
		m->setCoords(x, y);
		items.push_back(*m);
	}
}
开发者ID:Danice123,项目名称:DungeonCrawler,代码行数:41,代码来源:Room.cpp

示例2: initializeRandom

void Room::initializeRandom(std::vector<Monster>& tempM, std::vector<Items>& tempI, int level) {
	initialized = true;
	width = 5 + rand() % 5;
	height = 5 + rand() % 5;

	int nMonsters = maxMonsters != 0?rand() % maxMonsters:0;
	std::vector<Monster> vm;
	for (int i = 0; i < tempM.size(); i++) {
		if (tempM[i].getScale() <= level) vm.push_back(tempM[i]);
	}

	for (int i = 0; i < nMonsters; i++) {
		MonsterInstance m(vm[rand() % vm.size()]);
		m.setCoords(rand() % width, rand() % height);
		monsters.push_back(m);
	}

	int nItems = rand() % maxItems;
	std::vector<Items> wal;
	std::vector<Items> ol;
	for (int i = 1; i < tempI.size(); i++) {
		if (tempI[i].getType() == 2) {
			if (tempI[i].getScale() <= level) ol.push_back(tempI[i]);
		} else if (tempI[i].getScale() <= level) wal.push_back(tempI[i]);
	}

	for (int i = 0; i < nItems; i++) {
		ItemInstance* m;
		if (rand() % 100 < 20) {
			m = new ItemInstance(wal[rand() % wal.size()]);
		} else  {
			m = new ItemInstance(ol[rand() % ol.size()]);
		}
		m->setCoords(rand() % width, rand() % height);
		items.push_back(*m);
	}
}
开发者ID:Danice123,项目名称:DungeonCrawler,代码行数:37,代码来源:Room.cpp


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