собери все в один файл #ifndef MATRIXAPPMANAGERH #define MATRIXAPPMANAGERH class…
- User
собери все в один файл
#ifndef MATRIX_APPMANAGER_H #define MATRIX_APPMANAGER_H
class AppManager { public: AppManager(); void start(int argc, char* argv[]);
private: int speed; int length; bool epilepsyMode; bool running; int consoleWidth; int consoleHeight;
void configureSettings(); bool parseCommandLineArgs(char* argv[]); void hideConsoleCursor(); void getConsoleSize();};
#endif //MATRIX_APPMANAGER_H
#include "Line.h" #include #include
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)); //implace_back метод }}
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)]; }
int Line::getRandomColor() { return 1 + rand() % 15; }
void Line::setColor(int color) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color); }
//получение символа по индексу char Line::getCharacter(int index) const { if (index >= 0 && index < symbols.size()) { return symbols[index].getCharacter(); } return ' '; }
- Assistant