diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/cpp/exception/game.cc | |
add: graphs et rushs
Diffstat (limited to 'graphs/cpp/exception/game.cc')
| -rw-r--r-- | graphs/cpp/exception/game.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/graphs/cpp/exception/game.cc b/graphs/cpp/exception/game.cc new file mode 100644 index 0000000..88d435c --- /dev/null +++ b/graphs/cpp/exception/game.cc @@ -0,0 +1,23 @@ +#include "game.hh" + +#include <iostream> + +Game::Game(int secret) + : secret_(secret) +{} + +void Game::play(const Player& p1, const Player& p2) const +{ + if (p1 == p2) + throw InvalidArgumentException{ "Stop playing by yourself!" }; + + auto d1 = std::abs(p1.get_guess() - secret_); + auto d2 = std::abs(p2.get_guess() - secret_); + + if (d1 > d2) + std::cout << p1 << " wins!" << std::endl; + else if (d1 < d2) + std::cout << p2 << " wins!" << std::endl; + else + std::cout << "Draw!" << std::endl; +} |
