mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 10:23:16 +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());
|
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 卡牌对应的显示字符串
|
* @return 卡牌对应的显示字符串
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::string toString() const;
|
[[nodiscard]] std::string toString() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比较运算符,用于排序
|
||||||
|
*/
|
||||||
|
bool operator<(const Card &other) const;
|
||||||
};
|
};
|
||||||
} // namespace UNO::GAME
|
} // namespace UNO::GAME
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user