Skip to content

Commit

Permalink
feature-30: all rules can be layed at level 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jard-111 committed Jan 26, 2023
1 parent 3b04bff commit 1583193
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 26 deletions.
55 changes: 53 additions & 2 deletions include/class-diagram.dia
Original file line number Diff line number Diff line change
Expand Up @@ -20356,7 +20356,7 @@
<dia:point val="123.955,61.4873"/>
</dia:attribute>
<dia:attribute name="obj_bb">
<dia:rectangle val="123.905,61.4373;155.305,72.9373"/>
<dia:rectangle val="123.905,61.4373;155.305,73.7373"/>
</dia:attribute>
<dia:attribute name="elem_corner">
<dia:point val="123.955,61.4873"/>
Expand All @@ -20365,7 +20365,7 @@
<dia:real val="31.300000000000001"/>
</dia:attribute>
<dia:attribute name="elem_height">
<dia:real val="11.4"/>
<dia:real val="12.199999999999999"/>
</dia:attribute>
<dia:attribute name="name">
<dia:string>#Caravan#</dia:string>
Expand Down Expand Up @@ -20628,6 +20628,23 @@
<dia:enum val="0"/>
</dia:attribute>
</dia:composite>
<dia:composite type="umlparameter">
<dia:attribute name="name">
<dia:string>#player#</dia:string>
</dia:attribute>
<dia:attribute name="type">
<dia:string>#std::string#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
</dia:attribute>
<dia:attribute name="comment">
<dia:string>##</dia:string>
</dia:attribute>
<dia:attribute name="kind">
<dia:enum val="0"/>
</dia:attribute>
</dia:composite>
</dia:attribute>
</dia:composite>
<dia:composite type="umloperation">
Expand Down Expand Up @@ -21165,6 +21182,23 @@
<dia:enum val="0"/>
</dia:attribute>
</dia:composite>
<dia:composite type="umlparameter">
<dia:attribute name="name">
<dia:string>#player#</dia:string>
</dia:attribute>
<dia:attribute name="type">
<dia:string>#std::string#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
</dia:attribute>
<dia:attribute name="comment">
<dia:string>##</dia:string>
</dia:attribute>
<dia:attribute name="kind">
<dia:enum val="0"/>
</dia:attribute>
</dia:composite>
</dia:attribute>
</dia:composite>
<dia:composite type="umloperation">
Expand Down Expand Up @@ -21735,6 +21769,23 @@
<dia:enum val="0"/>
</dia:attribute>
</dia:composite>
<dia:composite type="umlparameter">
<dia:attribute name="name">
<dia:string>#player#</dia:string>
</dia:attribute>
<dia:attribute name="type">
<dia:string>#std::string#</dia:string>
</dia:attribute>
<dia:attribute name="value">
<dia:string>##</dia:string>
</dia:attribute>
<dia:attribute name="comment">
<dia:string>##</dia:string>
</dia:attribute>
<dia:attribute name="kind">
<dia:enum val="0"/>
</dia:attribute>
</dia:composite>
</dia:attribute>
</dia:composite>
<dia:composite type="umloperation">
Expand Down
33 changes: 29 additions & 4 deletions src/client/ClientGameEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<shared::Player>(player));
if (player != myself->getName())
{
otherPlayers.push_back(std::make_shared<shared::Player>(player));
}
}
else if (request.find("infoplayer") == 0)
{
Expand All @@ -284,6 +288,11 @@ void ClientGameEngine::processServerRequest(std::string request)
{
clientGame->addPlayer(player);
}

if (player != myself->getName())
{
otherPlayers.push_back(std::make_shared<shared::Player>(player));
}
}
else
{
Expand Down Expand Up @@ -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<unsigned, 2> 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<unsigned, 2> 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<unsigned, 2> 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<unsigned, 2> position = {(unsigned)x, (unsigned)y};
ruleArgsStruct.pawnsPositions.push_back(position);
ruleArgsStruct.militaryCardAttack = false;
}
}

Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/shared/Caravan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Caravan::Caravan()
this->used = false;
}

Caravan::Caravan(std::array<unsigned, 2> position)
Caravan::Caravan(std::array<unsigned, 2> position, std::string player)
{
this->position = position;
this->player = player;
}

std::array<unsigned, 2> Caravan::getPosition()
Expand Down
3 changes: 2 additions & 1 deletion src/shared/City.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ City::City()
this->position = {0, 0};
}

City::City(std::array<unsigned, 2> position)
City::City(std::array<unsigned, 2> position,std::string player)
{
this->position = position;
this->isMature = false;
this->isCapital = false;
this->isStateCity = false;
this->player = player;
}

std::array<unsigned, 2> City::getPosition()
Expand Down
3 changes: 2 additions & 1 deletion src/shared/ControlPawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ ControlPawn::ControlPawn()
this->position = {0, 0};
}

ControlPawn::ControlPawn(std::array<unsigned, 2> position)
ControlPawn::ControlPawn(std::array<unsigned, 2> position, std::string player)
{
this->reinforced = false;
this->position = position;
this->player = player;
}

bool ControlPawn::isReinforced()
Expand Down
2 changes: 1 addition & 1 deletion src/shared/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<shared::City> city = std::make_shared<shared::City>(position);
std::shared_ptr<shared::City> city = std::make_shared<shared::City>(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<variantElement>(*city));
Expand Down
12 changes: 8 additions & 4 deletions src/shared/Rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <algorithm>
#include <vector>
#include <array>
#include <iostream>

