正文
增加 29 行删除 24 行
10 行未改动1112131415161718192021222316 行未改动4041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909139 行未改动10 行未改动#include <stdlib.h>#include <windows.h>#include <conio.h>const WORD default_color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;const WORD red = FOREGROUND_RED | FOREGROUND_INTENSITY;const WORD green = FOREGROUND_GREEN | FOREGROUND_INTENSITY;const WORD blue = FOREGROUND_BLUE | FOREGROUND_INTENSITY;const WORD yellow = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;const WORD gray = FOREGROUND_INTENSITY;inline void set_cursor_visible(bool visible) {CONSOLE_CURSOR_INFO cursorInfo;16 行未改动if (_kbhit()) return _getch();return 0;}class screen {private:CHAR_INFO* buffer;int width;int height;void draw(int x, int y, char ch, WORD color) {if (x >= 0 && x < width && y >= 0 && y < height) {int index = y * width + x;buffer[index].Char.AsciiChar = ch;buffer[index].Attributes = color;}}public:screen(int w, int h) : width(w), height(h) {buffer = new CHAR_INFO[width * height];}~screen() {delete[] buffer;}void clear() {for (int i = 0; i < width * height; i++) {buffer[i].Char.AsciiChar = ' ';buffer[i].Attributes = default_color;}}void text(int x, int y, const char* str, WORD color = default_color) {int cur_x = x;while (*str) {draw(cur_x++, y, *str, color);str++;}}void render() {HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);COORD size = { (SHORT)width, (SHORT)height };COORD pos = { 0, 0 };SMALL_RECT rect = { 0, 0, (SHORT)(width - 1), (SHORT)(height - 1) };WriteConsoleOutput(h, buffer, size, pos, &rect);}};#endif39 行未改动10 行未改动11121314151617181920212223242516 行未改动4243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959639 行未改动10 行未改动#include <stdlib.h>#include <windows.h>#include <conio.h>const WORD default_color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;const WORD red = FOREGROUND_RED | FOREGROUND_INTENSITY;const WORD green = FOREGROUND_GREEN | FOREGROUND_INTENSITY;const WORD blue = FOREGROUND_BLUE | FOREGROUND_INTENSITY;const WORD yellow = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;const WORD cyan = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;const WORD gray = FOREGROUND_INTENSITY;inline void set_cursor_visible(bool visible) {CONSOLE_CURSOR_INFO cursorInfo;16 行未改动if (_kbhit()) return _getch();return 0;}#define MAX_BUF 4000class screen {private:int width;int height;char text_buf[MAX_BUF];WORD color_buf[MAX_BUF];public:screen(int w, int h) : width(w), height(h) {}void clear() {int total = width * height;for (int i = 0; i < total; i++) {text_buf[i] = ' ';color_buf[i] = default_color;}}void text(int x, int y, const char* str, WORD color = default_color) {int cur_x = x;while (*str) {if (cur_x >= 0 && cur_x < width && y >= 0 && y < height) {int index = y * width + cur_x;text_buf[index] = *str;color_buf[index] = color;}cur_x++;str++;}}void render() {HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);COORD pos = {0, 0};SetConsoleCursorPosition(h, pos);for (int y = 0; y < height; y++) {for (int x = 0; x < width; x++) {int index = y * width + x;SetConsoleTextAttribute(h, color_buf[index]);putchar(text_buf[index]);}if (y < height - 1) {putchar('\n');}}}};#endif39 行未改动