diff --git a/src/game/Card.cpp b/src/game/Card.cpp index 9abf7a7..c6b6d46 100644 --- a/src/game/Card.cpp +++ b/src/game/Card.cpp @@ -75,4 +75,22 @@ namespace UNO::GAME { } return this->type_ < other.type_; } + + bool Card::canBePlayedOn(const Card &other) const + { + if (other.getType()== CardType::DRAW2 && this->type_ != CardType::DRAW2 && this->type_ != CardType::WILDDRAWFOUR) { + return false; + } + if (other.getType() == CardType::WILDDRAWFOUR && this->type_ != CardType::WILDDRAWFOUR) { + return false; + } + if (this->color_ == CardColor::WILD) { + return true; + } + if (this->color_ == other.getColor() || this->type_ == other.getType()) { + return true; + } + return false; + } + } diff --git a/src/game/Card.h b/src/game/Card.h index 3082265..a30012d 100644 --- a/src/game/Card.h +++ b/src/game/Card.h @@ -86,6 +86,12 @@ namespace UNO::GAME { * 比较运算符,用于排序 */ bool operator<(const Card &other) const; + + /** + * @param other 另一张牌 + * @return 是否能在打出另一张牌后打出 + */ + [[nodiscard]] bool canBePlayedOn(const Card &other) const; }; } // namespace UNO::GAME