-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
72 lines (61 loc) · 1.73 KB
/
main.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <thread>
using namespace std;
class trash_guy {
const string HAPPY_LEFT = "(> ^_^)>";
const string HAPPY_RIGHT = "<(^_^ <)";
const string THRASH = "🗑️";
const int INTERVAL = 500;
string text;
static string repeat_space(const int times) {
string result;
for (int i = 0; i < times; ++i) result += ' ';
return result;
}
void play() {
char l;
int inc = 0;
while ((l = text[0]) != '\0') {
bool going_right = true;
for (int left_space = 0, right_space = 10 + inc;;) {
system("clear");
cout << THRASH << repeat_space(left_space)
<< (going_right ? HAPPY_LEFT : l + HAPPY_RIGHT)
<< repeat_space(right_space) << text << endl;
this_thread::sleep_for(chrono::milliseconds(INTERVAL));
if (going_right && left_space >= 10 + inc) {
going_right = false;
left_space = 10;
right_space = inc++;
text.erase(0, 1);
} else if (!going_right && right_space >= 10) {
break;
}
if (going_right) {
left_space++;
right_space--;
} else {
left_space--;
right_space++;
}
}
}
}
public:
void add(string& _text) {
this->text += _text;
play();
}
};
int main() {
trash_guy guy;
while (true) {
string text;
cin >> text;
if (text == "end") {
break;
}
guy.add(text);
}
return 0;
}