From 158319388488fa934584d2a7f7527dd733f528a3 Mon Sep 17 00:00:00 2001 From: Antoine COUTANT Date: Thu, 26 Jan 2023 23:37:36 +0100 Subject: [PATCH] feature-30: all rules can be layed at level 1 --- include/class-diagram.dia | 55 +++++++++++++++++++++++++++++++-- src/client/ClientGameEngine.cpp | 33 +++++++++++++++++--- src/shared/Caravan.cpp | 3 +- src/shared/City.cpp | 3 +- src/shared/ControlPawn.cpp | 3 +- src/shared/Map.cpp | 2 +- src/shared/Rules.cpp | 12 ++++--- test/shared/test_rules.cpp | 16 +++++----- test/shared/test_serialize.cpp | 8 ++--- 9 files changed, 109 insertions(+), 26 deletions(-) diff --git a/include/class-diagram.dia b/include/class-diagram.dia index 59616357..f958c431 100644 --- a/include/class-diagram.dia +++ b/include/class-diagram.dia @@ -20356,7 +20356,7 @@ - + @@ -20365,7 +20365,7 @@ - + #Caravan# @@ -20628,6 +20628,23 @@ + + + #player# + + + #std::string# + + + ## + + + ## + + + + + @@ -21165,6 +21182,23 @@ + + + #player# + + + #std::string# + + + ## + + + ## + + + + + @@ -21735,6 +21769,23 @@ + + + #player# + + + #std::string# + + + ## + + + ## + + + + + diff --git a/src/client/ClientGameEngine.cpp b/src/client/ClientGameEngine.cpp index fc0879c2..a236c4cb 100644 --- a/src/client/ClientGameEngine.cpp +++ b/src/client/ClientGameEngine.cpp @@ -145,11 +145,12 @@ void ClientGameEngine::runRule(shared::RuleArgsStruct ruleArgs) } else { - for (auto &player : otherPlayers) + for (auto player : otherPlayers) { + std::cout << "player name: " << player->getName() << std::endl; + std::cout << "ruleArgs.playerName: " << ruleArgs.playerName << std::endl; if (player->getName() == ruleArgs.playerName) { - ruleArgs.currentPlayer = player; rules.runTheRule(ruleArgs); } @@ -275,7 +276,10 @@ void ClientGameEngine::processServerRequest(std::string request) request = request.substr(10) + " join the game"; printChat(request); - otherPlayers.push_back(std::make_shared(player)); + if (player != myself->getName()) + { + otherPlayers.push_back(std::make_shared(player)); + } } else if (request.find("infoplayer") == 0) { @@ -284,6 +288,11 @@ void ClientGameEngine::processServerRequest(std::string request) { clientGame->addPlayer(player); } + + if (player != myself->getName()) + { + otherPlayers.push_back(std::make_shared(player)); + } } else { @@ -342,13 +351,29 @@ void ClientGameEngine::handleInformation(int x, int y) } if (ruleArgsStruct.ruleId == shared::CardsEnum::economy) { + clientGame->modifyTextForUser("Click on the hexagons of the path"); std::array position = {(unsigned)x, (unsigned)y}; ruleArgsStruct.caravanMovementPath.push_back(position); } if (ruleArgsStruct.ruleId == shared::CardsEnum::culture) { + clientGame->modifyTextForUser("place pawns on the hexagons"); + std::array position = {(unsigned)x, (unsigned)y}; + ruleArgsStruct.pawnsPositions.push_back(position); + } + if (ruleArgsStruct.ruleId == shared::CardsEnum::industry)// TODO : add the posibility to build wonder + { + clientGame->modifyTextForUser("place a city"); + std::array position = {(unsigned)x, (unsigned)y}; + ruleArgsStruct.positionOfCity = position; + ruleArgsStruct.industryCardBuildWonder = false; + } + if (ruleArgsStruct.ruleId == shared::CardsEnum::military) + { + clientGame->modifyTextForUser("choose pawns to reinforce"); std::array position = {(unsigned)x, (unsigned)y}; ruleArgsStruct.pawnsPositions.push_back(position); + ruleArgsStruct.militaryCardAttack = false; } } @@ -371,7 +396,7 @@ void ClientGameEngine::handlePriorityCardPlay(std::string typePlayed, int diffic { ruleArgsStruct.ruleId = shared::CardsEnum::culture; } - else if (typePlayed == "military") + else if (typePlayed == "army") { ruleArgsStruct.ruleId = shared::CardsEnum::military; } diff --git a/src/shared/Caravan.cpp b/src/shared/Caravan.cpp index 03f1806e..236f1626 100644 --- a/src/shared/Caravan.cpp +++ b/src/shared/Caravan.cpp @@ -8,9 +8,10 @@ Caravan::Caravan() this->used = false; } -Caravan::Caravan(std::array position) +Caravan::Caravan(std::array position, std::string player) { this->position = position; + this->player = player; } std::array Caravan::getPosition() diff --git a/src/shared/City.cpp b/src/shared/City.cpp index 7e5382b3..604fcf5a 100644 --- a/src/shared/City.cpp +++ b/src/shared/City.cpp @@ -10,12 +10,13 @@ City::City() this->position = {0, 0}; } -City::City(std::array position) +City::City(std::array position,std::string player) { this->position = position; this->isMature = false; this->isCapital = false; this->isStateCity = false; + this->player = player; } std::array City::getPosition() diff --git a/src/shared/ControlPawn.cpp b/src/shared/ControlPawn.cpp index a995b2a8..8ada868a 100644 --- a/src/shared/ControlPawn.cpp +++ b/src/shared/ControlPawn.cpp @@ -8,10 +8,11 @@ ControlPawn::ControlPawn() this->position = {0, 0}; } -ControlPawn::ControlPawn(std::array position) +ControlPawn::ControlPawn(std::array position, std::string player) { this->reinforced = false; this->position = position; + this->player = player; } bool ControlPawn::isReinforced() diff --git a/src/shared/Map.cpp b/src/shared/Map.cpp index 90e588d4..c6ce4940 100644 --- a/src/shared/Map.cpp +++ b/src/shared/Map.cpp @@ -195,7 +195,7 @@ void Map::generateRandomMap(int seed) if (remainingIndex.empty() == false) { int index = remainingIndex[rand() % remainingIndex.size()]; // remainingIndex is not empty - std::shared_ptr city = std::make_shared(position); + std::shared_ptr city = std::make_shared(position, "not defined"); // TODO: check if we place random cities city->setStateCity(stateCityField[index]); remainingCity[index] = false; mapOfTheGame[i * this->width + j]->addElement(std::make_shared(*city)); diff --git a/src/shared/Rules.cpp b/src/shared/Rules.cpp index 3ca70d0c..24d20459 100644 --- a/src/shared/Rules.cpp +++ b/src/shared/Rules.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #define RULESLENGTH 16 #define CARAVAN_STEPS_AT_LEVEL_1 3 @@ -37,6 +38,7 @@ Rules::Rules() */ bool Rules::runTheRule(RuleArgsStruct &args) { + std::cout << "runTheRule" << std::endl; switch (args.ruleId) { case CardsEnum::economy: @@ -184,7 +186,7 @@ void Rules::addCaravanAfterCardAmelioration(std::vector while (caravans.size() < (std::size_t)numberOfCaravans) { std::array pos = {0, 0}; - std::shared_ptr caravan = std::make_shared(pos); + std::shared_ptr caravan = std::make_shared(pos, currentPlayer->getName()); currentPlayer->addCaravan(caravan); caravans.push_back(caravan); } @@ -518,9 +520,9 @@ bool Rules::placeControlPawns(std::vector> positions, st return false; } } - if (isThereACityAround(position, gameMap) || true) // TODO : delete this true, it is for testing + if (isThereACityAround(position, gameMap)) { - std::shared_ptr controlPawn = std::make_shared(position); + std::shared_ptr controlPawn = std::make_shared(position, currentPlayer->getName()); currentPlayer->addControlPawn(controlPawn); std::variant element = *controlPawn; (*gameMap)(position[0], position[1])->addElement(std::make_shared>(element)); @@ -586,6 +588,7 @@ bool Rules::isThereAControlPawnAround(std::array position, std::sha */ bool Rules::playMilitaryCard(RuleArgsStruct &args) { + std::cout << "playMilitaryCard" << std::endl; if (args.militaryCardAttack == true) { return attack(args); @@ -617,6 +620,7 @@ bool Rules::attack(RuleArgsStruct &args) */ bool Rules::reinforce(RuleArgsStruct &args) { + std::cout << "reinforce" << std::endl; unsigned numberOfBoxUsed = args.numberOfBoxUsed; if (numberOfBoxUsed > args.currentPlayer->getNumberOfBox(CardsEnum::military)) { @@ -709,7 +713,7 @@ bool Rules::buildCity(RuleArgsStruct &args) // TODO : Check the distance to cont return false; } } - std::shared_ptr city = std::make_shared(position); + std::shared_ptr city = std::make_shared(position, args.currentPlayer->getName()); args.currentPlayer->addCity(city); (*gameMap)(position[0], position[1])->addElement(std::make_shared>(*city)); diff --git a/test/shared/test_rules.cpp b/test/shared/test_rules.cpp index 61c5139b..9f220743 100644 --- a/test/shared/test_rules.cpp +++ b/test/shared/test_rules.cpp @@ -88,19 +88,19 @@ BOOST_AUTO_TEST_CASE(TestRulesScienceCardLevel4) map->init(); std::array position = {5, 5}; - std::shared_ptr controlPawn = std::make_shared(position); + std::shared_ptr controlPawn = std::make_shared(position, player->getName()); player->addControlPawn(controlPawn); std::variant element = *controlPawn; (*map)(5, 5)->addElement(std::make_shared>(element)); position = {4, 4}; - controlPawn = std::make_shared(position); + controlPawn = std::make_shared(position, player->getName()); player->addControlPawn(controlPawn); element = *controlPawn; (*map)(4, 4)->addElement(std::make_shared>(element)); position = {6, 6}; - controlPawn = std::make_shared(position); + controlPawn = std::make_shared(position, player->getName()); player->addControlPawn(controlPawn); element = *controlPawn; (*map)(6, 6)->addElement(std::make_shared>(element)); @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(TestRulesEconomyCardLevel1) map->init(); std::array position = {0, 1}; - std::shared_ptr city = std::make_shared(position); + std::shared_ptr city = std::make_shared(position, player->getName()); player->addCity(city); std::variant element = *city; (*map)(0, 1)->addElement(std::make_shared>(element)); @@ -167,19 +167,19 @@ BOOST_AUTO_TEST_CASE(TestRulesMilitaryReinforceAllLevels) args.pawnsPositions.push_back({3, 4}); std::array position = {2, 2}; - std::shared_ptr controlPawn = std::make_shared(position); + std::shared_ptr controlPawn = std::make_shared(position, player->getName()); player->addControlPawn(controlPawn); std::variant element = *controlPawn; (*map)(2, 2)->addElement(std::make_shared>(element)); position = {3, 4}; - controlPawn = std::make_shared(position); + controlPawn = std::make_shared(position, player->getName()); player->addControlPawn(controlPawn); element = *controlPawn; (*map)(3, 4)->addElement(std::make_shared>(element)); position = {5, 5}; - controlPawn = std::make_shared(position); + controlPawn = std::make_shared(position, player->getName()); player->addControlPawn(controlPawn); element = *controlPawn; (*map)(5, 5)->addElement(std::make_shared>(element)); @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(TestRulesCultureCardLevel1) map->init(); std::array position = {4, 3}; - std::shared_ptr city = std::make_shared(position); + std::shared_ptr city = std::make_shared(position, player->getName()); player->addCity(city); std::variant element = *city; (*map)(position[0], position[1])->addElement(std::make_shared>(element)); diff --git a/test/shared/test_serialize.cpp b/test/shared/test_serialize.cpp index 6ed2ee3b..531a87a5 100644 --- a/test/shared/test_serialize.cpp +++ b/test/shared/test_serialize.cpp @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(BarbarianVillage) BOOST_AUTO_TEST_CASE(Caravan) { - shared::Caravan caravan({2, 4}); + shared::Caravan caravan({2, 4}, "not defined"); caravan.setUsed(true); caravan.player = "player"; shared::Binary binary; @@ -95,7 +95,7 @@ BOOST_AUTO_TEST_CASE(Caravan) BOOST_AUTO_TEST_CASE(City) { - shared::City city({2, 4}); + shared::City city({2, 4}, "not defined"); city.setStateCity(shared::CityStateEnum::seoul); city.player = "player"; shared::Binary binary; @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(City) BOOST_AUTO_TEST_CASE(ControlPawn) { - shared::ControlPawn controlPawn({2, 4}); + shared::ControlPawn controlPawn({2, 4}, "not defined"); controlPawn.setReinforced(); controlPawn.player = "player"; shared::Binary binary; @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(Hexagon) { shared::Hexagon hexagon; hexagon.setFieldType(shared::FieldLevel::Mountain); - shared::ControlPawn controlPawn({2, 4}); + shared::ControlPawn controlPawn({2, 4}, "not defined"); controlPawn.setReinforced(); controlPawn.player = "player"; std::shared_ptr> elem;