示例#1
0
	void MapCommand::invoke(vector<string>& parameters) {
		cout << "Map command." << endl;
		if (parameters.size() > 0) {
			TestMode* mode = dynamic_cast<TestMode*>(m_game->getMode(BlockWorld::TEST_MODE));
			if (mode) {
				cout << "Found mode." << endl;
				MapLoader* loader = new MapLoader();
				MapDirectory* map = NULL;
				
				loader->loadDirectory("Resources/Maps");
				
				list<MapDirectory*>& maps = loader->getMaps();
				list<MapDirectory*>::iterator it = maps.begin();
				
				for ( ; it != maps.end(); it++) {
					cout << "Map: " << (*it)->getDirectoryName() << " (" << parameters[0] << ")" << endl;
					if ((*it)->getDirectoryName().compare(parameters[0]) == 0) {
						map = *it;
						break;
					}
				}
				
				if (map) {
					cout << "Found map." << endl;
					mode->setMap(map);
					m_game->setCurrentMode(BlockWorld::TEST_MODE);
				}
				
				delete loader;
			}
		}
	}
示例#2
0
	void NetworkTestMode::onLoadMap(LoadMapMessage& message)
	{
		performStop();
		
		MapLoader* loader = new MapLoader();
		MapDirectory* map = NULL;
		
		loader->loadDirectory("Resources/Maps");
		
		list<MapDirectory*>& maps = loader->getMaps();
		list<MapDirectory*>::iterator it = maps.begin();
		
		for ( ; it != maps.end(); it++) {
			if ((*it)->getDirectoryName().compare(message.getName()) == 0) {
				map = *it;
				break;
			}
		}
		
		if (map) {
			Engine* engine = m_game->getEngine();
			
			ImageMapWorldCreator* worldCreator = new ImageMapWorldCreator();
			m_world = worldCreator->createWorld(*engine, *map);
			
			m_camera = new MouseScrollCamera(*m_world, *engine);
			
			delete worldCreator;
			
			m_objectManager = new ObjectManager();
			
			m_gibLoader = new GibResourceLoader(*engine);
			m_gibLoader->loadFile("Resources/Gibs/gibs.xml");
			
			// If we get here the map should be successfully loaded ;)
			// Therefore we send the message to the server.
			MapLoadedMessage loaded(m_thisNetworkID);
			m_game->getNetwork()->sendMessage(loaded);
		}

		delete loader;
	}