#include "Command.h"
#include "Person.h"
#include "Level.h"
#include "List.h"


using namespace std;

const std::string JumpCommand::_id = "jump";

JumpCommand::JumpCommand(Person *person, xDirection xDir)
:_person(person->id()),_xDir(xDir)
{
}

JumpCommand::JumpCommand(List *command)
{
	command = command->rest();
	//_person = (Person *)Level::instance()->getObject(command->firstString());
	_person = command->firstString();
	command = command->rest();
	_xDir = (xDirection)command->firstInt();
}

void JumpCommand::execute()
{
	Person *person = (Person *)Level::instance()->getObject(_person);
	if(person == NULL)
		return;
	person->jump(_xDir);
}

std::string JumpCommand::getString()
{
	List *command = new List();
	command->snoc(new Atom(_id));
	command->snoc(new Atom(_person));
	command->snoc(new Atom(_xDir));
	string commandString = command->getString();
	delete command;

	return commandString;
}