#define RULESLENGTH 16
#define CARAVAN_STEPS_AT_LEVEL_1 3
Expand Down Expand Up @@ -37,6 +38,7 @@ Rules::Rules()
*/
bool Rules::runTheRule(RuleArgsStruct &args)
{
std::cout << "runTheRule" << std::endl;
switch (args.ruleId)
{
case CardsEnum::economy:
Expand Down Expand Up @@ -184,7 +186,7 @@ void Rules::addCaravanAfterCardAmelioration(std::vector<std::shared_ptr<Caravan>
while (caravans.size() < (std::size_t)numberOfCaravans)
{
std::array<unsigned, 2> pos = {0, 0};
std::shared_ptr<Caravan> caravan = std::make_shared<Caravan>(pos);
std::shared_ptr<Caravan> caravan = std::make_shared<Caravan>(pos, currentPlayer->getName());
currentPlayer->addCaravan(caravan);
caravans.push_back(caravan);
}
Expand Down Expand Up @@ -518,9 +520,9 @@ bool Rules::placeControlPawns(std::vector<std::array<unsigned, 2>> positions, st
return false;
}
}
if (isThereACityAround(position, gameMap) || true) // TODO : delete this true, it is for testing
if (isThereACityAround(position, gameMap))
{
std::shared_ptr<shared::ControlPawn> controlPawn = std::make_shared<shared::ControlPawn>(position);
std::shared_ptr<shared::ControlPawn> controlPawn = std::make_shared<shared::ControlPawn>(position, currentPlayer->getName());
currentPlayer->addControlPawn(controlPawn);
std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City> element = *controlPawn;
(*gameMap)(position[0], position[1])->addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element));
Expand Down Expand Up @@ -586,6 +588,7 @@ bool Rules::isThereAControlPawnAround(std::array<unsigned, 2> position, std::sha
*/
bool Rules::playMilitaryCard(RuleArgsStruct &args)
{
std::cout << "playMilitaryCard" << std::endl;
if (args.militaryCardAttack == true)
{
return attack(args);
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -709,7 +713,7 @@ bool Rules::buildCity(RuleArgsStruct &args) // TODO : Check the distance to cont
return false;
}
}
std::shared_ptr<City> city = std::make_shared<City>(position);
std::shared_ptr<City> city = std::make_shared<City>(position, args.currentPlayer->getName());
args.currentPlayer->addCity(city);
(*gameMap)(position[0], position[1])->addElement(std::make_shared<std::variant<Caravan, Barbarian, BarbarianVillage, ControlPawn, City>>(*city));

Expand Down
16 changes: 8 additions & 8 deletions test/shared/test_rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ BOOST_AUTO_TEST_CASE(TestRulesScienceCardLevel4)
map->init();

std::array<unsigned, 2> position = {5, 5};
std::shared_ptr<shared::ControlPawn> controlPawn = std::make_shared<shared::ControlPawn>(position);
std::shared_ptr<shared::ControlPawn> controlPawn = std::make_shared<shared::ControlPawn>(position, player->getName());
player->addControlPawn(controlPawn);
std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City> element = *controlPawn;
(*map)(5, 5)->addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element));

position = {4, 4};
controlPawn = std::make_shared<shared::ControlPawn>(position);
controlPawn = std::make_shared<shared::ControlPawn>(position, player->getName());
player->addControlPawn(controlPawn);
element = *controlPawn;
(*map)(4, 4)->addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element));

position = {6, 6};
controlPawn = std::make_shared<shared::ControlPawn>(position);
controlPawn = std::make_shared<shared::ControlPawn>(position, player->getName());
player->addControlPawn(controlPawn);
element = *controlPawn;
(*map)(6, 6)->addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element));
Expand All @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(TestRulesEconomyCardLevel1)
map->init();

std::array<unsigned, 2> position = {0, 1};
std::shared_ptr<shared::City> city = std::make_shared<shared::City>(position);
std::shared_ptr<shared::City> city = std::make_shared<shared::City>(position, player->getName());
player->addCity(city);
std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City> element = *city;
(*map)(0, 1)->addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element));
Expand Down Expand Up @@ -167,19 +167,19 @@ BOOST_AUTO_TEST_CASE(TestRulesMilitaryReinforceAllLevels)
args.pawnsPositions.push_back({3, 4});

std::array<unsigned, 2> position = {2, 2};
std::shared_ptr<shared::ControlPawn> controlPawn = std::make_shared<shared::ControlPawn>(position);
std::shared_ptr<shared::ControlPawn> controlPawn = std::make_shared<shared::ControlPawn>(position, player->getName());
player->addControlPawn(controlPawn);
std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City> element = *controlPawn;
(*map)(2, 2)->addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element));

position = {3, 4};
controlPawn = std::make_shared<shared::ControlPawn>(position);
controlPawn = std::make_shared<shared::ControlPawn>(position, player->getName());
player->addControlPawn(controlPawn);
element = *controlPawn;
(*map)(3, 4)->addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element));

position = {5, 5};
controlPawn = std::make_shared<shared::ControlPawn>(position);
controlPawn = std::make_shared<shared::ControlPawn>(position, player->getName());
player->addControlPawn(controlPawn);
element = *controlPawn;
(*map)(5, 5)->addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element));
Expand Down Expand Up @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(TestRulesCultureCardLevel1)
map->init();

std::array<unsigned, 2> position = {4, 3};
std::shared_ptr<shared::City> city = std::make_shared<shared::City>(position);
std::shared_ptr<shared::City> city = std::make_shared<shared::City>(position, player->getName());
player->addCity(city);
std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City> element = *city;
(*map)(position[0], position[1])->addElement(std::make_shared<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>>(element));
Expand Down
8 changes: 4 additions & 4 deletions test/shared/test_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<std::variant<shared::Caravan, shared::Barbarian, shared::BarbarianVillage, shared::ControlPawn, shared::City>> elem;
Expand Down

0 comments on commit 1583193

Please sign in to comment.