summaryrefslogtreecommitdiff
path: root/graphs/cpp/hot_potato/bomb.cc
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/cpp/hot_potato/bomb.cc
add: graphs et rushs
Diffstat (limited to 'graphs/cpp/hot_potato/bomb.cc')
-rw-r--r--graphs/cpp/hot_potato/bomb.cc28
1 files changed, 28 insertions, 0 deletions
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 <iostream>
+#include <stdexcept>
+
+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