diff --git a/src/environment.cpp b/src/environment.cpp index d334d20..8d0656b 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -25,22 +25,22 @@ namespace envlibcpp { name = newName; } - void Environment::addEntity(Entity &entity) { + void Environment::addEntity(Entity& entity) { entity.setEnvironmentId(id); grid.addEntity(entity); } - void Environment::addEntityToLocation(Entity &entity, Location &location) { + void Environment::addEntityToLocation(Entity& entity, Location& location) { entity.setEnvironmentId(id); grid.addEntityToLocation(entity, location); } - void Environment::removeEntity(Entity &entity) { + void Environment::removeEntity(Entity& entity) { entity.setEnvironmentId(-1); grid.removeEntity(entity); } - bool Environment::isEntityPresent(Entity &entity) { + bool Environment::isEntityPresent(Entity& entity) { return grid.isEntityPresent(entity); } @@ -54,7 +54,7 @@ namespace envlibcpp { } envlibcpp::Entity& Environment::getFirstEntity() { - for (envlibcpp::Location &location : getGrid().getLocations()) { + for (envlibcpp::Location& location : getGrid().getLocations()) { if (location.getNumEntities() > 0) { return location.getEntities()[0]; } @@ -63,8 +63,8 @@ namespace envlibcpp { } envlibcpp::Entity& Environment::getEntity(int entityId) { - for (envlibcpp::Location &location : getGrid().getLocations()) { - for (envlibcpp::Entity &entity : location.getEntities()) { + for (envlibcpp::Location& location : getGrid().getLocations()) { + for (envlibcpp::Entity& entity : location.getEntities()) { if (entity.getId() == entityId) { return entity; } diff --git a/src/grid.cpp b/src/grid.cpp index e68fb0f..6d0692f 100644 --- a/src/grid.cpp +++ b/src/grid.cpp @@ -54,11 +54,11 @@ namespace envlibcpp { size = newSize; } - void Grid::addLocation(Location &location) { + void Grid::addLocation(Location& location) { locations.push_back(location); } - void Grid::removeLocation(Location &location) { + void Grid::removeLocation(Location& location) { for (auto i = locations.begin(); i != locations.end(); i++) { if (i->getId() == location.getId()) { locations.erase(i); @@ -66,13 +66,13 @@ namespace envlibcpp { } } - void Grid::addEntity(Entity &entity) { + void Grid::addEntity(Entity& entity) { entity.setGridId(id); - Location &firstLocation = getRandomLocation(); + Location& firstLocation = getRandomLocation(); firstLocation.addEntity(entity); } - void Grid::addEntityToLocation(Entity &entity, Location &location) { + void Grid::addEntityToLocation(Entity& entity, Location& location) { for (Location &l : locations) { if (l.getId() == location.getId()) { location.addEntity(entity); @@ -80,8 +80,8 @@ namespace envlibcpp { } } - void Grid::removeEntity(Entity &entity) { - for (Location &location : locations) { + void Grid::removeEntity(Entity& entity) { + for (Location& location : locations) { if (location.isEntityPresent(entity)) { location.removeEntity(entity); entity.setLocationId(-1); @@ -90,8 +90,8 @@ namespace envlibcpp { entity.setGridId(-1); } - bool Grid::isEntityPresent(Entity &entity) { - for (Location &location : locations) { + bool Grid::isEntityPresent(Entity& entity) { + for (Location& location : locations) { if (location.isEntityPresent(entity)) { return true; } @@ -100,7 +100,7 @@ namespace envlibcpp { } Location& Grid::getLocation(int locationId) { - for (Location &location : locations) { + for (Location& location : locations) { if (location.getId() == locationId) { return location; } diff --git a/src/header/environment.h b/src/header/environment.h index fee1be4..c9fcbb3 100644 --- a/src/header/environment.h +++ b/src/header/environment.h @@ -16,10 +16,10 @@ namespace envlibcpp { std::string getName(); Grid& getGrid(); void setName(std::string newName); - void addEntity(Entity &entity); - void addEntityToLocation(Entity &entity, Location &location); - void removeEntity(Entity &entity); - bool isEntityPresent(Entity &entity); + void addEntity(Entity& entity); + void addEntityToLocation(Entity& entity, Location& location); + void removeEntity(Entity& entity); + bool isEntityPresent(Entity& entity); int getNumEntities(); void printInfo(); envlibcpp::Entity& getFirstEntity(); diff --git a/src/header/grid.h b/src/header/grid.h index c369862..23e44fe 100644 --- a/src/header/grid.h +++ b/src/header/grid.h @@ -22,12 +22,12 @@ namespace envlibcpp { int getNumEntities(); void setId(int newId); void setSize(int newSize); - void addLocation(Location &location); - void removeLocation(Location &location); - void addEntity(Entity &entity); - void addEntityToLocation(Entity &entity, Location &location); - void removeEntity(Entity &entity); - bool isEntityPresent(Entity &entity); + void addLocation(Location& location); + void removeLocation(Location& location); + void addEntity(Entity& entity); + void addEntityToLocation(Entity& entity, Location& location); + void removeEntity(Entity& entity); + bool isEntityPresent(Entity& entity); Location& getLocation(int locationId); Location& getRandomLocation(); private: diff --git a/src/location.cpp b/src/location.cpp index 7e0f779..a38b65f 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -25,12 +25,12 @@ namespace envlibcpp { return entities.size(); } - void Location::addEntity(Entity &entity) { + void Location::addEntity(Entity& entity) { entity.setLocationId(getId()); entities.push_back(entity); } - void Location::removeEntity(Entity &entity) { + void Location::removeEntity(Entity& entity) { int index = -1; for (int i = 0; i < getNumEntities(); i++) { if (entities[i].getId() == entity.getId()) { @@ -44,7 +44,7 @@ namespace envlibcpp { entity.setLocationId(-1); } - bool Location::isEntityPresent(Entity &entity) { + bool Location::isEntityPresent(Entity& entity) { for (Entity &e : entities) { if (e.getId() == entity.getId()) { return true;