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

using namespace std;

const std::string MoveCommand::_id = "move";

MoveCommand::MoveCommand(Person *person, xDirection xDir)
:_person(person->id()),_xDir(xDir)
{
	
}
MoveCommand::MoveCommand(List *command)
{
	command = command->rest();
	_person = command->firstString();
	command = command->rest();
	_xDir = (xDirection)command->firstInt();
}
void MoveCommand::execute()
{
	Person *person = (Person *)Level::instance()->getObject(_person);
	if(person == NULL)
		return;

	person->incrVelocity((int)_xDir * person->getAccel(),0);
	person->setXDirection(_xDir);
}

std::string MoveCommand::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;
}