Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools"
"ms-vscode.cmake-tools",
"ms-vscode.cpptools-extension-pack",
"franneck94.c-cpp-runner"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand Down
3 changes: 3 additions & 0 deletions src/entity.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "header/entity.h"

#include <string>
#include <iostream>

namespace envlibcpp {
Entity::Entity(std::string entityName) {
Expand Down Expand Up @@ -36,10 +37,12 @@ namespace envlibcpp {
}

void Entity::setEnvironmentId(int id) {
std::cout << "Entity::setEnvironmentId()" << std::endl;
environmentId = id;
}

void Entity::setGridId(int id) {
std::cout << "Entity::setGridId()" << std::endl;
gridId = id;
}

Expand Down
3 changes: 3 additions & 0 deletions src/environment.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "header/environment.h"

#include <iostream>

namespace envlibcpp {
Environment::Environment(std::string envName, int size) {
id = rand() % 100 + 1;
Expand All @@ -24,6 +26,7 @@ namespace envlibcpp {
}

void Environment::addEntity(Entity entity) {
std::cout << "Environment::addEntity()" << std::endl;
entity.setEnvironmentId(id);
grid.addEntity(entity);
}
Expand Down
9 changes: 5 additions & 4 deletions src/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace envlibcpp {
Grid::Grid() {
id = rand() % 100 + 1;
size = 4;
generateLocations();
Grid(4);
}

Grid::Grid(int gridSize) {
Expand All @@ -24,6 +22,7 @@ namespace envlibcpp {
}

Location Grid::getFirstLocation() {
std::cout << "Grid::getFirstLocation()" << std::endl;
return locations.front();
}

Expand Down Expand Up @@ -69,8 +68,10 @@ namespace envlibcpp {
}

void Grid::addEntity(Entity entity) {
std::cout << "Grid::addEntity()" << std::endl;
entity.setGridId(id);
getFirstLocation().addEntity(entity);
Location firstLocation = getFirstLocation();
firstLocation.addEntity(entity);
}

void Grid::addEntityToLocation(Entity entity, Location location) {
Expand Down
2 changes: 1 addition & 1 deletion src/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace envlibcpp {
id = rand() % 100 + 1;
x = xpos;
y = ypos;

}

int Location::getId() {
Expand All @@ -27,6 +26,7 @@ namespace envlibcpp {
}

void Location::addEntity(Entity entity) {
std::cout << "Location::addEntity()" << std::endl;
entity.setLocationId(getId());
entities.push_back(entity);
}
Expand Down
8 changes: 6 additions & 2 deletions src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ void testGridGeneration() {
std::cout << "Test - Grid Generation" << std::endl;
int size = 4;
Environment environment("test environment", 4);
assert(environment.getGrid().getLocations().size() == size*size);
int numLocations = environment.getGrid().getLocations().size();
int expectedNumLocations = size*size;
assert(numLocations == expectedNumLocations);
std::cout << "Success" << std::endl;
}

Expand All @@ -21,8 +23,10 @@ void testEntityPlacement() {
std::cout << "Test - Entity Placement" << std::endl;
Entity entity("Daniel");
Environment environment("Earth", 2);

environment.addEntity(entity);
assert(environment.getNumEntities() > 0);

assert(environment.isEntityPresent(entity) == true);
std::cout << "Success" << std::endl;
}

Expand Down