feat(game): add canBePlayedOn for Card

This commit is contained in:
Kieran Kihn
2025-11-16 19:52:47 +08:00
parent 1b9ff0b413
commit da0f2160ce
2 changed files with 24 additions and 0 deletions

View File

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

View File

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