网易c++---------弹跳小球代码---------202

2020-10-03  本文已影响0人  heiqimingren

https://study.163.com/course/courseLearn.htm?courseId=1004489035#/learn/video?lessonId=1049009037&courseId=1004489035


#include<stdio.h>
#include<stdlib.h>    //清屏命令在这里。
#include <windows.h> //延时10毫秒-sleep


int main()
{
    int j, i;
    int x = 0;
    int y = 5;

    int velocity_x = 1;
    int velocity_y = 1;
    int left = 0;   //左边界
    int right = 20;   //右边界
    int top = 0;
    int bottom = 10;

    while (1)
    {
        x = x + velocity_x;
        y = y + velocity_y;
        system("cls");    //清屏函数
        //输出小球前的空行
        for (i = 0; i < x;i++)
        {
            printf("\n");
        }
        for (j = 0; j < y;j++)
        {
            printf(" ");
        }
        printf("o");
        printf("\n");
        Sleep(50); //延时10毫秒
        if ((x==top)||(x==bottom))
        {
            velocity_x = -velocity_x;
        }
        if ((y==left)||(y==right) )
        {
            velocity_y = -velocity_y;
        }
    }
    return 0;


}

上一篇下一篇

猜你喜欢

热点阅读