bool Sprites::process_command (const std::string &command) throw() { if (!command.empty()) { StringTokenizer tokens (command); std::string action = tokens.get_next_string(); if (action == "add_sprite") { attach (Sprite::from_string (tokens.get_remaining_string())); return true; } else if (action == "close_all_doors") { for (std::list<Sprite*>::const_iterator s = sprites.begin(); s != sprites.end(); ++s) { Door *door = dynamic_cast<Door*> (*s); if (door) { door->set_open (false); } } // for each sprite return true; } else if (action == "open_all_doors") { for (std::list<Sprite*>::const_iterator s = sprites.begin(); s != sprites.end(); ++s) { Door *door = dynamic_cast<Door*> (*s); if (door) { door->set_open (true); } } // for each sprite return true; } else { for (std::list<Sprite*>::const_iterator s = sprites.begin(); s != sprites.end(); ++s) { Sprite &sprite = **s; if (sprite.get_id() == action.substr(0, sprite.get_id().length())) { return sprite.execute (command); break; } } } // if a particular action } return false; }