#include #include #include using namespace std; // 绘制正方形 // 参数:边框颜色、填充颜色、左上角x、左上角y、边长 void drawSquare(color_t borderColor, color_t fillColor, int x, int y, int size) { int pts[8] = { x, y, x + size, y, x + size, y + size, x, y + size }; setcolor(borderColor); setfillcolor(fillColor); fillpoly(4, pts); } // 绘制圆形 // 参数:边框颜色、填充颜色、外框左上角x、外框左上角y、直径 void drawCircle(color_t borderColor, color_t fillColor, int x, int y, int size) { // 圆心 = 左上角 + 半径 int cx = x + size / 2; int cy = y + size / 2; int r = size / 2; setcolor(borderColor); setfillcolor(fillColor); fillcircle(cx, cy, r); } // 自定义非阻塞按键(改名:my_getkey 避免系统冲突) //返回值 例如 key_enter int my_getkey() { if (kbhit()) { return getch(); } return 0; } int G_x = 0; int G_y = 0; int G_f = 4; // 1 2 3 4 分别对应上下左右 int G_P = 0; //当前蛇头位置 struct _AA_ { int x; int y; }; _AA_ G_AA[10000] = {0}; int main() { initgraph(640, 480, INIT_RENDERMANUAL); setbkcolor(RGB(150, 200, 255)); while(is_run()) { // 背景色必须在 cleardevice() 之前设置才生效 cleardevice(); // 清空画布、刷新背景色 drawSquare(RED,WHITE,0,0,100); drawCircle(BLUE,PINK,0,0,100); int ret = my_getkey(); if(ret > 0) { cout<