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:
Kieran Kihn
2025-11-17 15:49:45 +08:00
parent cbb49343bc
commit d5e1d7f03d

View File

@@ -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;
}
}