Skip to content

Commit ecd6e9c

Browse files
committed
2 parents 971255c + dca314e commit ecd6e9c

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

monopoly.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,14 +1006,14 @@ bool trading_menue(player &p){
10061006
for(player pl : players){
10071007
if(pl.playerId != p.playerId){
10081008
otherplayers.push_back(pl.playerId);
1009-
std::cout<< i << " | " << pl.name << "\n";
1009+
std::cout<< std::string(i < 10 ? "0" : "") << i << " | " << pl.name << "\n";
10101010
i++;
10111011
}
10121012
}
10131013
std::cout<<"99 | go back\n"
10141014
<<std::endl;
10151015
std::cin>>sel;
1016-
if(sel < otherplayers.size()){
1016+
if(sel < otherplayers.size() && sel >=0 && std::cin.good()){
10171017
int amount1;
10181018
int amount2;
10191019
std::vector<int> tiles1;
@@ -1024,10 +1024,12 @@ bool trading_menue(player &p){
10241024
<<"How Much money do you want to give " << colorCodes[players[otherplayers[sel]].color].first << players[otherplayers[sel]].symbol << " " << players[otherplayers[sel]].name << RESET_COLOR << "?" <<std::endl;
10251025
while (true){
10261026
std::cin>>amount1;
1027-
if (amount1 <= p.money){
1027+
if (amount1 <= p.money && std::cin.good()){
10281028
break;
1029-
}else{
1029+
}else if(amount1 > p.money && std::cin.good()){
10301030
std::cout<<"You don't have enough money! 😡"<<std::endl;
1031+
} else {
1032+
std::cout<<"No valid input! 😡"<<std::endl;
10311033
clearInputBuffer();
10321034
}
10331035
}
@@ -1049,7 +1051,7 @@ bool trading_menue(player &p){
10491051
std::cout<< "99 | Finished in this menue" <<std::endl;
10501052
std::cout<<"Wich do you choose?"<<std::endl;
10511053
std::cin>>tilesel;
1052-
if(tilesel !=99 && tilesel < p.ownedStreets.size()){
1054+
if(tilesel !=99 && tilesel < p.ownedStreets.size() && std::cin.good() && tilesel >=0){
10531055
tiles1.push_back(p.ownedStreets[tilesel]);
10541056
}
10551057
}while(tilesel != 99);
@@ -1065,10 +1067,12 @@ bool trading_menue(player &p){
10651067
<<"How Much money do you want from " << colorCodes[players[otherplayers[sel]].color].first << players[otherplayers[sel]].symbol << " " << players[otherplayers[sel]].name << RESET_COLOR << "?" <<std::endl;
10661068
while (true){
10671069
std::cin>>amount2;
1068-
if (amount2 <= players[otherplayers[sel]].money){
1070+
if (amount2 <= players[otherplayers[sel]].money && std::cin.good()){
10691071
break;
1070-
}else{
1072+
}else if(amount2 > players[otherplayers[sel]].money && std::cin.good()){
10711073
std::cout<<"You don't have enough money! 😡"<<std::endl;
1074+
} else {
1075+
std::cout<<"No valid input! 😡"<<std::endl;
10721076
clearInputBuffer();
10731077
}
10741078
}
@@ -1091,7 +1095,7 @@ bool trading_menue(player &p){
10911095
std::cout<< "99 | Finished in this menue" <<std::endl;
10921096
std::cout<<"Wich do you choose?"<<std::endl;
10931097
std::cin>>tilesel;
1094-
if(tilesel !=99 && tilesel < players[otherplayers[sel]].ownedStreets.size()){
1098+
if(tilesel !=99 && tilesel < players[otherplayers[sel]].ownedStreets.size() && std::cin.good() && tilesel >=0){
10951099
tiles2.push_back(players[otherplayers[sel]].ownedStreets[tilesel]);
10961100
}
10971101
}while(tilesel != 99);
@@ -1121,7 +1125,7 @@ bool trading_menue(player &p){
11211125
<<"└────────┴────────┘\n"
11221126
<<std::endl;
11231127
std::cin>>desicion;
1124-
}while (desicion != 0 && desicion != 1);
1128+
}while (desicion != 0 && desicion != 1 && std::cin.good());
11251129
if(!desicion){
11261130
displayGameBoard();
11271131
std::cout<<"They didn't want your offer! 😡"<<std::endl;

0 commit comments

Comments
 (0)