#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void gotoxy(int x, int y){
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle, pos);
}
int main()
{
HideCursor();
int x, y;
int top = 0;
int bottom = 20;
int left =0;
int right = 20;
x = 8;
y = 2;
int v_x = 1;
int v_y = 1;
while(1)
{
gotoxy(0, 0);
x = x + v_x;
y = y + v_y;
int i, j;
for(i = 0; i < right + 2; i++)printf("#");
printf("\n");
for(i = 0; i < x; i++)
{
printf("#");
for(j = 0; j < right; j++)printf(" ");
printf("#\n");
}
printf("#");
for(j = 0; j < y; j++)printf(" ");
printf("O");
for(j = y + 1; j < 20; j++)
{
printf(" ");
}
printf("#\n");
for(i = x + 1; i < bottom; i++)
{
printf("#");
for(j = 0; j < right; j++)printf(" ");
printf("#\n");
}
for(i = 0; i < right + 2; i++)printf("#");
Sleep(100);
if(x == top|| x == bottom - 1)
{
v_x = -v_x;
//printf("\a");
}
if(y == left || y == right - 1)
{
v_y = -v_y;
//printf("\a");
}
}
return 0;
}