#include <iostream> #include <cstdlib> #include <conio.h> #include <thread> #include…
- User
#include #include #include <conio.h> #include #include #include <windows.h> #include #include #include
class Symbol { public: Symbol(char character = ' ', int color = 10);
char getCharacter() const; void setCharacter(char character); int getColor() const; void setColor(int color);private: char character; int color; };
Symbol::Symbol(char character, int color) : character(character), color(color) {}
char Symbol::getCharacter() const { return character; }
void Symbol::setCharacter(char character) { this->character = character; }
int Symbol::getColor() const { return color; }
void Symbol::setColor(int color) { this->color = color; }
class Line { public: Line(int length, bool epilepsyMode);
void move(); void draw(HANDLE hConsole, int position, int consoleWidth, int startPosition) const;private: int length; std::vector symbols; bool epilepsyMode; int lineColor;
void generateNewSymbol(int index); static char getRandomCharacter(); static int getRandomColor(); static void setColor(int color); char getCharacter(int index) const; int getColor(int index) const;};
Line::Line(int length, bool epilepsyMode) : length(length), epilepsyMode(epilepsyMode) { if (epilepsyMode) { lineColor = getRandomColor(); } else { lineColor = 10; // Зеленый по умолчанию }
for (int i = 0; i < length; ++i) { char randomChar = getRandomCharacter(); int color = epilepsyMode ? lineColor : 10; symbols.push_back(Symbol(randomChar, color)); }}
void Line::move() { symbols[0] = Symbol(' ', 7); // Удаление первого символа for (int i = 1; i < length - 1; ++i) { symbols[i] = symbols[i + 1]; } generateNewSymbol(length - 1); }
void Line::draw(HANDLE hConsole, int position, int consoleWidth, int startPosition) const { COORD cursorPos;
if (position - 1 >= 0 && position - 1 < consoleWidth) { cursorPos.X = static_cast<SHORT>(position - 1); cursorPos.Y = startPosition; SetConsoleCursorPosition(hConsole, cursorPos); std::cout << " "; } int startIndex = std::max(0, -position); int visibleLength = std::min(length - startIndex, consoleWidth - position); for (int i = startIndex; i < startIndex + visibleLength; ++i) { setColor(getColor(i)); cursorPos.X = static_cast<SHORT>(position + i); cursorPos.Y = startPosition; SetConsoleCursorPosition(hConsole, cursorPos); std::cout << getCharacter(i); }}
void Line::generateNewSymbol(int index) { char newChar = getRandomCharacter(); int color = epilepsyMode ? lineColor : 10; symbols[index] = Symbol(newChar, color); }
char Line::getRandomCharacter() { const char characters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;':",.<>?~"; return characters[rand() % (sizeof(characters) - 1)]; }
- Assistant