讨论区 综合讨论区 主题详情
一只杰叔
运行的时候好多这个符号“_”在闪啊

所有回复(1)

你是在说弹跳小球的边框吗?为了不受清屏影响我每个while循环一次就重画一次,这样就会随着小球弹跳边框不停闪烁

你有找到什么好方法吗?

我的代码在下面,大家可以找找办法如何简化?

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <windows.h>

#include <time.h>


void delay(int number_of_seconds)

{

    // Converting time into centi_seconds

    int centi_seconds = 100 * number_of_seconds;


    // Storing start time

    clock_t start_time = clock();


    // looping till required time is not achieved

    while (clock() < start_time + centi_seconds);


}


int main()

{

    int i,j;

    int x = 10;

    int y = 15;

    int velocity_x = 1;

    int velocity_y = 1;

    int left = 1;

    int right = 20;

    int top = 1;

    int bottom = 20;



    while (1)

    {

        x = x + velocity_x;

        y = y + velocity_y;


        system("cls");


        for(int i=0; i<=right; i++)     // print first"---------"

        {

            printf("-");

        }

        printf("\n");


        for (i=1; i<x; i++)     //print"|       |"for lines before the ball

        {

            printf("|");

            for (j=1; j<right+1; j++)

            {

                printf(" ");

            }

            printf("|\n");

        }


        printf("|");        // print"|      o    |"

        for (j=1; j<y; j++)

        {

            printf(" ");

        }

        printf("o");    // print ball at line (y,x)

        delay(1);       // delay for 100 cs after each print of the ball


        for (j=y; j<right; j++)

        {

            printf(" ");

        }

        printf("|\n");


        for (i=x; i<bottom; i++) //print"|       |"for lines after the ball

        {

            printf("|");

            for (j=1; j<right+1; j++)

            {

                printf(" ");

            }

            printf("|\n");

        }


        for(int i=0; i<=right; i++)     // print last"---------"

        {

            printf("-");

        }

        printf("\n");


        if ((x==bottom) || (x==top))

            velocity_x = -velocity_x;

            printf("\a");


        if ((y==right) || (y==left))

            velocity_y = -velocity_y;

            printf("\a");

    }

    return 0;

}


2020-12-27

回复

发布

发表观点要登录哦!

最近活动:2020-12-27
创建时间:2020-12-17
浏览次数:317
关注人数:0

使用协议与隐私政策

感谢您使用网易云课堂!

为了更好地保障您的个人权益,请认真阅读《使用协议》《隐私政策》《服务条款》的全部内容,同意并接受全部条款后开始使用我们的产品和服务。若不同意,将无法使用我们的产品和服务。

同意
手机课堂
下载App
返回顶部