From ff53af41eea03a4453a3fa55c6b13306045255b4 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sat, 17 Feb 2024 00:56:32 +0100 Subject: [PATCH 01/62] Created Map.h --- include/Map.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 include/Map.h diff --git a/include/Map.h b/include/Map.h new file mode 100644 index 0000000..b8dc7ae --- /dev/null +++ b/include/Map.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include + +using tileStdMap = std::map; +using entityStdMap = std::map; + +class Map { + private: + uint16_t id_; + uint8_t currentType_; + std::string mapName_; + std::string bitmapName_; + tileStdMap tiles_; // + entityStdMap entities_;// Map + + public: + + Map(); + Map(uint16_t id, uint8_t currentType, std::string mapName, std::string bitmapName, tileStdMap tiles, entityStdMap entities); + + bool doesItCollide(uint16_t desiredX, uint16_t desiredY, uint8_t direction); + bool doesItInteract(uint16_t desiredX, uint16_t desiredY, uint8_t direction); + +} \ No newline at end of file From 58e9e9fb9bcaa735c853223e6d615f922aa064e8 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sat, 17 Feb 2024 00:56:44 +0100 Subject: [PATCH 02/62] Created Map.cpp --- src/Map.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/Map.cpp diff --git a/src/Map.cpp b/src/Map.cpp new file mode 100644 index 0000000..d8cc497 --- /dev/null +++ b/src/Map.cpp @@ -0,0 +1,17 @@ +#include "Map.h" + +Map::Map(uint16_t id, uint8_t currentType, std::string mapName, std::string bitmapName, tileStdMap tiles, entityStdMap entities) { + id_ = id; + currentType_ = currentType; + mapName_ = mapName; + bitmapName_ = bitmapName; + tiles_ = tiles; + entities_ = entities; +} + +bool Map::doesItCollide(uint16_t desiredX, uint16_t desiredY, uint8_t direction) { + +} +bool Map::doesItInteract(uint16_t desiredX, uint16_t desiredY, uint8_t direction) { + +} \ No newline at end of file From 6a0ad5f5ce3aab800ffb22bad96512e315a8cc38 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sat, 17 Feb 2024 00:57:03 +0100 Subject: [PATCH 03/62] Created test for Map --- test/MapTest.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/MapTest.cpp diff --git a/test/MapTest.cpp b/test/MapTest.cpp new file mode 100644 index 0000000..e69de29 From 8ce95b873ba8483a52a1874221c82304f6b0fb3e Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sat, 17 Feb 2024 00:57:20 +0100 Subject: [PATCH 04/62] Added Map.h and Map.cpp --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1165909..82fcf7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,11 @@ add_library( target_include_directories(pokemon-lib PUBLIC include) target_include_directories(pokemon-lib PUBLIC ${JSONCPP_INCLUDE_DIRS}) +add_library( + include/Map.h + src/Map.cpp +) + add_executable(pokemon src/main.cpp) target_link_libraries(pokemon PRIVATE ${JSONCPP_LIBRARIES}) From f238951ba688c129ad3b31731791b26db2a8d7cd Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sat, 17 Feb 2024 02:07:01 +0100 Subject: [PATCH 05/62] Added destructor and included Tile.h --- include/Map.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/Map.h b/include/Map.h index b8dc7ae..869273c 100644 --- a/include/Map.h +++ b/include/Map.h @@ -1,5 +1,7 @@ #pragma once +#include "Tile.h" + #include #include #include @@ -19,6 +21,7 @@ class Map { public: Map(); + ~Map(); Map(uint16_t id, uint8_t currentType, std::string mapName, std::string bitmapName, tileStdMap tiles, entityStdMap entities); bool doesItCollide(uint16_t desiredX, uint16_t desiredY, uint8_t direction); From 8d2e6f186aed88ce9b182dff497e661f70cd47cb Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sat, 17 Feb 2024 02:08:05 +0100 Subject: [PATCH 06/62] populated destructor, doesItCollide, doesItInteract --- src/Map.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Map.cpp b/src/Map.cpp index d8cc497..ad733af 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -7,11 +7,23 @@ Map::Map(uint16_t id, uint8_t currentType, std::string mapName, std::string bitm bitmapName_ = bitmapName; tiles_ = tiles; entities_ = entities; + } -bool Map::doesItCollide(uint16_t desiredX, uint16_t desiredY, uint8_t direction) { +Map::~Map() { + tiles_.clear(); + entities_.clear(); } + +bool Map::doesItCollide(uint16_t desiredX, uint16_t desiredY, uint8_t direction) { + tile::Tile tile = tiles_.at( std::pair (desiredX, desiredY) ); + return tile.isCollision(direction); + +} + bool Map::doesItInteract(uint16_t desiredX, uint16_t desiredY, uint8_t direction) { + tile::Tile tile = tiles_.at( std::pair (desiredX, desiredY) ); + return tile.isInteraction(direction); } \ No newline at end of file From 09b2ef296e54973084bf9460e1044319811b8059 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sat, 17 Feb 2024 02:09:43 +0100 Subject: [PATCH 07/62] Imported prototype test map definition. --- test/MapTest.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/MapTest.cpp b/test/MapTest.cpp index e69de29..c77f48e 100644 --- a/test/MapTest.cpp +++ b/test/MapTest.cpp @@ -0,0 +1,38 @@ +#include "Map.h" + +int main() { + std::cout<<"hello Map"< testVectorMap1 = { 9, 9, 9, 9, 9, 9, 9, 9, 9}; + std::vector testVectorMap2 = { 9, 0, 0, 0, 0, 0, 0, 0, 100}; + std::vector testVectorMap3 = { 9, 0, 0, 0, 0, 0, 0, 0, 9}; + std::vector testVectorMap4 = { 9, 0, 0, 0, 0, 0, 9, -1, 9}; + std::vector testVectorMap5 = { 9, 0, 0, 0, 0, 0, 9, 9, 9}; + std::vector testVectorMap6 = { 9, 0, 0, 0, 0, 0, 0, 0, 9}; + std::vector testVectorMap7 = { 9, 0, 0, 0, 100, 9, 0, 0, 9}; + std::vector testVectorMap8 = { 9, 0, 0, 0, 0, 0, 0, 100, 9}; + std::vector testVectorMap9 = { 9, 0, 0, 0, 0, 0, 0, 100, 9}; + std::vector testVectorMap10 = { 9, 0, 0, 0, 0, 0, 0, 9, 9}; + std::vector testVectorMap11 = { 9, 0, 0, 100, 100, 0, 0, 9, 9}; + std::vector testVectorMap12 = { 9, 0, 0, 0, 0, 0, 0, 100, 9}; + std::vector testVectorMap13 = { 9, 9, 9, 9, 9, 9, 9, 9, 9}; + + std::vector> testVectorMap; + + testVectorMap.push_back(testVectorMap1); + testVectorMap.push_back(testVectorMap2); + testVectorMap.push_back(testVectorMap3); + testVectorMap.push_back(testVectorMap4); + testVectorMap.push_back(testVectorMap5); + testVectorMap.push_back(testVectorMap6); + testVectorMap.push_back(testVectorMap7); + testVectorMap.push_back(testVectorMap8); + testVectorMap.push_back(testVectorMap9); + testVectorMap.push_back(testVectorMap10); + testVectorMap.push_back(testVectorMap11); + testVectorMap.push_back(testVectorMap12); + testVectorMap.push_back(testVectorMap13); + + Map testMap(testVectorMap, "testMap"); + +} \ No newline at end of file From 10ca6b495c005d15452f25b8cb7d11f17c80172c Mon Sep 17 00:00:00 2001 From: Michele Michetti <92488318+MicheleMichetti@users.noreply.github.com> Date: Sat, 17 Feb 2024 00:37:59 +0100 Subject: [PATCH 08/62] doc: Update README.md --- Docker/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Docker/README.md b/Docker/README.md index 7208856..b9c93be 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -10,11 +10,12 @@ Our development philosophy with Docker is the following. - Windows: ```$ .\Docker\windows\build_docker_image.bat``` -The image that contains the `Ubuntu-latest` environment for our application is created at this point. You can double check by running the command `$ docker images`. + + The image that contains the `Ubuntu-latest` environment for our application is created at this point. You can double check by running the command `$ docker images`. -2. docker run -it "pokemon-container" +2. ```docker run -it "pokemon-image"``` 3. Next question you should be asking yourself is: What about the source code and the compilation? The folder `Re-Pokemon-Red/Testing` will contain a script for each test that will do `docker run ...` Step two will be much more frequent during the development process since it will be called each time we want to test our new code. -3. +4. From 07ccf1861a5b7a1721b6df804961b97b37e273fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 01:23:24 +0100 Subject: [PATCH 09/62] Update README.md --- Docker/README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Docker/README.md b/Docker/README.md index b9c93be..10080fa 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -1,6 +1,13 @@ # Docker -Our development philosophy with Docker is the following. +In this project we will use docker to compile, test and run our game. It would be quite helpful to quickly check a [guide like on Docker](https://phoenixnap.com/kb/docker-image-vs-container). In this `Readme`, we explain the different steps we take to run our code inside a Docker container. + +### Quick overview +1. Building Docker image with the project dependencies +2. Development mode: Opening a shell inside the container. +3. Test mode + +### Details 1. We build an image that contains all the necessary dependencies to compile the application. This image only needs to be created once as long as the dependencies do not change (very rarely). **This step does not compile the game**. - Linux and MacOS: @@ -11,11 +18,8 @@ Our development philosophy with Docker is the following. ```$ .\Docker\windows\build_docker_image.bat``` - The image that contains the `Ubuntu-latest` environment for our application is created at this point. You can double check by running the command `$ docker images`. - -2. ```docker run -it "pokemon-image"``` + At this point we have created an Docker image based on `Ubuntu-latest`. You can double check by executing `$ docker images` and hopefully find that a container called `pokemon-image`. -3. Next question you should be asking yourself is: What about the source code and the compilation? The folder `Re-Pokemon-Red/Testing` will contain a script for each test that will do `docker run ...` +2. From the root directory of our project run `$ docker run -it -v .:/pokemon_game "pokemon-image"`. This will run the docker image `"pokemon-image"` with the source code included as a [mounted volume](https://docs.docker.com/storage/volumes/). Inside this docker image you can manually compile the project as usual with: `mkdir build; cd build; cmake ..; make;`. Note: While you are developing, you can keep this shell open. Since your local machine files are synch with the docker's image thanks to `-v .:/pokemon_game`. The most comfortable workflow should be: `Write changes locally, Run make in the docker image, run the program, repeat` - Step two will be much more frequent during the development process since it will be called each time we want to test our new code. -4. +3. Test mode: TBD From 3f9de8a697a01739904c34ffc1dd650d0ceb1122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 01:24:24 +0100 Subject: [PATCH 10/62] doc: Update README.md --- Docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docker/README.md b/Docker/README.md index 10080fa..ce44533 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -20,6 +20,6 @@ In this project we will use docker to compile, test and run our game. It would b At this point we have created an Docker image based on `Ubuntu-latest`. You can double check by executing `$ docker images` and hopefully find that a container called `pokemon-image`. -2. From the root directory of our project run `$ docker run -it -v .:/pokemon_game "pokemon-image"`. This will run the docker image `"pokemon-image"` with the source code included as a [mounted volume](https://docs.docker.com/storage/volumes/). Inside this docker image you can manually compile the project as usual with: `mkdir build; cd build; cmake ..; make;`. Note: While you are developing, you can keep this shell open. Since your local machine files are synch with the docker's image thanks to `-v .:/pokemon_game`. The most comfortable workflow should be: `Write changes locally, Run make in the docker image, run the program, repeat` +2. From the root directory of our project run `$ docker run -it -v .:/pokemon_game "pokemon-image"`. This will run the docker image `"pokemon-image"` with the source code included as a [mounted volume](https://docs.docker.com/storage/volumes/). Inside this docker image you can manually compile the project as usual with: `mkdir build; cd build; cmake ..; make;`. Note: While you are developing, you can keep this shell open. Since your local machine files are synched with the docker's image thanks to `-v .:/pokemon_game`. The most comfortable workflow should be: `Write changes locally, Run make in the docker image, run the program, repeat` 3. Test mode: TBD From 1e3bc7ebfb55d4bff9451e3aa5f81432f52df0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 01:24:50 +0100 Subject: [PATCH 11/62] doc: Update README.md --- Docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docker/README.md b/Docker/README.md index ce44533..a56d942 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -20,6 +20,6 @@ In this project we will use docker to compile, test and run our game. It would b At this point we have created an Docker image based on `Ubuntu-latest`. You can double check by executing `$ docker images` and hopefully find that a container called `pokemon-image`. -2. From the root directory of our project run `$ docker run -it -v .:/pokemon_game "pokemon-image"`. This will run the docker image `"pokemon-image"` with the source code included as a [mounted volume](https://docs.docker.com/storage/volumes/). Inside this docker image you can manually compile the project as usual with: `mkdir build; cd build; cmake ..; make;`. Note: While you are developing, you can keep this shell open. Since your local machine files are synched with the docker's image thanks to `-v .:/pokemon_game`. The most comfortable workflow should be: `Write changes locally, Run make in the docker image, run the program, repeat` +2. From the root directory of our project run `$ docker run -it -v .:/pokemon_game "pokemon-image"`. This will run the docker image `"pokemon-image"` with the source code included as a [mounted volume](https://docs.docker.com/storage/volumes/). Inside this docker image you can manually compile the project as usual with: `mkdir build; cd build; cmake ..; make;`. Note: While you are developing, you can keep this shell open. Since your local machine files are synched with the docker's image thanks to `-v .:/pokemon_game`. The most comfortable workflow should be: `Write changes locally, run make in the docker image, run the program, repeat` 3. Test mode: TBD From 8e97c0a9269346945129eae349efbdf4db373514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 01:49:08 +0100 Subject: [PATCH 12/62] feat: Pull request template --- .github/PULL_REQUEST_TEMPLATE.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..2231301 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,3 @@ +Doneness: +- [ ] Testing +- [ ] Documentation \ No newline at end of file From 71175ed2e2a03e57d392b65d009b0545293e9e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 01:52:19 +0100 Subject: [PATCH 13/62] feat: Update PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2231301..5528e4f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,3 +1,3 @@ -Doneness: +Doneness checkbox: - [ ] Testing -- [ ] Documentation \ No newline at end of file +- [ ] Documentation From 9386af1656885a392920e48da06d44d04215f209 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 00:53:39 +0100 Subject: [PATCH 14/62] switched tiles_ from std::map to boost::multi_array. --- include/Map.h | 29 +++++++++++++++---- src/Map.cpp | 74 ++++++++++++++++++++++++++++++++++++++++-------- test/MapTest.cpp | 32 --------------------- 3 files changed, 86 insertions(+), 49 deletions(-) diff --git a/include/Map.h b/include/Map.h index 869273c..a7d5c88 100644 --- a/include/Map.h +++ b/include/Map.h @@ -6,7 +6,7 @@ #include #include -using tileStdMap = std::map; +using tileArray = boost::multi_array; using entityStdMap = std::map; class Map { @@ -15,16 +15,35 @@ class Map { uint8_t currentType_; std::string mapName_; std::string bitmapName_; - tileStdMap tiles_; // + tileArray tiles_; // entityStdMap entities_;// Map public: Map(); + Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityStdMap &entities); ~Map(); - Map(uint16_t id, uint8_t currentType, std::string mapName, std::string bitmapName, tileStdMap tiles, entityStdMap entities); - bool doesItCollide(uint16_t desiredX, uint16_t desiredY, uint8_t direction); - bool doesItInteract(uint16_t desiredX, uint16_t desiredY, uint8_t direction); + void setId(const uint16_t &id); + void setCurrentType(const uint8_t ¤tType); + void setMapName(const std::string &mapName); + void setBitmapName(const std::string &bitmapName); + void setTiles(const tileArray tiles, const uint16_t &dimensionX, const uint16_t &dimensionY); + void setEntities(const entityStdMap &entities); + void setTile(const utils::Coordinate &coordinate, const Tile &tile); + + const uint16_t getId(); + const uint8_t getCurrentType(); + const std::string getMapName(); + const std::string getBitmapName(); + const tileArray getTiles(); + const entityStdMap getEntities(); + + void swapTiles(Tile tile1, Tile Tile2); + + bool doesItCollide(const tils::Coordinate &coordinate, const uint8_t &direction); + bool doesItInteract(const utils::Coordinate &coordinate, const uint8_t &direction); + bool isPokemonBattleTriggered(); + bool isTrainerBattleTriggered(); } \ No newline at end of file diff --git a/src/Map.cpp b/src/Map.cpp index ad733af..4080ff2 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -1,29 +1,79 @@ #include "Map.h" -Map::Map(uint16_t id, uint8_t currentType, std::string mapName, std::string bitmapName, tileStdMap tiles, entityStdMap entities) { - id_ = id; - currentType_ = currentType; - mapName_ = mapName; - bitmapName_ = bitmapName; - tiles_ = tiles; - entities_ = entities; +Map::Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityStdMap &entities) { + setId(id); + setCurrentType(currentType); + setMapName(mapName); + setBitmapName(bitmapName); + setTiles(tiles, dimensionX, dimensionY); + setEntities(entities); } Map::~Map() { - tiles_.clear(); entities_.clear(); } -bool Map::doesItCollide(uint16_t desiredX, uint16_t desiredY, uint8_t direction) { - tile::Tile tile = tiles_.at( std::pair (desiredX, desiredY) ); +void Map::setId(const uint16_t &id) { + this->id_ = id; +} +void Map::setCurrentType(const uint8_t ¤tType) { + this->currentType_ currentType; +} +void Map::setMapName(const std::string &mapName) { + this->mapName_ = mapName; +} +void Map::setBitmapName(const std::string &bitmapName) { + this->bitmapName_ = bitmapName; +} +void Map::setTiles(const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY) { + if(dimensionX == 0 || dimensionY == 0) { + return; + } + tiles_.resize(boost::extents[dimensionX][dimensionY]); + this->tiles_ = tiles; +} +void Map::setEntities(const entityStdMap &entities) { + this->entities_ = entities; +} +void Map::setTile(const utils::Coordinate &coordinate, const Tile &tile) { + tiles_[coordinate.x][coordinate.y] = tile; +} + +const uint16_t Map::getId() { + return id_; +} +const uint8_t Map::getCurrentType() { + return currentType_; +} +const std::string Map::getMapName() { + return mapName_; +} +const std::string Map::getBitmapName() { + return bitmapName_; +} +const tileStdMap Map::getTiles() { + return tiles_; +} +const entityStdMap Map::getEntities() { + return entities_; +} + +void Map::swapTiles(Tile &tile1, Tile &tile2) { + tileArray tiletmp = tile1; + tile1 = tile2; + tile2 = tiletmp; +} + +bool Map::doesItCollide(const utils::Coordinate &coordinate, const uint8_t &direction) { + Tile tile = tiles_[coordinate.x][coordinate.y]; return tile.isCollision(direction); } -bool Map::doesItInteract(uint16_t desiredX, uint16_t desiredY, uint8_t direction) { - tile::Tile tile = tiles_.at( std::pair (desiredX, desiredY) ); +bool Map::doesItInteract(const utils::Coordinate &coordinate, const uint8_t &direction) { + Tile tile = tiles_[coordinate.x][coordinate.y]; return tile.isInteraction(direction); } \ No newline at end of file diff --git a/test/MapTest.cpp b/test/MapTest.cpp index c77f48e..cc6ee5f 100644 --- a/test/MapTest.cpp +++ b/test/MapTest.cpp @@ -3,36 +3,4 @@ int main() { std::cout<<"hello Map"< testVectorMap1 = { 9, 9, 9, 9, 9, 9, 9, 9, 9}; - std::vector testVectorMap2 = { 9, 0, 0, 0, 0, 0, 0, 0, 100}; - std::vector testVectorMap3 = { 9, 0, 0, 0, 0, 0, 0, 0, 9}; - std::vector testVectorMap4 = { 9, 0, 0, 0, 0, 0, 9, -1, 9}; - std::vector testVectorMap5 = { 9, 0, 0, 0, 0, 0, 9, 9, 9}; - std::vector testVectorMap6 = { 9, 0, 0, 0, 0, 0, 0, 0, 9}; - std::vector testVectorMap7 = { 9, 0, 0, 0, 100, 9, 0, 0, 9}; - std::vector testVectorMap8 = { 9, 0, 0, 0, 0, 0, 0, 100, 9}; - std::vector testVectorMap9 = { 9, 0, 0, 0, 0, 0, 0, 100, 9}; - std::vector testVectorMap10 = { 9, 0, 0, 0, 0, 0, 0, 9, 9}; - std::vector testVectorMap11 = { 9, 0, 0, 100, 100, 0, 0, 9, 9}; - std::vector testVectorMap12 = { 9, 0, 0, 0, 0, 0, 0, 100, 9}; - std::vector testVectorMap13 = { 9, 9, 9, 9, 9, 9, 9, 9, 9}; - - std::vector> testVectorMap; - - testVectorMap.push_back(testVectorMap1); - testVectorMap.push_back(testVectorMap2); - testVectorMap.push_back(testVectorMap3); - testVectorMap.push_back(testVectorMap4); - testVectorMap.push_back(testVectorMap5); - testVectorMap.push_back(testVectorMap6); - testVectorMap.push_back(testVectorMap7); - testVectorMap.push_back(testVectorMap8); - testVectorMap.push_back(testVectorMap9); - testVectorMap.push_back(testVectorMap10); - testVectorMap.push_back(testVectorMap11); - testVectorMap.push_back(testVectorMap12); - testVectorMap.push_back(testVectorMap13); - - Map testMap(testVectorMap, "testMap"); - } \ No newline at end of file From 6a477ca183365a652edd527fea6741ddaece2ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 00:29:40 +0100 Subject: [PATCH 15/62] feat: Tile class basic structure --- include/Tile.hpp | 24 ++++++++++++++++++++++++ include/utils.hpp | 12 ++++++++++++ src/Tile.cpp | 17 +++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 include/Tile.hpp create mode 100644 include/utils.hpp create mode 100644 src/Tile.cpp diff --git a/include/Tile.hpp b/include/Tile.hpp new file mode 100644 index 0000000..205d700 --- /dev/null +++ b/include/Tile.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +class Tile { + public: + Tile(); + ~Tile(); + bool isCollision(utils::Direction direction); + bool isInteraction(utils::Direction direction); + + private: + int x_pos; + int y_pos; + bool collidesFromAbove(); + bool collidesFromBelow(); + bool collidesFromRight(); + bool collidesFromLeft(); + + bool interactsFromAbove(); + bool interactsFromBelow(); + bool interactsFromRight(); + bool interactsFromLeft(); +}; \ No newline at end of file diff --git a/include/utils.hpp b/include/utils.hpp new file mode 100644 index 0000000..9f2652b --- /dev/null +++ b/include/utils.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace utils { + typedef enum Direction : uint8_t { + up = 0x00, + down, + left, + right, + } +} diff --git a/src/Tile.cpp b/src/Tile.cpp new file mode 100644 index 0000000..ed54894 --- /dev/null +++ b/src/Tile.cpp @@ -0,0 +1,17 @@ +#include + +Tile::Tile() {} +Tile::~Tile() {} + +bool Tile::isCollision(utils::Direction direction) {} +bool Tile::isInteraction(utils::Direction direction) {} + +bool Tile::collidesFromAbove() {} +bool Tile::collidesFromBelow() {} +bool Tile::collidesFromRight() {} +bool Tile::collidesFromLeft() {} + +bool Tile::interactsFromAbove() {} +bool Tile::interactsFromBelow() {} +bool Tile::interactsFromRight() {} +bool Tile::interactsFromLeft() {} \ No newline at end of file From 06f8d35562f0c57b57d61bd94e817d8e40c3c5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 00:33:30 +0100 Subject: [PATCH 16/62] feat: Update gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 259148f..2c2f89c 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ *.exe *.out *.app + +# Vscode +c_cpp_properties.json +settings.json \ No newline at end of file From 79b3916bfa828332cd93f58d30f796a09aeee32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 00:52:08 +0100 Subject: [PATCH 17/62] feat: Tile class logic --- include/Tile.hpp | 20 +++++++------------- include/utils.hpp | 10 +++++----- src/Tile.cpp | 24 ++++++++++++------------ 3 files changed, 24 insertions(+), 30 deletions(-) diff --git a/include/Tile.hpp b/include/Tile.hpp index 205d700..b269b1f 100644 --- a/include/Tile.hpp +++ b/include/Tile.hpp @@ -4,21 +4,15 @@ class Tile { public: - Tile(); + Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask); ~Tile(); - bool isCollision(utils::Direction direction); - bool isInteraction(utils::Direction direction); + bool isCollision(utils::Direction player_direction); + bool isInteraction(utils::Direction player_direction); private: - int x_pos; - int y_pos; - bool collidesFromAbove(); - bool collidesFromBelow(); - bool collidesFromRight(); - bool collidesFromLeft(); + int x_pos_; + int y_pos_; - bool interactsFromAbove(); - bool interactsFromBelow(); - bool interactsFromRight(); - bool interactsFromLeft(); + uint8_t collision_directions_bitmask_; + uint8_t interaction_directions_bitmask_; }; \ No newline at end of file diff --git a/include/utils.hpp b/include/utils.hpp index 9f2652b..64fc510 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -4,9 +4,9 @@ namespace utils { typedef enum Direction : uint8_t { - up = 0x00, - down, - left, - right, - } + up = 0x0001, + down = 0x0010, + left = 0x0100, + right = 0x1000, + }; } diff --git a/src/Tile.cpp b/src/Tile.cpp index ed54894..e1bd912 100644 --- a/src/Tile.cpp +++ b/src/Tile.cpp @@ -1,17 +1,17 @@ #include +#include -Tile::Tile() {} -Tile::~Tile() {} +Tile::Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask) { + this->collision_directions_bitmask_ = collision_directions_bitmask; + this->interaction_directions_bitmask_ = interaction_directions_bitmask; +} -bool Tile::isCollision(utils::Direction direction) {} -bool Tile::isInteraction(utils::Direction direction) {} +Tile::~Tile() {} -bool Tile::collidesFromAbove() {} -bool Tile::collidesFromBelow() {} -bool Tile::collidesFromRight() {} -bool Tile::collidesFromLeft() {} +bool Tile::isCollision(utils::Direction player_direction) { + return player_direction & this->collision_directions_bitmask_; +} -bool Tile::interactsFromAbove() {} -bool Tile::interactsFromBelow() {} -bool Tile::interactsFromRight() {} -bool Tile::interactsFromLeft() {} \ No newline at end of file +bool Tile::isInteraction(utils::Direction player_direction) { + return player_direction & this->interaction_directions_bitmask_; +} \ No newline at end of file From 783473f0676677dd7104f40284550fb8f82e86d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 00:56:41 +0100 Subject: [PATCH 18/62] feat: Include coordinate into Tile class --- include/Tile.hpp | 7 +++---- include/utils.hpp | 6 ++++++ src/Tile.cpp | 7 ++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/Tile.hpp b/include/Tile.hpp index b269b1f..367b9d2 100644 --- a/include/Tile.hpp +++ b/include/Tile.hpp @@ -4,15 +4,14 @@ class Tile { public: - Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask); + Tile(utils::Coordinate coordinate, uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask); ~Tile(); bool isCollision(utils::Direction player_direction); bool isInteraction(utils::Direction player_direction); + utils::Coordinate getCoordinate(); private: - int x_pos_; - int y_pos_; - + utils::Coordinate coordinate_; uint8_t collision_directions_bitmask_; uint8_t interaction_directions_bitmask_; }; \ No newline at end of file diff --git a/include/utils.hpp b/include/utils.hpp index 64fc510..793c558 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -3,6 +3,12 @@ #include namespace utils { + struct Coordinate + { + int x; + int y; + }; + typedef enum Direction : uint8_t { up = 0x0001, down = 0x0010, diff --git a/src/Tile.cpp b/src/Tile.cpp index e1bd912..448d19d 100644 --- a/src/Tile.cpp +++ b/src/Tile.cpp @@ -1,13 +1,18 @@ #include #include -Tile::Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask) { +Tile::Tile(utils::Coordinate coordinate, uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask) { + this->coordinate_ = coordinate; this->collision_directions_bitmask_ = collision_directions_bitmask; this->interaction_directions_bitmask_ = interaction_directions_bitmask; } Tile::~Tile() {} +utils::Coordinate Tile::getCoordinate() { + return this->coordinate_; +} + bool Tile::isCollision(utils::Direction player_direction) { return player_direction & this->collision_directions_bitmask_; } From 1023daa3a9c099642d91b5b66b5ec208d0a489ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 01:08:37 +0100 Subject: [PATCH 19/62] refactor: Coordinate not needed for tile --- include/Tile.hpp | 3 +-- src/Tile.cpp | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/include/Tile.hpp b/include/Tile.hpp index 367b9d2..d5d8fec 100644 --- a/include/Tile.hpp +++ b/include/Tile.hpp @@ -4,14 +4,13 @@ class Tile { public: - Tile(utils::Coordinate coordinate, uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask); + Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask); ~Tile(); bool isCollision(utils::Direction player_direction); bool isInteraction(utils::Direction player_direction); utils::Coordinate getCoordinate(); private: - utils::Coordinate coordinate_; uint8_t collision_directions_bitmask_; uint8_t interaction_directions_bitmask_; }; \ No newline at end of file diff --git a/src/Tile.cpp b/src/Tile.cpp index 448d19d..e1bd912 100644 --- a/src/Tile.cpp +++ b/src/Tile.cpp @@ -1,18 +1,13 @@ #include #include -Tile::Tile(utils::Coordinate coordinate, uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask) { - this->coordinate_ = coordinate; +Tile::Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask) { this->collision_directions_bitmask_ = collision_directions_bitmask; this->interaction_directions_bitmask_ = interaction_directions_bitmask; } Tile::~Tile() {} -utils::Coordinate Tile::getCoordinate() { - return this->coordinate_; -} - bool Tile::isCollision(utils::Direction player_direction) { return player_direction & this->collision_directions_bitmask_; } From 9735180199300a32ffa86eabf8db8dd42d5240ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 01:38:31 +0100 Subject: [PATCH 20/62] fix: Direction enum utils.hpp --- include/utils.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/utils.hpp b/include/utils.hpp index 793c558..09bc07c 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -10,9 +10,9 @@ namespace utils { }; typedef enum Direction : uint8_t { - up = 0x0001, - down = 0x0010, - left = 0x0100, - right = 0x1000, + up = 0b00000001, + down = 0b00000010, + left = 0b00000100, + right = 0b00001000, }; } From 72fc2ec90a8e2de8d6112cec3a8a01b7f9626d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 02:02:53 +0100 Subject: [PATCH 21/62] feat: Skeleton of testing capabilities --- test/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 test/README.md diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..3c3e1a8 --- /dev/null +++ b/test/README.md @@ -0,0 +1,3 @@ +# Testing practices and guidelines + +TODO: Follow https://google.github.io/googletest/ From be446c350637675d4510ec2e04a82a46e2de7ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 02:03:44 +0100 Subject: [PATCH 22/62] feat: Testing skeleton --- test/integration-test/README.md | 1 + test/ut/README.md | 1 + 2 files changed, 2 insertions(+) create mode 100644 test/integration-test/README.md create mode 100644 test/ut/README.md diff --git a/test/integration-test/README.md b/test/integration-test/README.md new file mode 100644 index 0000000..11b88fa --- /dev/null +++ b/test/integration-test/README.md @@ -0,0 +1 @@ +# Integration tests \ No newline at end of file diff --git a/test/ut/README.md b/test/ut/README.md new file mode 100644 index 0000000..4d46ee5 --- /dev/null +++ b/test/ut/README.md @@ -0,0 +1 @@ +# Unit tests \ No newline at end of file From f933a284cd178b2f09758815d415f4a9dcbceb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 12:43:44 +0100 Subject: [PATCH 23/62] fix: Add execution permissions for build_docker_image.sh --- Docker/unix/build_docker_image.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 Docker/unix/build_docker_image.sh diff --git a/Docker/unix/build_docker_image.sh b/Docker/unix/build_docker_image.sh old mode 100644 new mode 100755 From 1a3f5840b516a81d27be91453040085890f444a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 13:11:29 +0100 Subject: [PATCH 24/62] feat: Update gitignore --- .gitignore | 5 ++++- include/Map.hpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/Map.cpp | 8 ++++---- 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 include/Map.hpp diff --git a/.gitignore b/.gitignore index 2c2f89c..657cd61 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,7 @@ # Vscode c_cpp_properties.json -settings.json \ No newline at end of file +settings.json + +# Directory +build/* diff --git a/include/Map.hpp b/include/Map.hpp new file mode 100644 index 0000000..a0de56a --- /dev/null +++ b/include/Map.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include "Tile.hpp" + +#include +#include +#include + +using tileArray = boost::multi_array; +using entityMap = std::map; + +class Map { + private: + uint16_t id_; + uint8_t currentType_; + std::string mapName_; + std::string bitmapName_; + tileArray tiles_; + entityMap entities_; + + public: + + Map(); + Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities); + ~Map(); + + void setId(const uint16_t &id); + void setCurrentType(const uint8_t ¤tType); + void setMapName(const std::string &mapName); + void setBitmapName(const std::string &bitmapName); + void setTiles(const tileArray tiles, const uint16_t &dimensionX, const uint16_t &dimensionY); + void setEntities(const entityMap &entities); + void setTile(const utils::Coordinate &coordinate, const Tile &tile); + + const uint16_t getId(); + const uint8_t getCurrentType(); + const std::string getMapName(); + const std::string getBitmapName(); + const tileArray getTiles(); + const entityMap getEntities(); + + void swapTiles(Tile tile1, Tile Tile2); + + bool doesItCollide(const tils::Coordinate &coordinate, const uint8_t &direction); + bool doesItInteract(const utils::Coordinate &coordinate, const uint8_t &direction); + bool isPokemonBattleTriggered(); + bool isTrainerBattleTriggered(); + +} \ No newline at end of file diff --git a/src/Map.cpp b/src/Map.cpp index 4080ff2..781e679 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -1,6 +1,6 @@ #include "Map.h" -Map::Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityStdMap &entities) { +Map::Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities) { setId(id); setCurrentType(currentType); setMapName(mapName); @@ -34,7 +34,7 @@ void Map::setTiles(const tileArray &tiles, const uint16_t &dimensionX, const uin tiles_.resize(boost::extents[dimensionX][dimensionY]); this->tiles_ = tiles; } -void Map::setEntities(const entityStdMap &entities) { +void Map::setEntities(const entityMap &entities) { this->entities_ = entities; } void Map::setTile(const utils::Coordinate &coordinate, const Tile &tile) { @@ -53,10 +53,10 @@ const std::string Map::getMapName() { const std::string Map::getBitmapName() { return bitmapName_; } -const tileStdMap Map::getTiles() { +const tileArray Map::getTiles() { return tiles_; } -const entityStdMap Map::getEntities() { +const entityMap Map::getEntities() { return entities_; } From 11f5d0b3cda89f78c4b65384fff9329791f4446e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 13:12:33 +0100 Subject: [PATCH 25/62] feat: Add google test library --- Docker/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Docker/Dockerfile b/Docker/Dockerfile index 0c98993..02c7853 100644 --- a/Docker/Dockerfile +++ b/Docker/Dockerfile @@ -20,5 +20,6 @@ RUN apt-get install liballegro5-dev -y RUN apt-get install libjsoncpp-dev -y RUN apt-get install g++ -y RUN apt-get install pkgconf -y +RUN apt-get install libgtest-dev -y WORKDIR /pokemon_game \ No newline at end of file From 3f9603f0f6c6f53f5cf9a4003e76b14df932adcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 13:41:04 +0100 Subject: [PATCH 26/62] feat: Add Json reader --- game/include/JsonReader.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 game/include/JsonReader.hpp diff --git a/game/include/JsonReader.hpp b/game/include/JsonReader.hpp new file mode 100644 index 0000000..5705ead --- /dev/null +++ b/game/include/JsonReader.hpp @@ -0,0 +1,16 @@ +#pragma once +#include + +#include +#include + +class JsonReader { + private: + Json::Value root; + + public: + JsonReader(std::string fileName_); + Json::Value getRoot(); + + int getIntValue(std::string object, std::string property, int defaultValue); +}; \ No newline at end of file From 58e280140f6d53c1db041f5e2d0ce7e38874344e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 13:44:02 +0100 Subject: [PATCH 27/62] feat: CMakeLists.txt new hierarchy --- CMakeLists.txt | 26 ++++---------------------- game/CMakeLists.txt | 22 ++++++++++++++++++++++ tests/CMakeLists.txt | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 game/CMakeLists.txt create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 82fcf7d..4d80134 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,9 @@ cmake_minimum_required(VERSION 3.27) -project(Pokemon_Project VERSION 999.0.0) +project("Pokemon_Project" VERSION 999.0.0) set(CMAKE_CXX_STANDARD 17) -find_package(PkgConfig REQUIRED) +add_subdirectory(game) +add_subdirectory(tests) -pkg_check_modules(ALLEGRO REQUIRED allegro-5 allegro_font-5 allegro_ttf-5 allegro_image-5 allegro_primitives-5) -pkg_check_modules(JSONCPP REQUIRED jsoncpp) - -add_library( - pokemon-lib SHARED - src/main.cpp -) - -target_include_directories(pokemon-lib PUBLIC include) -target_include_directories(pokemon-lib PUBLIC ${JSONCPP_INCLUDE_DIRS}) - -add_library( - include/Map.h - src/Map.cpp -) - -add_executable(pokemon src/main.cpp) - -target_link_libraries(pokemon PRIVATE ${JSONCPP_LIBRARIES}) -target_link_libraries(pokemon PRIVATE ${ALLEGRO_LIBRARIES}) +add_executable(pokemon game/src/main.cpp) target_link_libraries(pokemon PRIVATE pokemon-lib) \ No newline at end of file diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt new file mode 100644 index 0000000..0bb2f33 --- /dev/null +++ b/game/CMakeLists.txt @@ -0,0 +1,22 @@ +find_package(PkgConfig REQUIRED) + +file(GLOB SRC_FILES + src/*.cpp + include/*.hpp +) + +add_library( + pokemon-lib SHARED + ${SRC_FILES} +) + +set_target_properties(pokemon-lib PROPERTIES LINKER_LANGUAGE CXX) + +pkg_check_modules(ALLEGRO REQUIRED allegro-5 allegro_font-5 allegro_ttf-5 allegro_image-5 allegro_primitives-5) +pkg_check_modules(JSONCPP REQUIRED jsoncpp) + +target_include_directories(pokemon-lib PUBLIC include) +target_include_directories(pokemon-lib PUBLIC ${JSONCPP_INCLUDE_DIRS}) + +target_link_libraries(pokemon-lib PRIVATE ${JSONCPP_LIBRARIES}) +target_link_libraries(pokemon-lib PRIVATE ${ALLEGRO_LIBRARIES}) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..e592853 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,18 @@ +find_package(PkgConfig REQUIRED) +pkg_search_module(GTEST REQUIRED gtest_main) + +add_executable(pokemon-tests) + +file(GLOB TEST_FILES + unit-tests/*.hpp + unit-tests/*.cpp + integration-tests/*.hpp + integration-tests/*.cpp +) + +target_sources(pokemon-tests PRIVATE ${TEST_FILES}) + +target_link_libraries(pokemon-tests PRIVATE ${GTEST_LDFLAGS}) +target_compile_options(pokemon-tests PRIVATE ${GTEST_CFLAGS}) + +enable_testing() \ No newline at end of file From 230fc770a3d9de6f8404758a07d23fb4d1debae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 13:44:39 +0100 Subject: [PATCH 28/62] refactor: Re-organize code structure --- {src => game/src}/Map.cpp | 2 +- {src => game/src}/Tile.cpp | 0 {src => game/src}/main.cpp | 0 test/README.md | 3 --- test/ut/README.md | 1 - tests/README.md | 2 ++ {test/integration-test => tests/integration-tests}/README.md | 0 tests/unit-tests/README.md | 1 + 8 files changed, 4 insertions(+), 5 deletions(-) rename {src => game/src}/Map.cpp (98%) rename {src => game/src}/Tile.cpp (100%) rename {src => game/src}/main.cpp (100%) delete mode 100644 test/README.md delete mode 100644 test/ut/README.md create mode 100644 tests/README.md rename {test/integration-test => tests/integration-tests}/README.md (100%) create mode 100644 tests/unit-tests/README.md diff --git a/src/Map.cpp b/game/src/Map.cpp similarity index 98% rename from src/Map.cpp rename to game/src/Map.cpp index 781e679..93f8601 100644 --- a/src/Map.cpp +++ b/game/src/Map.cpp @@ -19,7 +19,7 @@ void Map::setId(const uint16_t &id) { this->id_ = id; } void Map::setCurrentType(const uint8_t ¤tType) { - this->currentType_ currentType; + this->currentType_ = currentType; } void Map::setMapName(const std::string &mapName) { this->mapName_ = mapName; diff --git a/src/Tile.cpp b/game/src/Tile.cpp similarity index 100% rename from src/Tile.cpp rename to game/src/Tile.cpp diff --git a/src/main.cpp b/game/src/main.cpp similarity index 100% rename from src/main.cpp rename to game/src/main.cpp diff --git a/test/README.md b/test/README.md deleted file mode 100644 index 3c3e1a8..0000000 --- a/test/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Testing practices and guidelines - -TODO: Follow https://google.github.io/googletest/ diff --git a/test/ut/README.md b/test/ut/README.md deleted file mode 100644 index 4d46ee5..0000000 --- a/test/ut/README.md +++ /dev/null @@ -1 +0,0 @@ -# Unit tests \ No newline at end of file diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..ac889bf --- /dev/null +++ b/tests/README.md @@ -0,0 +1,2 @@ +# Testing practices and guidelines + diff --git a/test/integration-test/README.md b/tests/integration-tests/README.md similarity index 100% rename from test/integration-test/README.md rename to tests/integration-tests/README.md diff --git a/tests/unit-tests/README.md b/tests/unit-tests/README.md new file mode 100644 index 0000000..a0291f0 --- /dev/null +++ b/tests/unit-tests/README.md @@ -0,0 +1 @@ +# Unit tests From 608818414a63ae3afeb541d052eba7cd74dee8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 13:44:52 +0100 Subject: [PATCH 29/62] feat: Dummy unit test --- tests/unit-tests/example_test.cpp | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/unit-tests/example_test.cpp diff --git a/tests/unit-tests/example_test.cpp b/tests/unit-tests/example_test.cpp new file mode 100644 index 0000000..6540404 --- /dev/null +++ b/tests/unit-tests/example_test.cpp @@ -0,0 +1,61 @@ +#include +#include "gtest/gtest.h" + + +int Factorial(int n) { + //For negative n, n! is defined to be 1. + int result = 1; + for (int i = 1; i <= n; i++) { + result *= i; + } + + return result; +} + +bool IsPrime(int n) { + if (n <= 1) return false; + if (n % 2 == 0) return n == 2; + for (int i = 3;; i += 2) { + if (i > n / i) break; + if (n % i == 0) return false; + } + return true; +} + +namespace { + +TEST(FactorialTest, Negative) { + EXPECT_EQ(1, Factorial(-5)); + EXPECT_EQ(1, Factorial(-1)); + EXPECT_GT(Factorial(-10), 0); +} + +TEST(FactorialTest, Zero) { EXPECT_EQ(1, Factorial(0)); } + +TEST(FactorialTest, Positive) { + EXPECT_EQ(1, Factorial(1)); + EXPECT_EQ(2, Factorial(2)); + EXPECT_EQ(6, Factorial(3)); + EXPECT_EQ(40320, Factorial(8)); +} + +TEST(IsPrimeTest, Negative) { + EXPECT_FALSE(IsPrime(-1)); + EXPECT_FALSE(IsPrime(-2)); + EXPECT_FALSE(IsPrime(INT_MIN)); +} + +TEST(IsPrimeTest, Trivial) { + EXPECT_FALSE(IsPrime(0)); + EXPECT_FALSE(IsPrime(1)); + EXPECT_TRUE(IsPrime(2)); + EXPECT_TRUE(IsPrime(3)); +} + +TEST(IsPrimeTest, Positive) { + EXPECT_FALSE(IsPrime(4)); + EXPECT_TRUE(IsPrime(5)); + EXPECT_FALSE(IsPrime(6)); + EXPECT_TRUE(IsPrime(23)); +} +} // namespace From ec0bdd97e1f93a7fa80bdc1db4f99598e951669e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 13:45:34 +0100 Subject: [PATCH 30/62] feat: Interactive docker image scripts --- run_interactive_docker_image.bat | 1 + run_interactive_docker_image.sh | 1 + 2 files changed, 2 insertions(+) create mode 100644 run_interactive_docker_image.bat create mode 100755 run_interactive_docker_image.sh diff --git a/run_interactive_docker_image.bat b/run_interactive_docker_image.bat new file mode 100644 index 0000000..c5ae76e --- /dev/null +++ b/run_interactive_docker_image.bat @@ -0,0 +1 @@ +docker run -it -v .:/pokemon_game "pokemon-image" \ No newline at end of file diff --git a/run_interactive_docker_image.sh b/run_interactive_docker_image.sh new file mode 100755 index 0000000..c5ae76e --- /dev/null +++ b/run_interactive_docker_image.sh @@ -0,0 +1 @@ +docker run -it -v .:/pokemon_game "pokemon-image" \ No newline at end of file From 2822060a54467555f912d41ea29336f1be07bdf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 14:59:47 +0100 Subject: [PATCH 31/62] feat: Automated tests using github actions --- .cmake_compile | 7 +++++++ .github/workflows/README.md | 1 + .github/workflows/pull_request_checks.yml | 21 +++++++++++++++++++ Docker/README.md | 25 ----------------------- Docker/unix/build_docker_image.sh | 1 - Docker/windows/build_docker_image.bat | 1 - Docker/Dockerfile => Dockerfile | 0 docker-compose.yml | 19 +++++++++++++++++ run_interactive_docker_image.bat | 1 - run_interactive_docker_image.sh | 1 - 10 files changed, 48 insertions(+), 29 deletions(-) create mode 100755 .cmake_compile create mode 100644 .github/workflows/README.md create mode 100644 .github/workflows/pull_request_checks.yml delete mode 100644 Docker/README.md delete mode 100755 Docker/unix/build_docker_image.sh delete mode 100644 Docker/windows/build_docker_image.bat rename Docker/Dockerfile => Dockerfile (100%) create mode 100644 docker-compose.yml delete mode 100644 run_interactive_docker_image.bat delete mode 100755 run_interactive_docker_image.sh diff --git a/.cmake_compile b/.cmake_compile new file mode 100755 index 0000000..e6597d7 --- /dev/null +++ b/.cmake_compile @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# [This file will be automatically called by docker-compose] + +mkdir build +cd build +cmake .. +make \ No newline at end of file diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..c49e66e --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1 @@ +# Github Actions for CI/CD and other tasks diff --git a/.github/workflows/pull_request_checks.yml b/.github/workflows/pull_request_checks.yml new file mode 100644 index 0000000..d4b68c7 --- /dev/null +++ b/.github/workflows/pull_request_checks.yml @@ -0,0 +1,21 @@ +name: Pull-Request-Checks + +run-name: Pull request to ${{ inputs.deploy_target }} by @${{ github.actor }} + +on: + push: + branches: [ develop ] + pull_request: + branches: [ develop ] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + - name: Build docker image + run: docker-compose build + - name: Run tests + run: docker-compose run test + diff --git a/Docker/README.md b/Docker/README.md deleted file mode 100644 index a56d942..0000000 --- a/Docker/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Docker - -In this project we will use docker to compile, test and run our game. It would be quite helpful to quickly check a [guide like on Docker](https://phoenixnap.com/kb/docker-image-vs-container). In this `Readme`, we explain the different steps we take to run our code inside a Docker container. - -### Quick overview -1. Building Docker image with the project dependencies -2. Development mode: Opening a shell inside the container. -3. Test mode - -### Details - -1. We build an image that contains all the necessary dependencies to compile the application. This image only needs to be created once as long as the dependencies do not change (very rarely). **This step does not compile the game**. - - Linux and MacOS: - - ```$ bash ./Docker/unix/build_docker_image.sh``` - - - Windows: - - ```$ .\Docker\windows\build_docker_image.bat``` - - At this point we have created an Docker image based on `Ubuntu-latest`. You can double check by executing `$ docker images` and hopefully find that a container called `pokemon-image`. - -2. From the root directory of our project run `$ docker run -it -v .:/pokemon_game "pokemon-image"`. This will run the docker image `"pokemon-image"` with the source code included as a [mounted volume](https://docs.docker.com/storage/volumes/). Inside this docker image you can manually compile the project as usual with: `mkdir build; cd build; cmake ..; make;`. Note: While you are developing, you can keep this shell open. Since your local machine files are synched with the docker's image thanks to `-v .:/pokemon_game`. The most comfortable workflow should be: `Write changes locally, run make in the docker image, run the program, repeat` - -3. Test mode: TBD diff --git a/Docker/unix/build_docker_image.sh b/Docker/unix/build_docker_image.sh deleted file mode 100755 index 7c79aee..0000000 --- a/Docker/unix/build_docker_image.sh +++ /dev/null @@ -1 +0,0 @@ -docker build --file Docker/Dockerfile -t "pokemon-image" . \ No newline at end of file diff --git a/Docker/windows/build_docker_image.bat b/Docker/windows/build_docker_image.bat deleted file mode 100644 index 7c79aee..0000000 --- a/Docker/windows/build_docker_image.bat +++ /dev/null @@ -1 +0,0 @@ -docker build --file Docker/Dockerfile -t "pokemon-image" . \ No newline at end of file diff --git a/Docker/Dockerfile b/Dockerfile similarity index 100% rename from Docker/Dockerfile rename to Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..56fbe62 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +services: + bash: + build: . + entrypoint: bash + <<: &default # Define named block: default + image: pokemon-image + volumes: + - .:/pokemon_game + + test: + <<: *default # Reference named block default (copy-paste) + command: bash -c "./.cmake_compile && ./build/tests/pokemon-tests" + + play: + <<: *default # Reference named block default (copy-paste) + command: bash -c "./.cmake_compile && ./build/pokemon" + + inspect: + <<: *default # Reference named block default (copy-paste) diff --git a/run_interactive_docker_image.bat b/run_interactive_docker_image.bat deleted file mode 100644 index c5ae76e..0000000 --- a/run_interactive_docker_image.bat +++ /dev/null @@ -1 +0,0 @@ -docker run -it -v .:/pokemon_game "pokemon-image" \ No newline at end of file diff --git a/run_interactive_docker_image.sh b/run_interactive_docker_image.sh deleted file mode 100755 index c5ae76e..0000000 --- a/run_interactive_docker_image.sh +++ /dev/null @@ -1 +0,0 @@ -docker run -it -v .:/pokemon_game "pokemon-image" \ No newline at end of file From 0e49c1c6df4635618896ee2ac8504e26b67268cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 15:04:10 +0100 Subject: [PATCH 32/62] doc: New simplified Docker instructions --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a025ee9..eb8e2b6 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# Re-Pokemon-Red \ No newline at end of file +# Re-Pokemon-Red + +# Running the game +`docker compose build` +`docker compose run play` + +# Testing your changes +`docker compose build` +`docker compose run test` From a7a3ace21b5b6b27174f90dfb412962c5b609add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 15:13:26 +0100 Subject: [PATCH 33/62] breaking: Test failed testing pipeline behaviour --- tests/unit-tests/example_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit-tests/example_test.cpp b/tests/unit-tests/example_test.cpp index 6540404..66217a2 100644 --- a/tests/unit-tests/example_test.cpp +++ b/tests/unit-tests/example_test.cpp @@ -4,7 +4,7 @@ int Factorial(int n) { //For negative n, n! is defined to be 1. - int result = 1; + int result = 2; for (int i = 1; i <= n; i++) { result *= i; } From cdb203074d6dc4f0a18198ce5fc8885cc1dae3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 15:18:07 +0100 Subject: [PATCH 34/62] fix: Fix breaking change --- tests/unit-tests/example_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit-tests/example_test.cpp b/tests/unit-tests/example_test.cpp index 66217a2..6540404 100644 --- a/tests/unit-tests/example_test.cpp +++ b/tests/unit-tests/example_test.cpp @@ -4,7 +4,7 @@ int Factorial(int n) { //For negative n, n! is defined to be 1. - int result = 2; + int result = 1; for (int i = 1; i <= n; i++) { result *= i; } From 74310c5dd7bd22e32187ce512cc2270a30809e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 16:39:33 +0100 Subject: [PATCH 35/62] fix: Update CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d80134..34a2389 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,4 +6,4 @@ add_subdirectory(game) add_subdirectory(tests) add_executable(pokemon game/src/main.cpp) -target_link_libraries(pokemon PRIVATE pokemon-lib) \ No newline at end of file +target_link_libraries(pokemon PRIVATE pokemon-lib) From b2de58edef81881f970eac56b738523c1f844159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 16:40:32 +0100 Subject: [PATCH 36/62] doc: Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index eb8e2b6..c6db4f5 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Re-Pokemon-Red # Running the game -`docker compose build` -`docker compose run play` +```$ docker compose build``` +```$ docker compose run play``` # Testing your changes -`docker compose build` -`docker compose run test` +```$ docker compose build``` +```$ docker compose run test``` From 2659a5c87b2a065c0a8edfe0b2b3ddee8d043af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 16:41:38 +0100 Subject: [PATCH 37/62] doc: Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c6db4f5..e96f293 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Re-Pokemon-Red # Running the game -```$ docker compose build``` -```$ docker compose run play``` +- ```$ docker compose build``` +- ```$ docker compose run play``` # Testing your changes -```$ docker compose build``` -```$ docker compose run test``` +- ```$ docker compose build``` +- ```$ docker compose run test``` From 76565c95499532119e2c48f34d2f0b057e128fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sun, 18 Feb 2024 00:14:03 +0100 Subject: [PATCH 38/62] fix: Incorporate PR comments --- docker-compose.yml | 2 +- tests/CMakeLists.txt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 56fbe62..3a89d50 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ services: - bash: + build-container: build: . entrypoint: bash <<: &default # Define named block: default diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e592853..c945728 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,4 +15,6 @@ target_sources(pokemon-tests PRIVATE ${TEST_FILES}) target_link_libraries(pokemon-tests PRIVATE ${GTEST_LDFLAGS}) target_compile_options(pokemon-tests PRIVATE ${GTEST_CFLAGS}) -enable_testing() \ No newline at end of file +enable_testing() + +target_link_libraries(pokemon-tests PRIVATE pokemon-lib) \ No newline at end of file From 6b2c26b1b9e88b182c0b6d1615bba0e5c5a8a87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 15:34:40 +0100 Subject: [PATCH 39/62] feat: Auto-formatter --- .clang-format | 6 +++++ .github/workflows/clang-format.yml | 38 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 .clang-format create mode 100644 .github/workflows/clang-format.yml diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..6593b99 --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +BasedOnStyle: Google +ColumnLimit: 200 +IndentWidth: 4 +# Force pointers to the type for C++. +DerivePointerAlignment: false +PointerAlignment: Left \ No newline at end of file diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 0000000..6c806f3 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,38 @@ +name: Clang-Format + +on: [push] + +jobs: + clang-format: + name: Clang-Format + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + persist-credentials: false + fetch-depth: 0 + + - name: Set up Clang-Format + run: sudo apt-get install -y clang-format + + - name: Run Clang-Format + run: clang-format -i *.cpp *.hpp --style file:.clang-format + + - name: Check for modifications + id: check_modifications + run: | + git diff --exit-code > /dev/null || echo "modified=true" >> $GITHUB_ENV + + - name: Commit and push changes + if: env.modified == 'true' + run: | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git commit -a -m "Format: ${{github.event.commits[0].message}}" + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} \ No newline at end of file From 686f1136a4593c719b42245765164f501fde17ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sat, 17 Feb 2024 15:38:49 +0100 Subject: [PATCH 40/62] feat: Update clang formatter with current code structure --- .github/workflows/clang-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 6c806f3..97ee008 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -18,7 +18,7 @@ jobs: run: sudo apt-get install -y clang-format - name: Run Clang-Format - run: clang-format -i *.cpp *.hpp --style file:.clang-format + run: clang-format -i src/*.cpp game/src/*.cpp game/src/*.hpp tests/integration-tests/*.cpp tests/integration-tests/*.hpp tests/unit-tests/*.cpp tests/unit-tests/*.hpp 0 --style file:.clang-format - name: Check for modifications id: check_modifications From 884638aa2f2027755e20f338ff6e6e3b8147b849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sun, 18 Feb 2024 00:19:59 +0100 Subject: [PATCH 41/62] fix: Clang formatter list of files --- .github/workflows/clang-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 97ee008..9aff238 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -18,7 +18,7 @@ jobs: run: sudo apt-get install -y clang-format - name: Run Clang-Format - run: clang-format -i src/*.cpp game/src/*.cpp game/src/*.hpp tests/integration-tests/*.cpp tests/integration-tests/*.hpp tests/unit-tests/*.cpp tests/unit-tests/*.hpp 0 --style file:.clang-format + run: clang-format -i game/src/*.cpp game/src/*.hpp tests/integration-tests/*.cpp tests/integration-tests/*.hpp tests/unit-tests/*.cpp tests/unit-tests/*.hpp 0 --style file:.clang-format - name: Check for modifications id: check_modifications From 9755ed2d468f2f481f93a106da6eab1157765bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sun, 18 Feb 2024 00:24:42 +0100 Subject: [PATCH 42/62] feat: Nice clang-format workflow --- .github/workflows/clang-format.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 9aff238..aa16b93 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -17,8 +17,14 @@ jobs: - name: Set up Clang-Format run: sudo apt-get install -y clang-format - - name: Run Clang-Format - run: clang-format -i game/src/*.cpp game/src/*.hpp tests/integration-tests/*.cpp tests/integration-tests/*.hpp tests/unit-tests/*.cpp tests/unit-tests/*.hpp 0 --style file:.clang-format + - name: Format source code + run: clang-format -i game/src/*.cpp game/src/*.hpp 0 --style file:.clang-format --verbose + + - name: Format unit tests + run: clang-format -i tests/unit-tests/*.cpp tests/unit-tests/*.hpp 0 --style file:.clang-format --verbose + + - name: Format integration tests + run: clang-format -i tests/integration-tests/*.cpp tests/integration-tests/*.hpp 0 --style file:.clang-format --verbose - name: Check for modifications id: check_modifications From 5306a8beea17382c7c621cea5bde750eb093856f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sun, 18 Feb 2024 00:27:08 +0100 Subject: [PATCH 43/62] feat: Improve clang-format.yml --- .github/workflows/clang-format.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index aa16b93..1be20b5 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -18,13 +18,10 @@ jobs: run: sudo apt-get install -y clang-format - name: Format source code - run: clang-format -i game/src/*.cpp game/src/*.hpp 0 --style file:.clang-format --verbose + run: clang-format -i game/**/*.cpp game/**/*.hpp 0 --style file:.clang-format --verbose - - name: Format unit tests - run: clang-format -i tests/unit-tests/*.cpp tests/unit-tests/*.hpp 0 --style file:.clang-format --verbose - - - name: Format integration tests - run: clang-format -i tests/integration-tests/*.cpp tests/integration-tests/*.hpp 0 --style file:.clang-format --verbose + - name: Format tests + run: clang-format -i tests/**/*.cpp tests/**/*.hpp 0 --style file:.clang-format --verbose - name: Check for modifications id: check_modifications From 02d002ddd1d4a1fceea8e8506f36b17fadc43d45 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 01:15:07 +0100 Subject: [PATCH 44/62] Refactor .h -> .hpp and correct typos --- game/src/Map.cpp | 2 +- include/Map.h | 49 ------------------------------------------------ include/Map.hpp | 20 ++++++++++++++++++++ test/MapTest.cpp | 2 +- 4 files changed, 22 insertions(+), 51 deletions(-) delete mode 100644 include/Map.h diff --git a/game/src/Map.cpp b/game/src/Map.cpp index 93f8601..d993746 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -1,4 +1,4 @@ -#include "Map.h" +#include "Map.hpp" Map::Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities) { setId(id); diff --git a/include/Map.h b/include/Map.h deleted file mode 100644 index a7d5c88..0000000 --- a/include/Map.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "Tile.h" - -#include -#include -#include - -using tileArray = boost::multi_array; -using entityStdMap = std::map; - -class Map { - private: - uint16_t id_; - uint8_t currentType_; - std::string mapName_; - std::string bitmapName_; - tileArray tiles_; // - entityStdMap entities_;// Map - - public: - - Map(); - Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityStdMap &entities); - ~Map(); - - void setId(const uint16_t &id); - void setCurrentType(const uint8_t ¤tType); - void setMapName(const std::string &mapName); - void setBitmapName(const std::string &bitmapName); - void setTiles(const tileArray tiles, const uint16_t &dimensionX, const uint16_t &dimensionY); - void setEntities(const entityStdMap &entities); - void setTile(const utils::Coordinate &coordinate, const Tile &tile); - - const uint16_t getId(); - const uint8_t getCurrentType(); - const std::string getMapName(); - const std::string getBitmapName(); - const tileArray getTiles(); - const entityStdMap getEntities(); - - void swapTiles(Tile tile1, Tile Tile2); - - bool doesItCollide(const tils::Coordinate &coordinate, const uint8_t &direction); - bool doesItInteract(const utils::Coordinate &coordinate, const uint8_t &direction); - bool isPokemonBattleTriggered(); - bool isTrainerBattleTriggered(); - -} \ No newline at end of file diff --git a/include/Map.hpp b/include/Map.hpp index a0de56a..c849ec0 100644 --- a/include/Map.hpp +++ b/include/Map.hpp @@ -7,7 +7,11 @@ #include using tileArray = boost::multi_array; +<<<<<<< HEAD using entityMap = std::map; +======= +using entityStdMap = std::map; +>>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) class Map { private: @@ -16,12 +20,20 @@ class Map { std::string mapName_; std::string bitmapName_; tileArray tiles_; +<<<<<<< HEAD entityMap entities_; +======= + entityStdMap entities_; +>>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) public: Map(); +<<<<<<< HEAD Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities); +======= + Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityStdMap &entities); +>>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) ~Map(); void setId(const uint16_t &id); @@ -29,7 +41,11 @@ class Map { void setMapName(const std::string &mapName); void setBitmapName(const std::string &bitmapName); void setTiles(const tileArray tiles, const uint16_t &dimensionX, const uint16_t &dimensionY); +<<<<<<< HEAD void setEntities(const entityMap &entities); +======= + void setEntities(const entityStdMap &entities); +>>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) void setTile(const utils::Coordinate &coordinate, const Tile &tile); const uint16_t getId(); @@ -37,7 +53,11 @@ class Map { const std::string getMapName(); const std::string getBitmapName(); const tileArray getTiles(); +<<<<<<< HEAD const entityMap getEntities(); +======= + const entityStdMap getEntities(); +>>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) void swapTiles(Tile tile1, Tile Tile2); diff --git a/test/MapTest.cpp b/test/MapTest.cpp index cc6ee5f..aa4b9f2 100644 --- a/test/MapTest.cpp +++ b/test/MapTest.cpp @@ -1,4 +1,4 @@ -#include "Map.h" +#include "Map.hpp" int main() { std::cout<<"hello Map"< Date: Sun, 18 Feb 2024 01:24:55 +0100 Subject: [PATCH 45/62] Correction in Map.cpp->swapTiles() --- game/src/Map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/src/Map.cpp b/game/src/Map.cpp index d993746..bf568e7 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -61,7 +61,7 @@ const entityMap Map::getEntities() { } void Map::swapTiles(Tile &tile1, Tile &tile2) { - tileArray tiletmp = tile1; + Tile tiletmp = tile1; tile1 = tile2; tile2 = tiletmp; } From 9a3ae73202744a2e940bd175c3c8de385d57bb43 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 01:50:55 +0100 Subject: [PATCH 46/62] Fixed includes --- game/src/Map.cpp | 2 +- include/Map.hpp | 22 +--------------------- test/MapTest.cpp | 2 +- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/game/src/Map.cpp b/game/src/Map.cpp index bf568e7..e235046 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -1,4 +1,4 @@ -#include "Map.hpp" +#include Map::Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities) { setId(id); diff --git a/include/Map.hpp b/include/Map.hpp index c849ec0..074b6dc 100644 --- a/include/Map.hpp +++ b/include/Map.hpp @@ -1,17 +1,13 @@ #pragma once -#include "Tile.hpp" +#include #include #include #include using tileArray = boost::multi_array; -<<<<<<< HEAD using entityMap = std::map; -======= -using entityStdMap = std::map; ->>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) class Map { private: @@ -20,20 +16,12 @@ class Map { std::string mapName_; std::string bitmapName_; tileArray tiles_; -<<<<<<< HEAD entityMap entities_; -======= - entityStdMap entities_; ->>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) public: Map(); -<<<<<<< HEAD Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities); -======= - Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityStdMap &entities); ->>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) ~Map(); void setId(const uint16_t &id); @@ -41,11 +29,7 @@ class Map { void setMapName(const std::string &mapName); void setBitmapName(const std::string &bitmapName); void setTiles(const tileArray tiles, const uint16_t &dimensionX, const uint16_t &dimensionY); -<<<<<<< HEAD void setEntities(const entityMap &entities); -======= - void setEntities(const entityStdMap &entities); ->>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) void setTile(const utils::Coordinate &coordinate, const Tile &tile); const uint16_t getId(); @@ -53,11 +37,7 @@ class Map { const std::string getMapName(); const std::string getBitmapName(); const tileArray getTiles(); -<<<<<<< HEAD const entityMap getEntities(); -======= - const entityStdMap getEntities(); ->>>>>>> 27e3747 (Refactor .h -> .hpp and correct typos) void swapTiles(Tile tile1, Tile Tile2); diff --git a/test/MapTest.cpp b/test/MapTest.cpp index aa4b9f2..de8151e 100644 --- a/test/MapTest.cpp +++ b/test/MapTest.cpp @@ -1,4 +1,4 @@ -#include "Map.hpp" +#include int main() { std::cout<<"hello Map"< Date: Sun, 18 Feb 2024 10:30:09 +0000 Subject: [PATCH 47/62] Autoformat code --- game/src/Map.cpp | 71 ++++++++++++++--------------------------------- game/src/Tile.cpp | 12 +++----- 2 files changed, 25 insertions(+), 58 deletions(-) diff --git a/game/src/Map.cpp b/game/src/Map.cpp index e235046..980a1f6 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -1,79 +1,50 @@ #include -Map::Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities) { +Map::Map(const uint16_t& id, const uint8_t& currentType, const std::string& mapName, const std::string& bitmapName, const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY, + const entityMap& entities) { setId(id); setCurrentType(currentType); setMapName(mapName); setBitmapName(bitmapName); setTiles(tiles, dimensionX, dimensionY); setEntities(entities); - } -Map::~Map() { - entities_.clear(); - -} +Map::~Map() { entities_.clear(); } -void Map::setId(const uint16_t &id) { - this->id_ = id; -} -void Map::setCurrentType(const uint8_t ¤tType) { - this->currentType_ = currentType; -} -void Map::setMapName(const std::string &mapName) { - this->mapName_ = mapName; -} -void Map::setBitmapName(const std::string &bitmapName) { - this->bitmapName_ = bitmapName; -} -void Map::setTiles(const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY) { - if(dimensionX == 0 || dimensionY == 0) { +void Map::setId(const uint16_t& id) { this->id_ = id; } +void Map::setCurrentType(const uint8_t& currentType) { this->currentType_ = currentType; } +void Map::setMapName(const std::string& mapName) { this->mapName_ = mapName; } +void Map::setBitmapName(const std::string& bitmapName) { this->bitmapName_ = bitmapName; } +void Map::setTiles(const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY) { + if (dimensionX == 0 || dimensionY == 0) { return; } - tiles_.resize(boost::extents[dimensionX][dimensionY]); + tiles_.resize(boost::extents[dimensionX][dimensionY]); this->tiles_ = tiles; } -void Map::setEntities(const entityMap &entities) { - this->entities_ = entities; -} -void Map::setTile(const utils::Coordinate &coordinate, const Tile &tile) { - tiles_[coordinate.x][coordinate.y] = tile; -} +void Map::setEntities(const entityMap& entities) { this->entities_ = entities; } +void Map::setTile(const utils::Coordinate& coordinate, const Tile& tile) { tiles_[coordinate.x][coordinate.y] = tile; } -const uint16_t Map::getId() { - return id_; -} -const uint8_t Map::getCurrentType() { - return currentType_; -} -const std::string Map::getMapName() { - return mapName_; -} -const std::string Map::getBitmapName() { - return bitmapName_; -} -const tileArray Map::getTiles() { - return tiles_; -} -const entityMap Map::getEntities() { - return entities_; -} +const uint16_t Map::getId() { return id_; } +const uint8_t Map::getCurrentType() { return currentType_; } +const std::string Map::getMapName() { return mapName_; } +const std::string Map::getBitmapName() { return bitmapName_; } +const tileArray Map::getTiles() { return tiles_; } +const entityMap Map::getEntities() { return entities_; } -void Map::swapTiles(Tile &tile1, Tile &tile2) { +void Map::swapTiles(Tile& tile1, Tile& tile2) { Tile tiletmp = tile1; tile1 = tile2; tile2 = tiletmp; } -bool Map::doesItCollide(const utils::Coordinate &coordinate, const uint8_t &direction) { +bool Map::doesItCollide(const utils::Coordinate& coordinate, const uint8_t& direction) { Tile tile = tiles_[coordinate.x][coordinate.y]; return tile.isCollision(direction); - } -bool Map::doesItInteract(const utils::Coordinate &coordinate, const uint8_t &direction) { +bool Map::doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction) { Tile tile = tiles_[coordinate.x][coordinate.y]; return tile.isInteraction(direction); - } \ No newline at end of file diff --git a/game/src/Tile.cpp b/game/src/Tile.cpp index e1bd912..95b3608 100644 --- a/game/src/Tile.cpp +++ b/game/src/Tile.cpp @@ -2,16 +2,12 @@ #include Tile::Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask) { - this->collision_directions_bitmask_ = collision_directions_bitmask; - this->interaction_directions_bitmask_ = interaction_directions_bitmask; + this->collision_directions_bitmask_ = collision_directions_bitmask; + this->interaction_directions_bitmask_ = interaction_directions_bitmask; } Tile::~Tile() {} -bool Tile::isCollision(utils::Direction player_direction) { - return player_direction & this->collision_directions_bitmask_; -} +bool Tile::isCollision(utils::Direction player_direction) { return player_direction & this->collision_directions_bitmask_; } -bool Tile::isInteraction(utils::Direction player_direction) { - return player_direction & this->interaction_directions_bitmask_; -} \ No newline at end of file +bool Tile::isInteraction(utils::Direction player_direction) { return player_direction & this->interaction_directions_bitmask_; } \ No newline at end of file From 970bc660aa4746801639e217d8f1d61700a3791b Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 13:42:19 +0100 Subject: [PATCH 48/62] Moved hpp and cpp in the new structure. Updated dependencies. --- {include => game/include}/Map.hpp | 5 +++-- {include => game/include}/Tile.hpp | 2 +- {include => game/include}/utils.hpp | 0 game/src/Map.cpp | 2 +- src/Tile.cpp | 17 ----------------- {test => tests/unit-tests}/MapTest.cpp | 0 6 files changed, 5 insertions(+), 21 deletions(-) rename {include => game/include}/Map.hpp (95%) rename {include => game/include}/Tile.hpp (93%) rename {include => game/include}/utils.hpp (100%) delete mode 100644 src/Tile.cpp rename {test => tests/unit-tests}/MapTest.cpp (100%) diff --git a/include/Map.hpp b/game/include/Map.hpp similarity index 95% rename from include/Map.hpp rename to game/include/Map.hpp index 074b6dc..e4d43ba 100644 --- a/include/Map.hpp +++ b/game/include/Map.hpp @@ -1,10 +1,11 @@ #pragma once -#include +#include #include #include -#include +#include +#include using tileArray = boost::multi_array; using entityMap = std::map; diff --git a/include/Tile.hpp b/game/include/Tile.hpp similarity index 93% rename from include/Tile.hpp rename to game/include/Tile.hpp index d5d8fec..c944910 100644 --- a/include/Tile.hpp +++ b/game/include/Tile.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include class Tile { public: diff --git a/include/utils.hpp b/game/include/utils.hpp similarity index 100% rename from include/utils.hpp rename to game/include/utils.hpp diff --git a/game/src/Map.cpp b/game/src/Map.cpp index 980a1f6..fe980e8 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -1,4 +1,4 @@ -#include +#include Map::Map(const uint16_t& id, const uint8_t& currentType, const std::string& mapName, const std::string& bitmapName, const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY, const entityMap& entities) { diff --git a/src/Tile.cpp b/src/Tile.cpp deleted file mode 100644 index e1bd912..0000000 --- a/src/Tile.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -Tile::Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask) { - this->collision_directions_bitmask_ = collision_directions_bitmask; - this->interaction_directions_bitmask_ = interaction_directions_bitmask; -} - -Tile::~Tile() {} - -bool Tile::isCollision(utils::Direction player_direction) { - return player_direction & this->collision_directions_bitmask_; -} - -bool Tile::isInteraction(utils::Direction player_direction) { - return player_direction & this->interaction_directions_bitmask_; -} \ No newline at end of file diff --git a/test/MapTest.cpp b/tests/unit-tests/MapTest.cpp similarity index 100% rename from test/MapTest.cpp rename to tests/unit-tests/MapTest.cpp From 983abbd680afc2a88854f5504a6a5692e981af3c Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 13:43:49 +0100 Subject: [PATCH 49/62] Install boost lib in docker and include in CMakeLists. Not in a working state yet, to be debugged. --- Dockerfile | 1 + game/CMakeLists.txt | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 02c7853..6a9df56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ RUN rm /etc/apt/trusted.gpg.d/kitware.gpg RUN apt-get install cmake -y # Install project dependencies +RUN apt-get install libboost-all-dev -y RUN apt-get install liballegro5-dev -y RUN apt-get install libjsoncpp-dev -y RUN apt-get install g++ -y diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 0bb2f33..cd00ae2 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -14,9 +14,12 @@ set_target_properties(pokemon-lib PROPERTIES LINKER_LANGUAGE CXX) pkg_check_modules(ALLEGRO REQUIRED allegro-5 allegro_font-5 allegro_ttf-5 allegro_image-5 allegro_primitives-5) pkg_check_modules(JSONCPP REQUIRED jsoncpp) +pkg_check_modules(BOOST REQUIRED boost_all_dev) target_include_directories(pokemon-lib PUBLIC include) target_include_directories(pokemon-lib PUBLIC ${JSONCPP_INCLUDE_DIRS}) +target_include_directories(pokemon-lib PUBLIC ${BOOST_INCLUDE_DIRS}) target_link_libraries(pokemon-lib PRIVATE ${JSONCPP_LIBRARIES}) -target_link_libraries(pokemon-lib PRIVATE ${ALLEGRO_LIBRARIES}) \ No newline at end of file +target_link_libraries(pokemon-lib PRIVATE ${ALLEGRO_LIBRARIES}) +target_link_libraries(pokemon-lib PRIVATE ${BOOST_LIBRARIES}) \ No newline at end of file From 28266480c52fbacd7d2462bca17ded293c7b82f6 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 12:44:26 +0000 Subject: [PATCH 50/62] Autoformat code --- game/include/Map.hpp | 80 ++++++++++++++++++------------------ game/include/Tile.hpp | 18 ++++---- game/include/utils.hpp | 23 +++++------ tests/unit-tests/MapTest.cpp | 5 +-- 4 files changed, 60 insertions(+), 66 deletions(-) diff --git a/game/include/Map.hpp b/game/include/Map.hpp index e4d43ba..01efd78 100644 --- a/game/include/Map.hpp +++ b/game/include/Map.hpp @@ -1,50 +1,48 @@ #pragma once #include - +#include #include -#include #include -#include +#include -using tileArray = boost::multi_array; -using entityMap = std::map; +using tileArray = boost::multi_array; +using entityMap = std::map; class Map { - private: - uint16_t id_; - uint8_t currentType_; - std::string mapName_; - std::string bitmapName_; - tileArray tiles_; - entityMap entities_; - - public: - - Map(); - Map(const uint16_t &id, const uint8_t ¤tType, const std::string &mapName, const std::string &bitmapName, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities); - ~Map(); - - void setId(const uint16_t &id); - void setCurrentType(const uint8_t ¤tType); - void setMapName(const std::string &mapName); - void setBitmapName(const std::string &bitmapName); - void setTiles(const tileArray tiles, const uint16_t &dimensionX, const uint16_t &dimensionY); - void setEntities(const entityMap &entities); - void setTile(const utils::Coordinate &coordinate, const Tile &tile); - - const uint16_t getId(); - const uint8_t getCurrentType(); - const std::string getMapName(); - const std::string getBitmapName(); - const tileArray getTiles(); - const entityMap getEntities(); - - void swapTiles(Tile tile1, Tile Tile2); - - bool doesItCollide(const tils::Coordinate &coordinate, const uint8_t &direction); - bool doesItInteract(const utils::Coordinate &coordinate, const uint8_t &direction); - bool isPokemonBattleTriggered(); - bool isTrainerBattleTriggered(); - + private: + uint16_t id_; + uint8_t currentType_; + std::string mapName_; + std::string bitmapName_; + tileArray tiles_; + entityMap entities_; + + public: + Map(); + Map(const uint16_t& id, const uint8_t& currentType, const std::string& mapName, const std::string& bitmapName, const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY, + const entityMap& entities); + ~Map(); + + void setId(const uint16_t& id); + void setCurrentType(const uint8_t& currentType); + void setMapName(const std::string& mapName); + void setBitmapName(const std::string& bitmapName); + void setTiles(const tileArray tiles, const uint16_t& dimensionX, const uint16_t& dimensionY); + void setEntities(const entityMap& entities); + void setTile(const utils::Coordinate& coordinate, const Tile& tile); + + const uint16_t getId(); + const uint8_t getCurrentType(); + const std::string getMapName(); + const std::string getBitmapName(); + const tileArray getTiles(); + const entityMap getEntities(); + + void swapTiles(Tile tile1, Tile Tile2); + + bool doesItCollide(const tils::Coordinate& coordinate, const uint8_t& direction); + bool doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction); + bool isPokemonBattleTriggered(); + bool isTrainerBattleTriggered(); } \ No newline at end of file diff --git a/game/include/Tile.hpp b/game/include/Tile.hpp index c944910..f7137be 100644 --- a/game/include/Tile.hpp +++ b/game/include/Tile.hpp @@ -3,14 +3,14 @@ #include class Tile { - public: - Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask); - ~Tile(); - bool isCollision(utils::Direction player_direction); - bool isInteraction(utils::Direction player_direction); - utils::Coordinate getCoordinate(); + public: + Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask); + ~Tile(); + bool isCollision(utils::Direction player_direction); + bool isInteraction(utils::Direction player_direction); + utils::Coordinate getCoordinate(); - private: - uint8_t collision_directions_bitmask_; - uint8_t interaction_directions_bitmask_; + private: + uint8_t collision_directions_bitmask_; + uint8_t interaction_directions_bitmask_; }; \ No newline at end of file diff --git a/game/include/utils.hpp b/game/include/utils.hpp index 09bc07c..f8f0dc4 100644 --- a/game/include/utils.hpp +++ b/game/include/utils.hpp @@ -3,16 +3,15 @@ #include namespace utils { - struct Coordinate - { - int x; - int y; - }; +struct Coordinate { + int x; + int y; +}; - typedef enum Direction : uint8_t { - up = 0b00000001, - down = 0b00000010, - left = 0b00000100, - right = 0b00001000, - }; -} +typedef enum Direction : uint8_t { + up = 0b00000001, + down = 0b00000010, + left = 0b00000100, + right = 0b00001000, +}; +} // namespace utils diff --git a/tests/unit-tests/MapTest.cpp b/tests/unit-tests/MapTest.cpp index de8151e..598ffbc 100644 --- a/tests/unit-tests/MapTest.cpp +++ b/tests/unit-tests/MapTest.cpp @@ -1,6 +1,3 @@ #include -int main() { - std::cout<<"hello Map"< Date: Sun, 18 Feb 2024 14:03:15 +0100 Subject: [PATCH 51/62] Use consistent variable format "my_variable" --- game/src/Map.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/game/src/Map.cpp b/game/src/Map.cpp index fe980e8..8ecfaea 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -1,21 +1,21 @@ #include -Map::Map(const uint16_t& id, const uint8_t& currentType, const std::string& mapName, const std::string& bitmapName, const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY, +Map::Map(const uint16_t& id, const uint8_t& current_type, const std::string& map_name, const std::string& bitmap_name, const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY, const entityMap& entities) { setId(id); - setCurrentType(currentType); - setMapName(mapName); - setBitmapName(bitmapName); + setCurrentType(current_type); + setMapName(map_name); + setBitmapName(bitmap_name); setTiles(tiles, dimensionX, dimensionY); setEntities(entities); } -Map::~Map() { entities_.clear(); } +Map::~Map() {} void Map::setId(const uint16_t& id) { this->id_ = id; } -void Map::setCurrentType(const uint8_t& currentType) { this->currentType_ = currentType; } -void Map::setMapName(const std::string& mapName) { this->mapName_ = mapName; } -void Map::setBitmapName(const std::string& bitmapName) { this->bitmapName_ = bitmapName; } +void Map::setcurrentType(const uint8_t& current_type) { this->current_type_ = current_type; } +void Map::setMapName(const std::string& map_name) { this->map_name_ = map_name; } +void Map::setBitmapName(const std::string& bitmap_name) { this->bitmap_name_ = bitmap_name; } void Map::setTiles(const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY) { if (dimensionX == 0 || dimensionY == 0) { return; @@ -27,9 +27,9 @@ void Map::setEntities(const entityMap& entities) { this->entities_ = entities; } void Map::setTile(const utils::Coordinate& coordinate, const Tile& tile) { tiles_[coordinate.x][coordinate.y] = tile; } const uint16_t Map::getId() { return id_; } -const uint8_t Map::getCurrentType() { return currentType_; } -const std::string Map::getMapName() { return mapName_; } -const std::string Map::getBitmapName() { return bitmapName_; } +const uint8_t Map::getCurrentType() { return current_type_; } +const std::string Map::getMapName() { return map_name_; } +const std::string Map::getBitmapName() { return bitmap_name_; } const tileArray Map::getTiles() { return tiles_; } const entityMap Map::getEntities() { return entities_; } From 5aa42de4f7694a97081b29b9dce398b86fd1fbd8 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 14:06:57 +0100 Subject: [PATCH 52/62] Using consistent member name format "my_member" --- game/include/Map.hpp | 80 +++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/game/include/Map.hpp b/game/include/Map.hpp index 01efd78..84d667f 100644 --- a/game/include/Map.hpp +++ b/game/include/Map.hpp @@ -1,48 +1,50 @@ #pragma once #include -#include + #include -#include #include +#include +#include -using tileArray = boost::multi_array; -using entityMap = std::map; +using tileArray = boost::multi_array; +using entityMap = std::map; class Map { - private: - uint16_t id_; - uint8_t currentType_; - std::string mapName_; - std::string bitmapName_; - tileArray tiles_; - entityMap entities_; - - public: - Map(); - Map(const uint16_t& id, const uint8_t& currentType, const std::string& mapName, const std::string& bitmapName, const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY, - const entityMap& entities); - ~Map(); - - void setId(const uint16_t& id); - void setCurrentType(const uint8_t& currentType); - void setMapName(const std::string& mapName); - void setBitmapName(const std::string& bitmapName); - void setTiles(const tileArray tiles, const uint16_t& dimensionX, const uint16_t& dimensionY); - void setEntities(const entityMap& entities); - void setTile(const utils::Coordinate& coordinate, const Tile& tile); - - const uint16_t getId(); - const uint8_t getCurrentType(); - const std::string getMapName(); - const std::string getBitmapName(); - const tileArray getTiles(); - const entityMap getEntities(); - - void swapTiles(Tile tile1, Tile Tile2); - - bool doesItCollide(const tils::Coordinate& coordinate, const uint8_t& direction); - bool doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction); - bool isPokemonBattleTriggered(); - bool isTrainerBattleTriggered(); + private: + uint16_t id_; + uint8_t current_type_; + std::string map_name_; + std::string bitmap_name_; + tileArray tiles_; + entityMap entities_; + + public: + + Map(); + Map(const uint16_t &id, const uint8_t ¤t_type, const std::string &map_name, const std::string &bitmap_name, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities); + ~Map(); + + void setId(const uint16_t &id); + void setCurrentType(const uint8_t ¤t_type); + void setMapName(const std::string &map_name); + void setBitmapName(const std::string &bitmap_name); + void setTiles(const tileArray tiles, const uint16_t &dimensionX, const uint16_t &dimensionY); + void setEntities(const entityMap &entities); + void setTile(const utils::Coordinate &coordinate, const Tile &tile); + + const uint16_t getId(); + const uint8_t getCurrentType(); + const std::string getMapName(); + const std::string getBitmapName(); + const tileArray getTiles(); + const entityMap getEntities(); + + void swapTiles(Tile tile1, Tile Tile2); + + bool doesItCollide(const tils::Coordinate &coordinate, const uint8_t &direction); + bool doesItInteract(const utils::Coordinate &coordinate, const uint8_t &direction); + bool isPokemonBattleTriggered(); + bool isTrainerBattleTriggered(); + } \ No newline at end of file From 23904ceac2f80aeba21b741888081e8d7fef0f36 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 13:07:15 +0000 Subject: [PATCH 53/62] Autoformat code --- game/include/Map.hpp | 80 +++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/game/include/Map.hpp b/game/include/Map.hpp index 84d667f..8cf4f18 100644 --- a/game/include/Map.hpp +++ b/game/include/Map.hpp @@ -1,50 +1,48 @@ #pragma once #include - +#include #include -#include #include -#include +#include -using tileArray = boost::multi_array; -using entityMap = std::map; +using tileArray = boost::multi_array; +using entityMap = std::map; class Map { - private: - uint16_t id_; - uint8_t current_type_; - std::string map_name_; - std::string bitmap_name_; - tileArray tiles_; - entityMap entities_; - - public: - - Map(); - Map(const uint16_t &id, const uint8_t ¤t_type, const std::string &map_name, const std::string &bitmap_name, const tileArray &tiles, const uint16_t &dimensionX, const uint16_t &dimensionY, const entityMap &entities); - ~Map(); - - void setId(const uint16_t &id); - void setCurrentType(const uint8_t ¤t_type); - void setMapName(const std::string &map_name); - void setBitmapName(const std::string &bitmap_name); - void setTiles(const tileArray tiles, const uint16_t &dimensionX, const uint16_t &dimensionY); - void setEntities(const entityMap &entities); - void setTile(const utils::Coordinate &coordinate, const Tile &tile); - - const uint16_t getId(); - const uint8_t getCurrentType(); - const std::string getMapName(); - const std::string getBitmapName(); - const tileArray getTiles(); - const entityMap getEntities(); - - void swapTiles(Tile tile1, Tile Tile2); - - bool doesItCollide(const tils::Coordinate &coordinate, const uint8_t &direction); - bool doesItInteract(const utils::Coordinate &coordinate, const uint8_t &direction); - bool isPokemonBattleTriggered(); - bool isTrainerBattleTriggered(); - + private: + uint16_t id_; + uint8_t current_type_; + std::string map_name_; + std::string bitmap_name_; + tileArray tiles_; + entityMap entities_; + + public: + Map(); + Map(const uint16_t& id, const uint8_t& current_type, const std::string& map_name, const std::string& bitmap_name, const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY, + const entityMap& entities); + ~Map(); + + void setId(const uint16_t& id); + void setCurrentType(const uint8_t& current_type); + void setMapName(const std::string& map_name); + void setBitmapName(const std::string& bitmap_name); + void setTiles(const tileArray tiles, const uint16_t& dimensionX, const uint16_t& dimensionY); + void setEntities(const entityMap& entities); + void setTile(const utils::Coordinate& coordinate, const Tile& tile); + + const uint16_t getId(); + const uint8_t getCurrentType(); + const std::string getMapName(); + const std::string getBitmapName(); + const tileArray getTiles(); + const entityMap getEntities(); + + void swapTiles(Tile tile1, Tile Tile2); + + bool doesItCollide(const tils::Coordinate& coordinate, const uint8_t& direction); + bool doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction); + bool isPokemonBattleTriggered(); + bool isTrainerBattleTriggered(); } \ No newline at end of file From 0aed526cd3f33bd60980a8fb509bf5fbbd153709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gavil=C3=A1n?= Date: Sun, 18 Feb 2024 14:54:30 +0100 Subject: [PATCH 54/62] fix: Find Boost library CMakeLists.txt --- game/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index cd00ae2..0896530 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -14,7 +14,7 @@ set_target_properties(pokemon-lib PROPERTIES LINKER_LANGUAGE CXX) pkg_check_modules(ALLEGRO REQUIRED allegro-5 allegro_font-5 allegro_ttf-5 allegro_image-5 allegro_primitives-5) pkg_check_modules(JSONCPP REQUIRED jsoncpp) -pkg_check_modules(BOOST REQUIRED boost_all_dev) +FIND_PACKAGE( Boost 1.74 COMPONENTS REQUIRED ) target_include_directories(pokemon-lib PUBLIC include) target_include_directories(pokemon-lib PUBLIC ${JSONCPP_INCLUDE_DIRS}) From fd453439bac5e37ee33d2504d52b09be9bb216df Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 16:59:17 +0100 Subject: [PATCH 55/62] feat: install spdlog to Docker container and include it in CMake. --- .gitignore | 1 + Dockerfile | 1 + game/CMakeLists.txt | 1 + 3 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b330286..930ebc6 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ settings.json # Directories build/* +external_libs/* diff --git a/Dockerfile b/Dockerfile index 6a9df56..6901b98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,5 +22,6 @@ RUN apt-get install libjsoncpp-dev -y RUN apt-get install g++ -y RUN apt-get install pkgconf -y RUN apt-get install libgtest-dev -y +RUN apt-get install libspdlog-dev -y WORKDIR /pokemon_game \ No newline at end of file diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 0896530..4526b28 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -14,6 +14,7 @@ set_target_properties(pokemon-lib PROPERTIES LINKER_LANGUAGE CXX) pkg_check_modules(ALLEGRO REQUIRED allegro-5 allegro_font-5 allegro_ttf-5 allegro_image-5 allegro_primitives-5) pkg_check_modules(JSONCPP REQUIRED jsoncpp) +pkg_check_modules(SPDLOG REQUIRED spdlog) FIND_PACKAGE( Boost 1.74 COMPONENTS REQUIRED ) target_include_directories(pokemon-lib PUBLIC include) From 3d0d8c23cd7aa9c880b9a91adad9ee2a724abdb8 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 17:00:26 +0100 Subject: [PATCH 56/62] feat: Added tile matrix of dimension 0 error. Made some variables format coherent. --- game/include/Map.hpp | 8 ++++---- game/src/Map.cpp | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/game/include/Map.hpp b/game/include/Map.hpp index 8cf4f18..fccbabe 100644 --- a/game/include/Map.hpp +++ b/game/include/Map.hpp @@ -7,7 +7,7 @@ #include using tileArray = boost::multi_array; -using entityMap = std::map; +using entityMap = std::map; class Map { private: @@ -20,7 +20,7 @@ class Map { public: Map(); - Map(const uint16_t& id, const uint8_t& current_type, const std::string& map_name, const std::string& bitmap_name, const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY, + Map(const uint16_t& id, const uint8_t& current_type, const std::string& map_name, const std::string& bitmap_name, const tileArray& tiles, const uint16_t& length_x, const uint16_t& length_y, const entityMap& entities); ~Map(); @@ -28,7 +28,7 @@ class Map { void setCurrentType(const uint8_t& current_type); void setMapName(const std::string& map_name); void setBitmapName(const std::string& bitmap_name); - void setTiles(const tileArray tiles, const uint16_t& dimensionX, const uint16_t& dimensionY); + void setTiles(const tileArray tiles, const uint16_t& length_x, const uint16_t& length_y); void setEntities(const entityMap& entities); void setTile(const utils::Coordinate& coordinate, const Tile& tile); @@ -39,7 +39,7 @@ class Map { const tileArray getTiles(); const entityMap getEntities(); - void swapTiles(Tile tile1, Tile Tile2); + void swapTiles(Tile tile_1, Tile tile_2); bool doesItCollide(const tils::Coordinate& coordinate, const uint8_t& direction); bool doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction); diff --git a/game/src/Map.cpp b/game/src/Map.cpp index 8ecfaea..34f4831 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -1,12 +1,14 @@ #include -Map::Map(const uint16_t& id, const uint8_t& current_type, const std::string& map_name, const std::string& bitmap_name, const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY, +#include "spdlog/spdlog.h" + +Map::Map(const uint16_t& id, const uint8_t& current_type, const std::string& map_name, const std::string& bitmap_name, const tileArray& tiles, const uint16_t& length_x, const uint16_t& length_y, const entityMap& entities) { setId(id); setCurrentType(current_type); setMapName(map_name); setBitmapName(bitmap_name); - setTiles(tiles, dimensionX, dimensionY); + setTiles(tiles, length_x, length_y); setEntities(entities); } @@ -16,11 +18,13 @@ void Map::setId(const uint16_t& id) { this->id_ = id; } void Map::setcurrentType(const uint8_t& current_type) { this->current_type_ = current_type; } void Map::setMapName(const std::string& map_name) { this->map_name_ = map_name; } void Map::setBitmapName(const std::string& bitmap_name) { this->bitmap_name_ = bitmap_name; } -void Map::setTiles(const tileArray& tiles, const uint16_t& dimensionX, const uint16_t& dimensionY) { - if (dimensionX == 0 || dimensionY == 0) { +void Map::setTiles(const tileArray& tiles, const uint16_t& length_x, const uint16_t& length_y) { + if (length_x == 0 || length_y == 0) { + SPDLOG_ERROR("The tile matrix that is being set has a dimension of value 0. Exiting. "); + throw; return; } - tiles_.resize(boost::extents[dimensionX][dimensionY]); + tiles_.resize(boost::extents[length_x][length_y]); this->tiles_ = tiles; } void Map::setEntities(const entityMap& entities) { this->entities_ = entities; } @@ -33,10 +37,10 @@ const std::string Map::getBitmapName() { return bitmap_name_; } const tileArray Map::getTiles() { return tiles_; } const entityMap Map::getEntities() { return entities_; } -void Map::swapTiles(Tile& tile1, Tile& tile2) { - Tile tiletmp = tile1; - tile1 = tile2; - tile2 = tiletmp; +void Map::swapTiles(Tile& tile_1, Tile& tile_2) { + Tile tiletmp = tile_1; + tile_1 = tile_2; + tile_2 = tiletmp; } bool Map::doesItCollide(const utils::Coordinate& coordinate, const uint8_t& direction) { From a06f53de05d180aa8aaf8d7fc2bdcc5baa9d7ac0 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 17:09:48 +0100 Subject: [PATCH 57/62] fix: changed the argument type of the functions Tile::isCollision and isInteraction to uint8_t --- game/include/Tile.hpp | 4 ++-- game/src/Tile.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/game/include/Tile.hpp b/game/include/Tile.hpp index f7137be..1a1c60f 100644 --- a/game/include/Tile.hpp +++ b/game/include/Tile.hpp @@ -6,8 +6,8 @@ class Tile { public: Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_bitmask); ~Tile(); - bool isCollision(utils::Direction player_direction); - bool isInteraction(utils::Direction player_direction); + bool isCollision(uint8_t player_direction); + bool isInteraction(uint8_t player_direction); utils::Coordinate getCoordinate(); private: diff --git a/game/src/Tile.cpp b/game/src/Tile.cpp index 95b3608..9960d22 100644 --- a/game/src/Tile.cpp +++ b/game/src/Tile.cpp @@ -8,6 +8,6 @@ Tile::Tile(uint8_t collision_directions_bitmask, uint8_t interaction_directions_ Tile::~Tile() {} -bool Tile::isCollision(utils::Direction player_direction) { return player_direction & this->collision_directions_bitmask_; } +bool Tile::isCollision(uint8_t player_direction) { return player_direction & this->collision_directions_bitmask_; } -bool Tile::isInteraction(utils::Direction player_direction) { return player_direction & this->interaction_directions_bitmask_; } \ No newline at end of file +bool Tile::isInteraction(uint8_t player_direction) { return player_direction & this->interaction_directions_bitmask_; } \ No newline at end of file From 140381ec1946047a62e4741ea7fbab697565b0c6 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 17:13:15 +0100 Subject: [PATCH 58/62] fix: changed the argument type of the functions Map::doesItCollide and doesItInteract to uint8_t --- game/include/Map.hpp | 6 +++--- game/src/Map.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/game/include/Map.hpp b/game/include/Map.hpp index fccbabe..d169ca3 100644 --- a/game/include/Map.hpp +++ b/game/include/Map.hpp @@ -30,7 +30,7 @@ class Map { void setBitmapName(const std::string& bitmap_name); void setTiles(const tileArray tiles, const uint16_t& length_x, const uint16_t& length_y); void setEntities(const entityMap& entities); - void setTile(const utils::Coordinate& coordinate, const Tile& tile); + void setTile(const uint8_t& coordinate, const Tile& tile); const uint16_t getId(); const uint8_t getCurrentType(); @@ -41,8 +41,8 @@ class Map { void swapTiles(Tile tile_1, Tile tile_2); - bool doesItCollide(const tils::Coordinate& coordinate, const uint8_t& direction); - bool doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction); + bool doesItCollide(const uint8_t& coordinate, const uint8_t& direction); + bool doesItInteract(const uint8_t& coordinate, const uint8_t& direction); bool isPokemonBattleTriggered(); bool isTrainerBattleTriggered(); } \ No newline at end of file diff --git a/game/src/Map.cpp b/game/src/Map.cpp index 34f4831..ece2a26 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -28,7 +28,7 @@ void Map::setTiles(const tileArray& tiles, const uint16_t& length_x, const uint1 this->tiles_ = tiles; } void Map::setEntities(const entityMap& entities) { this->entities_ = entities; } -void Map::setTile(const utils::Coordinate& coordinate, const Tile& tile) { tiles_[coordinate.x][coordinate.y] = tile; } +void Map::setTile(const uint8_t& coordinate, const Tile& tile) { tiles_[coordinate.x][coordinate.y] = tile; } const uint16_t Map::getId() { return id_; } const uint8_t Map::getCurrentType() { return current_type_; } @@ -43,12 +43,12 @@ void Map::swapTiles(Tile& tile_1, Tile& tile_2) { tile_2 = tiletmp; } -bool Map::doesItCollide(const utils::Coordinate& coordinate, const uint8_t& direction) { +bool Map::doesItCollide(const uint8_t& coordinate, const uint8_t& direction) { Tile tile = tiles_[coordinate.x][coordinate.y]; return tile.isCollision(direction); } -bool Map::doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction) { +bool Map::doesItInteract(const uint8_t& coordinate, const uint8_t& direction) { Tile tile = tiles_[coordinate.x][coordinate.y]; return tile.isInteraction(direction); } \ No newline at end of file From cb7268c84af9c68c4e4bf22d32d1ec4f2646d682 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 17:23:45 +0100 Subject: [PATCH 59/62] fix: fixed passage of coordinates to collision and interaction functions --- game/include/Map.hpp | 6 +++--- game/include/utils.hpp | 4 ++-- game/src/Map.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/game/include/Map.hpp b/game/include/Map.hpp index d169ca3..ad06ca2 100644 --- a/game/include/Map.hpp +++ b/game/include/Map.hpp @@ -30,7 +30,7 @@ class Map { void setBitmapName(const std::string& bitmap_name); void setTiles(const tileArray tiles, const uint16_t& length_x, const uint16_t& length_y); void setEntities(const entityMap& entities); - void setTile(const uint8_t& coordinate, const Tile& tile); + void setTile(const utils::Coordinate& coordinate, const Tile& tile); const uint16_t getId(); const uint8_t getCurrentType(); @@ -41,8 +41,8 @@ class Map { void swapTiles(Tile tile_1, Tile tile_2); - bool doesItCollide(const uint8_t& coordinate, const uint8_t& direction); - bool doesItInteract(const uint8_t& coordinate, const uint8_t& direction); + bool doesItCollide(const utils::Coordinate& coordinate, const uint8_t& direction); + bool doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction); bool isPokemonBattleTriggered(); bool isTrainerBattleTriggered(); } \ No newline at end of file diff --git a/game/include/utils.hpp b/game/include/utils.hpp index f8f0dc4..7eecc51 100644 --- a/game/include/utils.hpp +++ b/game/include/utils.hpp @@ -4,8 +4,8 @@ namespace utils { struct Coordinate { - int x; - int y; + int16_t x; + int16_t y; }; typedef enum Direction : uint8_t { diff --git a/game/src/Map.cpp b/game/src/Map.cpp index ece2a26..9753f95 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -15,7 +15,7 @@ Map::Map(const uint16_t& id, const uint8_t& current_type, const std::string& map Map::~Map() {} void Map::setId(const uint16_t& id) { this->id_ = id; } -void Map::setcurrentType(const uint8_t& current_type) { this->current_type_ = current_type; } +void Map::setCurrentType(const uint8_t& current_type) { this->current_type_ = current_type; } void Map::setMapName(const std::string& map_name) { this->map_name_ = map_name; } void Map::setBitmapName(const std::string& bitmap_name) { this->bitmap_name_ = bitmap_name; } void Map::setTiles(const tileArray& tiles, const uint16_t& length_x, const uint16_t& length_y) { @@ -28,7 +28,7 @@ void Map::setTiles(const tileArray& tiles, const uint16_t& length_x, const uint1 this->tiles_ = tiles; } void Map::setEntities(const entityMap& entities) { this->entities_ = entities; } -void Map::setTile(const uint8_t& coordinate, const Tile& tile) { tiles_[coordinate.x][coordinate.y] = tile; } +void Map::setTile(const utils::Coordinate& coordinate, const Tile& tile) { tiles_[coordinate.x][coordinate.y] = tile; } const uint16_t Map::getId() { return id_; } const uint8_t Map::getCurrentType() { return current_type_; } @@ -43,12 +43,12 @@ void Map::swapTiles(Tile& tile_1, Tile& tile_2) { tile_2 = tiletmp; } -bool Map::doesItCollide(const uint8_t& coordinate, const uint8_t& direction) { +bool Map::doesItCollide(const utils::Coordinate& coordinate, const uint8_t& direction) { Tile tile = tiles_[coordinate.x][coordinate.y]; return tile.isCollision(direction); } -bool Map::doesItInteract(const uint8_t& coordinate, const uint8_t& direction) { +bool Map::doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction) { Tile tile = tiles_[coordinate.x][coordinate.y]; return tile.isInteraction(direction); } \ No newline at end of file From 6e7fbfaf7318faa7e2013b5befd7fb3728da34b9 Mon Sep 17 00:00:00 2001 From: MicheleMichetti Date: Sun, 18 Feb 2024 17:25:48 +0100 Subject: [PATCH 60/62] fix: swapTiles() in Map class coherence between cpp and hpp --- game/include/Map.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/include/Map.hpp b/game/include/Map.hpp index ad06ca2..4c546ac 100644 --- a/game/include/Map.hpp +++ b/game/include/Map.hpp @@ -39,7 +39,7 @@ class Map { const tileArray getTiles(); const entityMap getEntities(); - void swapTiles(Tile tile_1, Tile tile_2); + void swapTiles(Tile& tile_1, Tile& tile_2); bool doesItCollide(const utils::Coordinate& coordinate, const uint8_t& direction); bool doesItInteract(const utils::Coordinate& coordinate, const uint8_t& direction); From 026a9d58123e32112ae64a577d5d46f8dcc5933b Mon Sep 17 00:00:00 2001 From: michelemichetti Date: Sat, 9 Mar 2024 20:35:02 +0100 Subject: [PATCH 61/62] Added map type enum. Throw invalid_argument. Use std::swap --- game/include/utils.hpp | 12 +++++++++++- game/src/Map.cpp | 8 +++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/game/include/utils.hpp b/game/include/utils.hpp index 7eecc51..2053fcb 100644 --- a/game/include/utils.hpp +++ b/game/include/utils.hpp @@ -8,10 +8,20 @@ struct Coordinate { int16_t y; }; -typedef enum Direction : uint8_t { +enum Direction : uint8_t { up = 0b00000001, down = 0b00000010, left = 0b00000100, right = 0b00001000, }; + +enum MapTypes : uint8_t { + generic_building = 0b00000001, + outside_world = 0b00000010, + gym = 0b00000100, + rocket_hideout = 0b00001000, + cave = 0b00010000, + dark_cave = 0b00100000 +} + } // namespace utils diff --git a/game/src/Map.cpp b/game/src/Map.cpp index 9753f95..30138b9 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -20,8 +20,8 @@ void Map::setMapName(const std::string& map_name) { this->map_name_ = map_name; void Map::setBitmapName(const std::string& bitmap_name) { this->bitmap_name_ = bitmap_name; } void Map::setTiles(const tileArray& tiles, const uint16_t& length_x, const uint16_t& length_y) { if (length_x == 0 || length_y == 0) { - SPDLOG_ERROR("The tile matrix that is being set has a dimension of value 0. Exiting. "); - throw; + SPDLOG_ERROR("The tile matrix that is being set has dimension 0. Exiting. "); + throw std::invalid_argument("The tile matrix that is being set has dimension 0."); return; } tiles_.resize(boost::extents[length_x][length_y]); @@ -38,9 +38,7 @@ const tileArray Map::getTiles() { return tiles_; } const entityMap Map::getEntities() { return entities_; } void Map::swapTiles(Tile& tile_1, Tile& tile_2) { - Tile tiletmp = tile_1; - tile_1 = tile_2; - tile_2 = tiletmp; + std::swap(tile_1, tile_2); } bool Map::doesItCollide(const utils::Coordinate& coordinate, const uint8_t& direction) { From 38b83be8b41b8898fbd60b92c9d1a8ee0dcfd9df Mon Sep 17 00:00:00 2001 From: michelemichetti Date: Sat, 9 Mar 2024 19:36:12 +0000 Subject: [PATCH 62/62] Autoformat code --- game/include/utils.hpp | 9 +-------- game/src/Map.cpp | 4 +--- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/game/include/utils.hpp b/game/include/utils.hpp index 2053fcb..e5d273e 100644 --- a/game/include/utils.hpp +++ b/game/include/utils.hpp @@ -15,13 +15,6 @@ enum Direction : uint8_t { right = 0b00001000, }; -enum MapTypes : uint8_t { - generic_building = 0b00000001, - outside_world = 0b00000010, - gym = 0b00000100, - rocket_hideout = 0b00001000, - cave = 0b00010000, - dark_cave = 0b00100000 -} +enum MapTypes : uint8_t { generic_building = 0b00000001, outside_world = 0b00000010, gym = 0b00000100, rocket_hideout = 0b00001000, cave = 0b00010000, dark_cave = 0b00100000 } } // namespace utils diff --git a/game/src/Map.cpp b/game/src/Map.cpp index 30138b9..125b24b 100644 --- a/game/src/Map.cpp +++ b/game/src/Map.cpp @@ -37,9 +37,7 @@ const std::string Map::getBitmapName() { return bitmap_name_; } const tileArray Map::getTiles() { return tiles_; } const entityMap Map::getEntities() { return entities_; } -void Map::swapTiles(Tile& tile_1, Tile& tile_2) { - std::swap(tile_1, tile_2); -} +void Map::swapTiles(Tile& tile_1, Tile& tile_2) { std::swap(tile_1, tile_2); } bool Map::doesItCollide(const utils::Coordinate& coordinate, const uint8_t& direction) { Tile tile = tiles_[coordinate.x][coordinate.y];