弹跳小球

#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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值