// // Created by tqcq on 2023/11/14. // #include "FoodObject.h" namespace tqcq { } // namespace tqcq FoodObject::FoodObject(const std::string &name, const std::string &keyword, const std::string &description, int energy) : GameObject(name, keyword, description) { object_type = Food; setEnergy(energy); } int FoodObject::getEnergy() const { return energy; } std::string FoodObject::ToString() const { Packer packer; packer.pack(GameObject::ToString()); packer.pack(energy); return packer.ToHexStr(); } void FoodObject::FromString(const std::string &str) { Packer packer; std::string game_object_hex; packer.FromHexStr(str); packer.unpack(energy); packer.unpack(game_object_hex); GameObject::FromString(game_object_hex); } FoodObject::FoodObject() : GameObject(), energy(0) { object_type = Food; } void FoodObject::setEnergy(int _energy) { _energy = std::min(_energy, 10); _energy = std::max(_energy, 1); energy = _energy; } std::string FoodObject::getInfo() const { return GameObject::getInfo() + " (" + std::to_string(energy) + ")"; }