mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
feat(game): add operator< for Card
This commit is contained in:
@@ -68,4 +68,11 @@ namespace UNO::GAME {
|
||||
}
|
||||
return std::format("{} {}", this->colorToString(), this->typeToString());
|
||||
}
|
||||
|
||||
bool Card::operator<(const Card &other) const {
|
||||
if (this->color_ != other.color_) {
|
||||
return this->color_ < other.color_;
|
||||
}
|
||||
return this->type_ < other.type_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,11 @@ namespace UNO::GAME {
|
||||
* @return 卡牌对应的显示字符串
|
||||
*/
|
||||
[[nodiscard]] std::string toString() const;
|
||||
|
||||
/**
|
||||
* 比较运算符,用于排序
|
||||
*/
|
||||
bool operator<(const Card &other) const;
|
||||
};
|
||||
} // namespace UNO::GAME
|
||||
|
||||
|
||||
Reference in New Issue
Block a user