#include "c_Console.h" #include #include int main() { c_Console_Init(); CONSOLE_CLEAR(); CONSOLE_HIDE_CURSOR(); int x = 10, y = 5; int running = 1; CONSOLE_GOTOXY(1, 1); CONSOLE_COLOR_GREEN(); printf("=== 跨平台控制台框架示例 ==="); CONSOLE_GOTOXY(1, 2); CONSOLE_COLOR_RESET(); printf("控制键: W/A/S/D 移动,Q 退出\n"); while (running) { // 1. 处理输入 if (c_Console_kbhit()) { int key = c_Console_getch(); // 擦除旧位置 CONSOLE_GOTOXY(x, y); printf(" "); switch (key) { case 'w': case 'W': y--; break; case 's': case 'S': y++; break; case 'a': case 'A': x--; break; case 'd': case 'D': x++; break; case 'q': case 'Q': running = 0; break; default: break; } // 边界约束 if (x < 1) x = 1; if (y < 3) y = 3; } // 2. 渲染画面 CONSOLE_GOTOXY(x, y); CONSOLE_COLOR_RED(); printf("@"); // 绘制玩家 fflush(stdout); // 刷新标准输出缓冲区(防止字符滞留) // 3. 控制帧率 (约 30 FPS) c_Console_Sleep(33); } // 退出处理 CONSOLE_CLEAR(); CONSOLE_SHOW_CURSOR(); CONSOLE_COLOR_RESET(); printf("程序已安全退出。\n"); return 0; }