一.弹跳小球源码和知识点

#include <stdio.h>
#include <stdlib.h>
#include <windows.h> 
int main()
{

    int i=0,j=0,x=0,y=5,xx=1,yy=1;
    int a=0,s=10,w=0,d=20;
    while(1)
    {
    	x=x+xx;
    	y=y+yy;
    	system("cls");
        for(i=0;i<x;i++)
        {
         	printf("\n");
	    }
		for(j=0;j<y;j++)
		{
		 	printf(" ");
		}
		printf("O\n"); 
		Sleep(50);
		
		if(x==w||x==s)
		{
			printf("\a");
			xx=-xx;
		}
		if(y==a||y==d)
		{
			printf("\a");
			yy=-yy;
		}
	}
	return 0;
	 
}


1.清屏

#include <stdlib.h>     system("cls");

2.让小球运动缓慢

#include <windows.h>    Sleep(50);

3.碰到边框有响铃

printf("\a");

4.通过用for循环每行每列增或减一个单位,让小球移动。


学习网址:http://study.163.com/course/courseMain.htm?courseId=1004489035




猜你喜欢

转载自blog.csdn.net/qq_41160739/article/details/80323727