#include <stdio.h>
#include <windows.h>
#include <conio.h>

// 自动清屏 + 填充空格(覆盖上一帧,不闪烁)
void clearScreen() {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coord = {0, 0};
    DWORD count;
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    GetConsoleScreenBufferInfo(hConsole, &csbi);
    FillConsoleOutputCharacter(hConsole, ' ', csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
    SetConsoleCursorPosition(hConsole, coord);
}

// 移动光标到 (x,y)
void setPos(int x, int y) {
    COORD pos = {x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

// 绘制一个小飞机(你可以换成爱心、方块、笑脸)
void drawPattern(int x, int y) {
    setPos(x, y);     printf("  ▲  ");
    setPos(x, y+1);   printf(" ■■■ ");
    setPos(x, y+2);   printf("■■■■■");
}

int main() {
    system("mode con cols=60 lines=20");
    SetConsoleTitle("自动移动图案 + 自动清屏");

    // 初始位置
    int x = 5;
    int y = 5;

    // 移动方向
    int dx = 1;
    int dy = 1;

    while (1) {
        // ======================
        // 核心:自动清屏 + 覆盖空格
        // ======================
        clearScreen();

        // 绘制图案
        drawPattern(x, y);

        // 自动移动
        x += dx;
        y += dy;

        // 碰到边界反弹
        if (x <= 0 || x >= 50) dx = -dx;
        if (y <= 0 || y >= 15) dy = -dy;

        // 控制速度
        Sleep(50);
    }

    return 0;
}