@@ -66,21 +66,6 @@ const std::vector<std::pair<std::string, ColorGroup>> colorCodes = {
6666 {" \033 [38;2;102;0;255m" , PURPLE}
6767};
6868
69- inline ColorGroup stringColorGroupMatcher (const std::string& colorStr) {
70- if (colorStr == " brown" ) return ColorGroup::BROWN;
71- if (colorStr == " blue" ) return ColorGroup::BLUE;
72- if (colorStr == " pink" ) return ColorGroup::PINK;
73- if (colorStr == " orange" ) return ColorGroup::ORANGE;
74- if (colorStr == " red" ) return ColorGroup::RED;
75- if (colorStr == " yellow" ) return ColorGroup::YELLOW;
76- if (colorStr == " green" ) return ColorGroup::GREEN;
77- if (colorStr == " darkblue" ) return ColorGroup::DARK_BLUE;
78- if (colorStr == " gray" ) return ColorGroup::GRAY;
79- if (colorStr == " purple" ) return ColorGroup::PURPLE;
80-
81- return ColorGroup::NONE; // safer default
82- }
83-
8469void clearInputBuffer () {
8570 std::cin.clear ();
8671 std::cin.ignore (std::numeric_limits<std::streamsize>::max (), ' \n ' );
@@ -1327,36 +1312,34 @@ int main(){
13271312 <<std::endl;
13281313 std::cin>>sel;
13291314 } else { sel = 0 ; }
1315+
1316+ std::vector<std::size_t > turnOrder;
1317+ int index;
13301318 if (sel == 1 && std::cin.good ()){
13311319 importFile (gameBoard);
13321320 importFile (players);
1321+ importFile (freeParkingFunds, index, turnOrder);
13331322 }else {
13341323 gameBoard = initializeGameBoard ();
13351324 players = initializePlayers ();
1325+ // Randomize turn order
1326+ // create vector with player indices
1327+ turnOrder.resize (players.size ());
1328+ // fill vector with values 0, 1, ..., players.size() - 1
1329+ std::iota (turnOrder.begin (), turnOrder.end (), 0 );
1330+ // shuffle the vector
1331+ std::shuffle (turnOrder.begin (), turnOrder.end (), gen);
1332+ index = 0 ;
13361333 }
13371334 chanceCards = initializeChanceCards ();
13381335 communityCards = initializeCommunityCards ();
13391336
1340- // Randomize turn order
1341- // create vector with player indices
1342- std::vector<std::size_t > turnOrder (players.size ());
1343- // fill vector with values 0, 1, ..., players.size() - 1
1344- std::iota (turnOrder.begin (), turnOrder.end (), 0 );
1345- // shuffle the vector
1346- std::shuffle (turnOrder.begin (), turnOrder.end (), gen);
1347-
1348- int index = 0 ;
1349-
1350- if (sel == 1 && std::cin.good ()){
1351- importFile (freeParkingFunds, currentPlayerTurn, turnOrder);
1352- index = currentPlayerTurn;
1353- }
1354-
13551337 // Display Gameboard
13561338 displayGameBoard ();
13571339
13581340 do {
1359- player ¤tPlayer = players[index];
1341+ std::size_t playerIdx = turnOrder[index];
1342+ player ¤tPlayer = players[playerIdx];
13601343
13611344 // Skip bankrupt players
13621345 if (!currentPlayer.bankrupt ) {
@@ -1397,7 +1380,7 @@ int main(){
13971380 }
13981381 } else {
13991382 std::cout << " Game ended early.\n "
1400- <<" Do you want to export the game state?\n "
1383+ <<" Do you want to export the game state? (You turn ends with this action) \n "
14011384 <<" ┌────────┬────────┐\n "
14021385 <<" │ 1: YES │ 0: NO │\n "
14031386 <<" └────────┴────────┘\n "
@@ -1406,15 +1389,15 @@ int main(){
14061389 if (sel == 1 && std::cin.good ()){
14071390 exportFile (players);
14081391 exportFile (gameBoard);
1409- exportFile (freeParkingFunds, currentPlayerTurn, turnOrder);
1392+ exportFile (freeParkingFunds, (( currentPlayerTurn + 1 ) % turnOrder. size ()) , turnOrder);
14101393 std::cout<<" Exited with saving" <<std::endl;
14111394
14121395 }else if (sel == 0 && std::cin.good ()){
14131396 std::cout<<" Exited without saving" <<std::endl;
14141397 }else {
14151398 exportFile (players);
14161399 exportFile (gameBoard);
1417- exportFile (freeParkingFunds, currentPlayerTurn, turnOrder);
1400+ exportFile (freeParkingFunds, (( currentPlayerTurn + 1 ) % turnOrder. size ()) , turnOrder);
14181401 std::cout<<" Saved you :)" <<std::endl;
14191402 }
14201403 }
0 commit comments