C:/Documents and Settings/jegan/Desktop/projectX/SetPositionCommand.cpp

Go to the documentation of this file.
00001 #include "Command.h"
00002 #include "Person.h"
00003 #include "List.h"
00004 #include "Level.h"
00005 
00006 using namespace std;
00007 
00008 const std::string SetPositionCommand::_id = "setPosition";
00009 
00010 SetPositionCommand::SetPositionCommand(Object *object, int xPos, int yPos)
00011 :_object(object->id()),_xPos(xPos),_yPos(yPos)
00012 {
00013         
00014 }
00015 
00016 SetPositionCommand::SetPositionCommand(List *command)
00017 {
00018         command = command->rest();
00019         _object = command->firstString();
00020         command = command->rest();
00021         _xPos = command->firstInt();
00022         command = command->rest();
00023         _yPos = command->firstInt();
00024 }
00025 
00026 void SetPositionCommand::execute()
00027 {
00028         Object *object = Level::instance()->getObject(_object);
00029         if(object == NULL)
00030                 return;
00031         object->setPos(_xPos,_yPos);
00032 }
00033 
00034 std::string SetPositionCommand::getString()
00035 {
00036         List *command = new List();
00037         command->snoc(new Atom(_id));
00038         command->snoc(new Atom(_object));
00039         command->snoc(new Atom(_xPos));
00040         command->snoc(new Atom(_yPos));
00041         string commandString = command->getString();
00042         delete command;
00043 
00044         return commandString;
00045 }

Generated on Fri May 5 00:20:19 2006 for ProjectX by  doxygen 1.4.6-NO