示例#1
0
void FileManager::Save(int saveNum)
{
	//Declare variables to read the file
	std::string temp;
	std::vector<std::string> save = LoadSaveFile();
	std::vector<std::string>::iterator iter;
	
	std::ofstream osaveFile;
	osaveFile.open("save/save.sav");

	std::stringstream ss;

	float playerX=0, playerY=0, playerVelX=0, playerVelY=0, playerGravity=0;
	bool playerDir=false, playerVerticalDir=false, playerJump=false, playerIdle=false;
	
	GameObjectManager::GetInstance().GetPlayerData(playerX, playerY, playerVelX, playerVelY, playerGravity, playerDir, playerVerticalDir, playerJump, playerIdle);

	ss << 1 << "," << _currentLevel << "," << _difficulty << "," << _camX << "," << _camY << "," << playerX << "," << playerY << "," << playerVelX << ","
		<< playerVelY << "," << playerDir << "," << playerVerticalDir << "," << playerGravity << "," << playerJump << "," << playerIdle << "," << _deaths << ","
		<< _hours << "," << _minutes << "," << _seconds << "," << _steps << ";";
	save[saveNum] = ss.str();

	//Clear stringstream
	ss.clear();
	ss.str(std::string());
	
	for(iter = save.begin(); iter!=save.end();iter++)
		ss << (*iter) << std::endl;

	osaveFile << ss.str();

	osaveFile.close();
}
示例#2
0
ret_ CXMLLoaderActions::LoadProcessBlock(CProgram &Program,
										 const DOMElement *pElement,
										 const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

	if (!pChild)
		return XML_LOADER_ERROR;

	auto_xerces_str wsEmpty				("empty");
	auto_xerces_str	wsUnitaryCalculate	("unitary_calculate");
	auto_xerces_str	wsDualityCalculate	("duality_calculate");
	auto_xerces_str wsConfigGroup		("config_group");
	auto_xerces_str	wsIf				("if");
	auto_xerces_str	wsWhile				("while");
	auto_xerces_str wsContinue			("continue");
	auto_xerces_str wsBlock				("block");
	auto_xerces_str wsBreak				("break");
	auto_xerces_str	wsSend				("send");
	auto_xerces_str wsReadFile			("read_file");
	auto_xerces_str wsSaveFile			("save_file");
	auto_xerces_str wsDeleteFile		("delete_file");
	auto_xerces_str wsSplit				("split");
	auto_xerces_str	wsDie				("die");
	auto_xerces_str wsShowWindow		("show_window");
	auto_xerces_str wsWaitMessage		("wait_message");
	auto_xerces_str wsAlert				("alert");
	auto_xerces_str wsEnable			("enable");
	auto_xerces_str wsAddItem			("add_item");
	auto_xerces_str wsProgram			("program");

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsEmpty))
		{
			if (SUCCESS != LoadEmpty(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsUnitaryCalculate))
		{
			if (SUCCESS != LoadUnitaryCalculate(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsDualityCalculate))
		{
			if (SUCCESS != LoadDualityCalculate(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsConfigGroup))
		{
			if (SUCCESS != LoadConfigGroup(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsIf))
		{
			if (SUCCESS != LoadIf(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsWhile))
		{
			if (SUCCESS != LoadWhile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsContinue))
		{
			if (SUCCESS != LoadContinue(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsBlock))
		{
			if (SUCCESS != LoadBlock(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsBreak))
		{
			if (SUCCESS != LoadBreak(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSend))
		{
			if (SUCCESS != LoadSend(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsReadFile))
		{
			if (SUCCESS != LoadReadFile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSaveFile))
		{
			if (SUCCESS != LoadSaveFile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsDeleteFile))
		{
			if (SUCCESS != LoadDeleteFile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSplit))
		{
			if (SUCCESS != LoadSplit(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsDie))
		{
			if (SUCCESS != LoadDie(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsShowWindow))
		{
			if (SUCCESS != LoadShowWindow(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsWaitMessage))
		{
			if (SUCCESS != LoadWaitMessage(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsAlert))
		{
			if (SUCCESS != LoadAlert(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsEnable))
		{
			if (SUCCESS != LoadEnable(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsAddItem))
		{
			if (SUCCESS != LoadAddItem(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsProgram))
		{
			CProgram *pSubProgram = new CProgram();

			if (SUCCESS != LoadProgram(&Program.Data(),
										*pSubProgram,
										pChild,
										pPDU))
            {
				return XML_LOADER_ERROR;
            }

			if (false_v == Program.AddOperator(pSubProgram))
				return XML_LOADER_ERROR;
		}

		pChild = (DOMElement *)pChild->getNextSibling();
	}

	return SUCCESS;
}
示例#3
0
void FileManager::Load(int saveNum)
{
	std::string temp;
	const std::vector<std::string> save = LoadSaveFile();;
	std::vector<std::string>::iterator iter;
	temp = "";
	//This variable keeps track of the place of the value to identify what it must do with it.
	int valueNum=0;
	float playerX=0, playerY=0, playerVelX=0, playerVelY=0, playerGravity=0;
	bool playerDir=false, playerVerticalDir=false, playerJump=false, playerIdle=false;
	for(unsigned int i=0; i<save[saveNum].size(); i++)
	{
		if(save[saveNum][i]==',' || save[saveNum][i]==';')
		{
			switch(valueNum)
			{
			case 0:
				if(!::atoi(temp.c_str()))
					return;
				break;
			case 1:
				_currentLevel = ::atoi(temp.c_str());
				break;
			case 2:
				_difficulty = ::atoi(temp.c_str());
				break;
			case 3:
				_camX = ::atoi(temp.c_str());
				break;
			case 4:
				_camY = ::atoi(temp.c_str());
				break;
			case 5:
				playerX = ::atof(temp.c_str());
				break;
			case 6:
				playerY = ::atof(temp.c_str());
				break;
			case 7:
				playerVelX = ::atof(temp.c_str());
				break;
			case 8:
				playerVelY = ::atof(temp.c_str());
				break;	
			case 9:
				if(temp == "0")
					playerDir = false;
				else if(temp=="1")
					playerDir = true;
				break;
			case 10:
				if(temp == "0")
					playerVerticalDir = false;
				else if(temp=="1")
					playerVerticalDir = true;
				break;
			case 11:
				playerGravity = ::atof(temp.c_str());
				break;
			case 12:
				playerJump = ::atoi(temp.c_str());
				break;
			case 13:
				playerIdle = ::atoi(temp.c_str());
				break;
			case 14:
				_deaths = ::atoi(temp.c_str());
				break;
			case 15:
				_hours = ::atoi(temp.c_str());
				break;
			case 16:
				_minutes = ::atoi(temp.c_str());
				break;
			case 17:
				_seconds = ::atoi(temp.c_str());
				break;
			case 18:
				_steps = ::atoi(temp.c_str());
				break;				
			}
			valueNum++;
			temp = "";
		}
		else if(save[saveNum][i]==';')
		{
		}
		else
			temp += save[saveNum][i];
	}
	GameObjectManager::GetInstance().SetPlayerData(playerX, playerY, playerVelX, playerVelY, playerGravity, playerDir, playerVerticalDir, playerJump, playerIdle);
}