diff --git a/src/game/Card.cpp b/src/game/Card.cpp index b50b786..666a603 100644 --- a/src/game/Card.cpp +++ b/src/game/Card.cpp @@ -76,12 +76,13 @@ namespace UNO::GAME { return this->type_ < other.type_; } - bool Card::canBePlayedOn(const Card &other) const + bool Card::canBePlayedOn(const Card &other, size_t drawCount) const { - if (other.getType() == CardType::DRAW2 && this->type_ != CardType::DRAW2 && this->type_ != CardType::WILDDRAWFOUR) { + if (drawCount != 0 && other.getType() == CardType::DRAW2 && this->type_ != CardType::DRAW2 + && this->type_ != CardType::WILDDRAWFOUR) { return false; } - if (other.getType() == CardType::WILDDRAWFOUR && this->type_ != CardType::WILDDRAWFOUR) { + if (drawCount != 0 && other.getType() == CardType::WILDDRAWFOUR && this->type_ != CardType::WILDDRAWFOUR) { return false; } if (this->type_ == CardType::WILD || this->type_ == CardType::WILDDRAWFOUR) { diff --git a/src/game/Card.h b/src/game/Card.h index 0bc3406..d24be26 100644 --- a/src/game/Card.h +++ b/src/game/Card.h @@ -91,7 +91,7 @@ namespace UNO::GAME { * @param other 另一张牌 * @return 是否能在打出另一张牌后打出 */ - [[nodiscard]] bool canBePlayedOn(const Card &other) const; + [[nodiscard]] bool canBePlayedOn(const Card &other, size_t drawCount) const; }; } // namespace UNO::GAME diff --git a/src/game/GameState.h b/src/game/GameState.h index 7cae6a4..398b946 100644 --- a/src/game/GameState.h +++ b/src/game/GameState.h @@ -285,7 +285,7 @@ namespace UNO::GAME { template void GameState::updateStateByCard(const Card &card) { - if (this->discardPile_.isEmpty() == false && card.canBePlayedOn(this->discardPile_.getFront()) == false) { + if (this->discardPile_.isEmpty() == false && card.canBePlayedOn(this->discardPile_.getFront(), this->drawCount_) == false) { throw std::invalid_argument("Card cannot be played"); } this->currentPlayer_->play(card);