исправь код, чтобы выполнялись условия • Общее количество появившихся в секунду линий…
- User
исправь код, чтобы выполнялись условия • Общее количество появившихся в секунду линий должно соответствовать заданной частоте появления. • Если частота n линий в секунду, то генерируется n случайных временных промежутков в диапазоне от 0 до 1000 миллисекунд (одна секунда). Это определяет, в какой момент времени каждая линия начнёт своё движение. • Например, если сгенерированы промежутки 200 мс, 700 мс и 400 мс, линии начнут двигаться в следующем порядке: первая линия через 200 мс от начала итерации, вторая через 400 мс от начала и третья - через 700 мс.
#include #include #include #include <conio.h> #include #include #include <windows.h> #include #include
class Random { public: static char getRandomCharacter() { const char characters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;':",.<>?~"; return characters[rand() % (sizeof(characters) - 1)]; }
static int getRandomColor() { return 1 + rand() % 15; } static int getRandomPosition(int limit) { return rand() % limit; } static int getRandomDelay() { return rand() % 1000; // Random delay in milliseconds (0-1000) }};
class ConsoleUtils { public: static void getConsoleSize(int& width, int& height) { CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); width = csbi.srWindow.Right - csbi.srWindow.Left + 1; height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; }
static void hideCursor() { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cursorInfo; GetConsoleCursorInfo(hConsole, &cursorInfo); cursorInfo.bVisible = FALSE; SetConsoleCursorInfo(hConsole, &cursorInfo); } static void clearScreen() { system("cls"); }};
class Symbol { public: Symbol(char character = ' ', int color = 10) : character(character), color(color) {}
char getCharacter() const { return character; } void setCharacter(char character) { this->character = character; } int getColor() const { return color; } void setColor(int color) { this->color = color; }private: char character; int color; };
class Line { public: Line(int length, bool epilepsyMode) : length(length), epilepsyMode(epilepsyMode) { lineColor = epilepsyMode ? Random::getRandomColor() : 10; for (int i = 0; i < length; ++i) { char randomChar = Random::getRandomCharacter(); int color = epilepsyMode ? lineColor : 10; symbols.push_back(Symbol(randomChar, color)); } }
void move() { symbols[0] = Symbol(' ', 7); // Replacing the first symbol with a space for (int i = 1; i < length - 1; ++i) { symbols[i] = symbols[i + 1]; // Shifting symbols to the right } generateNewSymbol(length - 1); // Generating a new random symbol on the right } void draw(HANDLE hConsole, int position, int consoleWidth, int startPosition) const { COORD cursorPos; 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); } } - Assistant
- User
линия все равно поялвяется одна исправь это может надо классы изменить
- Assistant