mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
fix(game): add validation for card existence in GameState::play
- Throw exception if card is not found in player's hand. - Ensure loop exits correctly after playing the card.
This commit is contained in:
@@ -62,9 +62,13 @@ namespace UNO::GAME {
|
||||
}
|
||||
|
||||
const auto &handCardSet = this->getCurrentPlayer()->handCard->getCards();
|
||||
for (auto it = handCardSet.begin(); it != handCardSet.end(); it++) {
|
||||
for (auto it = handCardSet.begin(); ; it++) {
|
||||
if (it == handCardSet.end()) {
|
||||
throw std::invalid_argument("Card not found in hand");
|
||||
}
|
||||
if (card.getType() == it->getType() && (card.getType() == CardType::WILD || card.getType() == CardType::WILDDRAWFOUR || card.getColor() == it->getColor())) {
|
||||
this->getCurrentPlayer()->handCard->play(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user