Ejemplo n.º 1
0
	void ExampleProtocol::info() const
	{
		printf("ExampleProtocol: \n");
		printf("  RunMode:    " );
		switch (RunMode)
		{
			case Mode1: printf("Mode1\n"); break;
			case Mode2: printf("Mode2\n"); break;
			case Mode3: printf("Mode3\n"); break;
			default: throw(CodeException("Unknown Mode in ExampleProtocol"));
		}
		printf("  ExampleParam1: %d Units \n", ExampleParam1);
		printf("  ExampleParam2: %f Units \n", ExampleParam2);
	}
Ejemplo n.º 2
0
void Player::read(string name, string script)
{
	ifstream infile(script);
	if (!infile.is_open()) {
		string error = "[ERROR]:  Open file fail: " + script;
		throw CodeException(FAIL_FILE_OPEN, error.c_str());
	}
	string currentLine;
	//Using regular expression to check the data for each line
	regex re("^\\s*(\\d+)\\s*([^\\d\\s].*?)\\s*$");
	while (getline(infile, currentLine)) {
		smatch sm;
		regex_match(currentLine, sm, re);
		if (sm.size() > 0) {
			//Once the line match the RE, come in this if condition and insert data
			lines[stoi(sm[1])] = SingleLine(name, sm[2]);
		}
	}
}
Ejemplo n.º 3
0
Director::Director(const string& scriptName, unsigned int playerCount, bool overRide)
{
	isOverride = overRide;
	maximum = 0;
	ifstream infile(scriptName);
	if (!infile.is_open()) {
		string error = "[ERROR]:  Open file fail: " + scriptName;
		throw CodeException(FAIL_FILE_OPEN, error.c_str());
	}
	string currentLine;
	bool followingPL;
	int scriptCounter = 1;
	int lastPartDefCount = 0;

	regex re("^\\[scene\\][\\s]([\\w\\s]*)$");
	smatch sm;
	regex re_config("^[\\s]*(.*.txt)[\\s]*$");
	smatch sm_config;
	regex re_part("^[\\s]*([\\w]+)[\\s]+(.*.txt)[\\s]*$");
	smatch sm_part;

	while (getline(infile, currentLine)) {
		// scan for scene titles
		if (regex_match(currentLine, sm, re)) {
			titles.push_back(sm[1]);
			followingPL = false;
		}
		else {
			// scan for scene fragment config files
			if (regex_match(currentLine, sm_config, re_config)) {
				scripts[scriptCounter] = script();

				if (!followingPL) {
					followingPL = true;
				}
				else {
					titles.push_back(string());
				}
				ifstream configFile(sm_config[1]);
				int partDefinitionLineCount = 0;

				if (!configFile.is_open()) {
					string temp = sm_config[1];
					string error = "[ERROR]:  Open file fail: " + temp;
					throw CodeException(FAIL_FILE_OPEN, error.c_str());
				}
				
				string partDefinitionLine;
				while (getline(configFile, partDefinitionLine)) {
					// scan for part definition files
					if (regex_match(partDefinitionLine, sm_part, re_part)) {
						partDefinitionLineCount++;
						scripts[scriptCounter][sm_part[1]] = sm_part[2];
					}
				}

				scriptCounter++;
				if (!isOverride) {
					int consecutiveSum = partDefinitionLineCount + lastPartDefCount;
					lastPartDefCount = partDefinitionLineCount;
					maximum = maximum > consecutiveSum ? maximum : consecutiveSum;
				}
			}
		}
	}

	//finish reading script
	try {
		play = playPtr(new Play(titles, finished.get_future()));
	}
	catch (exception& e) {
		throw (BAD_ALLOCATION,e);
	}
	
	// check the override option
	if (!isOverride) {
		maximum = maximum > (int)playerCount ? maximum : (int)playerCount;
	}
	else {
		maximum = (int)playerCount;
	}
	
	for (int i = 0; i < maximum; i++) {
		try {
			players.push_back(playerPtr(new Player(*play)));
		}
		catch (exception& e) {
			throw (BAD_ALLOCATION, e);
		}
		
		players[i]->activate();
	}
}