Exemplo n.º 1
0
void ViewObject::draw()
{
	auto& gfxMgr = GraphicsManager::getInstance();
	std::stringstream temp_str;
	// Display view string + value.
	if (border)
	{
		temp_str << "|" << getViewString() << " " << value << "|";
	}
	else
	{
		temp_str << getViewString() << " " << value;
	}
	// Draw centered at position.
	Position pos = viewToWorld(getPosition());
	gfxMgr.drawString(pos, temp_str.str(), CENTER_JUSTIFIED, getColor());
	if (border)
	{
		int x = pos.getX();
		int y = pos.getY();
		int length = temp_str.str().length();
		std::stringstream frameStr;
		for (int i = 0; i < length; i++)
		{
			frameStr << "=";
		}
		// Draw box around display.
		gfxMgr.drawString(Position(x, y - 1), frameStr.str(), CENTER_JUSTIFIED, getColor());
		gfxMgr.drawString(Position(x, y + 1), frameStr.str(), CENTER_JUSTIFIED, getColor());
	}
}
Exemplo n.º 2
0
void CapturedString::draw() {

	string temp_str;
	if (getBorder()) {
		temp_str = (" " + getViewString() + " ");
	}
	else {
		temp_str = (getViewString());
	}

	//Draw centered at position
	Position pos = worldToView(getPosition());
	GraphicsManager &graphicsmanager = GraphicsManager::getInstance();
	graphicsmanager.drawString(pos, temp_str, CENTER_JUSTIFIED, getColor());

	if (getBorder()) {
		string top_border = "";
		char side_border = '|';
		for (int i = 0; i < temp_str.length(); i++) {
			top_border += "-";
		}
		Position bottom_pos = Position(pos.getX(), pos.getY() + 1);
		Position top_pos = Position(pos.getX(), pos.getY() - 1);
		Position left_border = Position(pos.getX() - temp_str.length()/2 - 1, pos.getY());
		Position right_border = Position(pos.getX() + temp_str.length()/2 + 1, pos.getY());
		graphicsmanager.drawString(top_pos, top_border, CENTER_JUSTIFIED, getColor());
		graphicsmanager.drawString(bottom_pos, top_border, CENTER_JUSTIFIED, getColor());
		graphicsmanager.drawCh(left_border, side_border, getColor());
		graphicsmanager.drawCh(right_border, side_border, getColor());

	}
}
Exemplo n.º 3
0
void ViewObject::draw(){
	GraphicsManager &graphics_manager = GraphicsManager::getInstance();
	string temp_str;

	if(getBorder() == true){
		temp_str = " " + getViewString() + " " + intToString(value) + " ";
	} else {
		temp_str = getViewString() + " " + intToString(value);
	}

	//Draw centered at position
	Position pos = viewToWorld(getPosition());
	graphics_manager.drawString(pos, temp_str, CENTER_JUSTIFIED, getColor());

	//Draw box around display
	if (getBorder() == true){
		int boxLength = strlen(getViewString().c_str()) + 4;
		int boxHeight = 3;
		int boxOffset = boxLength/2;
		bool odd = false;

		if (boxLength % 2){
			odd = true;
		}

		for (int i = 0; i < boxLength; i++){
			Position new_pos(pos.getX() + i - boxOffset, pos.getY()-1);
			graphics_manager.drawCh(new_pos, '-', getColor());
		}

		//Bottom
		for (int i = 0; i < boxLength; i++){
			Position new_pos(pos.getX() + i - boxOffset, pos.getY()+1);
			graphics_manager.drawCh(new_pos, '-', getColor());
		}

		//Left
		Position left_pos(pos.getX()-boxOffset-1, pos.getY());
		graphics_manager.drawCh(left_pos, '|', getColor());

		//Right
		if (!odd){
			Position right_pos(pos.getX()+boxOffset, pos.getY());
			graphics_manager.drawCh(right_pos, '|', getColor());
		} else {
			Position right_pos(pos.getX()+boxOffset+1, pos.getY());
			graphics_manager.drawCh(right_pos, '|', getColor());
		}
	}
}
Exemplo n.º 4
0
int ViewObject::eventHandler(Event *p_e)
{
	// See if this is a `view' event.
	if (p_e->getType() == DF_VIEW_EVENT)
	{
		EventView *p_ve = static_cast <EventView *> (p_e);
		// See if this event is meant for this object.
		if (p_ve->getTag() == getViewString())
		{
			if (p_ve->getDelta())
			{
				setValue(getValue() + p_ve->getValue()); // Change in value.
			}
			else
			{
				setValue(p_ve->getValue()); // New value.
			}
		}

		// Event was handled.
		return 1;
	}



	// If here, event was not handled.
	return 0;
}
Exemplo n.º 5
0
void CapturedString::addLetter(char letter) {
	string temp_str = getViewString();

	// Handle wildcard
	if(letter == '*') {

		int firstEmptyPos = 0;
		for(int i = 0; i < temp_str.length(); ++i) {
			if(temp_str[i] == ' ') {
				firstEmptyPos = i;
				break;
			}
		}

		// Add letter
		temp_str[firstEmptyPos] = complete_string[firstEmptyPos];
	} else {
		// Normal character
		size_t posInCompleteString = complete_string.find_first_of(letter, 0);

		if(posInCompleteString == string::npos) 
			return; // character isn't in string, ignore

		do {
			if(temp_str[posInCompleteString] == letter)
				continue; // already got this one
			// else

			temp_str[posInCompleteString] = letter;
			break; // done

		} while((posInCompleteString = complete_string.find_first_of(letter,
			 posInCompleteString + 1)) != string::npos);
		// loop until there are no more instances of this character in the string
	}

	setViewString(temp_str);

	if(temp_str == complete_string) { // completed string
		LogManager &logmanager = LogManager::getInstance();
		logmanager.writeLog("Completed string!\n");

		//Level over, make hero spectral
		WorldManager &worldmanager = WorldManager::getInstance();
		ObjectList objects_copy = worldmanager.getAllObjects();
		ObjectListIterator i(&objects_copy);
		for (i.first(); !i.isDone(); i.next()) {
			if (i.currentObject()->getType().compare("Hero") == 0) {
				i.currentObject()->setSolidness(SPECTRAL);
			}
		}

		LevelHandler &levelhandler = LevelHandler::getInstance();
		new LevelChange(levelhandler.getLevel() + 1);

	}
}
Exemplo n.º 6
0
int ViewObject::eventHandler(Event *p_e){

	//See if this is a ViewEvent
	if (p_e->getType() == VIEW_EVENT){
		EventView *p_ve = (EventView *) p_e;

		//See if event is meant for this object
		if(p_ve->getTag() == getViewString()){

			//Act accoridng if it is a delta or not
			if (p_ve->getDelta()){
				setValue(getValue() + p_ve->getValue());
			} else {
				setValue(p_ve->getValue());
			}
			//Event handled
			return 1;
		}
	}


	//Event not handled
	return 0;
}
Exemplo n.º 7
0
string TextObject::getRenderString() const
{
	return getViewString();
}