mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
feat(game): add canBePlayedOn for Card
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user