00001 #include "Command.h" 00002 #include "Person.h" 00003 #include "List.h" 00004 #include "Level.h" 00005 00006 #include <iostream> 00007 00008 using namespace std; 00009 00010 const string InvincibleCommand::_id = "invincible"; 00011 00012 InvincibleCommand::InvincibleCommand(Person *person, bool inv) 00013 :_person(person->id()),_inv(inv) 00014 { 00015 } 00016 00017 InvincibleCommand::InvincibleCommand(List *command) 00018 { 00019 command = command->rest(); 00020 _person = command->firstString(); 00021 string inv = command->rest()->firstString(); 00022 if(inv == "true") 00023 _inv = true; 00024 else 00025 _inv = false; 00026 } 00027 00028 void InvincibleCommand::execute() 00029 { 00030 ((Person *)Level::instance()->getObject(_person))->setInvincible(_inv); 00031 } 00032 00033 std::string InvincibleCommand::getString() 00034 { 00035 List *command = new List(); 00036 command->snoc(new Atom(_id)); 00037 command->snoc(new Atom(_person)); 00038 string inv; 00039 if(_inv) 00040 inv = "true"; 00041 else 00042 inv = "false"; 00043 command->snoc(new Atom(inv)); 00044 string commandString = command->getString(); 00045 delete command; 00046 00047 return commandString; 00048 }
1.4.6-NO