From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/cpp/hot_potato/bomb.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 graphs/cpp/hot_potato/bomb.cc (limited to 'graphs/cpp/hot_potato/bomb.cc') diff --git a/graphs/cpp/hot_potato/bomb.cc b/graphs/cpp/hot_potato/bomb.cc new file mode 100644 index 0000000..256e3d7 --- /dev/null +++ b/graphs/cpp/hot_potato/bomb.cc @@ -0,0 +1,28 @@ +#include "bomb.hh" + +#include +#include + +Bomb::Bomb(int ticks) +{ + if (ticks <= 0) + throw std::runtime_error{ + "Number of ticks should be strictly positive" + }; + max_ticks_ = ticks; + count_ = 0; +} +void Bomb::tick() +{ + if (count_ >= max_ticks_) + throw std::runtime_error{ "Bomb should have already exploded." }; + if (count_ % 2) + std::cout << "Tac!\n"; + else + std::cout << "Tic!\n"; + count_++; +} +bool Bomb::has_exploded() const +{ + return count_ >= max_ticks_; +} \ No newline at end of file -- cgit v1.2.3