00001 #include "Command.h" 00002 #include "Person.h" 00003 #include "List.h" 00004 #include "Level.h" 00005 #include "Player.h" 00006 00007 #include <iostream> 00008 00009 using namespace std; 00010 00011 const string AddHealthCommand::_id = "addHealth"; 00012 00013 AddHealthCommand::AddHealthCommand(Person *person, int dHealth) 00014 :_person(person),_dHealth(dHealth) 00015 { 00016 } 00017 00018 AddHealthCommand::AddHealthCommand(List *command) 00019 { 00020 command = command->rest(); 00021 _person = (Person *)Level::instance()->getObject(command->firstString()); 00022 _dHealth = command->rest()->firstInt(); 00023 } 00024 00025 void AddHealthCommand::execute() 00026 { 00027 _person->addHealth(_dHealth); 00028 } 00029 00030 std::string AddHealthCommand::getString() 00031 { 00032 List *command = new List(); 00033 command->snoc(new Atom(_id)); 00034 command->snoc(new Atom(_person->id())); 00035 command->snoc(new Atom(_dHealth)); 00036 00037 string commandString = command->getString(); 00038 delete command; 00039 00040 return commandString; 00041 }