summaryrefslogtreecommitdiff
path: root/graphs/cpp/hot_potato/bomb.cc
blob: 256e3d7b01bd05edcdad06a0f91150cda5c34fb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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_;
}