summaryrefslogtreecommitdiff
path: root/graphs/cpp/hot_potato/bomb.cc
diff options
context:
space:
mode:
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