- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/Documents and Settings/jegan/Desktop/projectX/SetDoorLockCommand.cpp

Go to the documentation of this file.

    00001 #include "Command.h"
    00002 #include "Door.h"
    00003 #include "Level.h"
    00004 #include "List.h"
    00005
    00006 using namespace std;
    00007
    00008 const std::string SetDoorLockCommand::_id = "setDoorLock";
    00009
    00010 SetDoorLockCommand::SetDoorLockCommand(Door *door, bool locked)
    00011 :_door(door),_locked(locked)
    00012 {
    00013 }
    00014
    00015 SetDoorLockCommand::SetDoorLockCommand(List *command)
    00016 {
    00017         command = command->rest();
    00018         _door = (Door*)Level::instance()->getObject(command->firstString());
    00019         command = command->rest();
    00020         string locked = command->firstString();
    00021         if(locked == "true")
    00022                 _locked = true;
    00023         else
    00024                 _locked = false;
    00025 }
    00026
    00027 void SetDoorLockCommand::execute()
    00028 {
    00029         _door->setLock(_locked);
    00030 }
    00031
    00032 std::string SetDoorLockCommand::getString()
    00033 {
    00034         List *command = new List();
    00035         command->snoc(new Atom(_id));
    00036         command->snoc(new Atom(_door->id()));
    00037         if(_locked)
    00038                 command->snoc(new Atom("true"));
    00039         else
    00040                 command->snoc(new Atom("false"));
    00041         string commandString = command->getString();
    00042         delete command;
    00043
    00044         return commandString;
    00045 }