C语言如何实现一个无限循环运动

Python021

C语言如何实现一个无限循环运动,第1张

//用C++写了个效果还算是可以的,你可以改成C试一试

#include <iostream>

//#include <system.h>

using namespace std

void showLine(int n)

{

cout<<n<<": *********"<<endl

}

void showN(int n)

{

cout<<n<<":"<<endl

}

void delay(long n)//延时作用

{

long m,k,j,z

m=k=j=z=n

for(n>0n--)

for(k>0k--)

for(j>0j--)

for(z>0z--)

}

int main()

{

int i=0

while(true)

{

//1

if(i%2!=0)

{

showLine(1)

showN(2)

showLine(3)

showN(4)

showLine(5)

showN(6)

showLine(7)

}

else

{

showN(1)

showLine(2)

showN(3)

showLine(4)

showN(5)

showLine(6)

showN(7)

}

//cin.clear()

system("cls")

delay(5000000)//这个自己写的延时函数实在不怎么样,效果还算可以吧

i++

}

return 0

}

//改了一下,完美解决

#include <iostream>

#include <windows.h>

using namespace std

#define stl 50 //Sleep函数以毫秒为单位,Sleep(500)表示停半秒

void showLine(int n)

{

cout<<n<<": *********"<<endl

}

void showN(int n)

{

cout<<n<<":"<<endl

}

void delay(long n)//延时作用

{

long m,k,j,z

m=k=j=z=n

for(n>0n--)

for(k>0k--)

for(j>0j--)

for(z>0z--)

}

int main()

{

int i=0

while(true)

{

//1

if(i%2!=0)

{

showLine(1)

showN(2)

showLine(3)

showN(4)

showLine(5)

showN(6)

showLine(7)

}

else

{

showN(1)

showLine(2)

showN(3)

showLine(4)

showN(5)

showLine(6)

showN(7)

}

//cin.clear()

system("cls")

//delay(5000000)//这个自己写的延时函数实在不怎么样,效果还算可以吧

Sleep(stl)

i++

}

return 0

}

#include <graphics.h>

#include <bios.h>

#include <malloc.h>

void moveball(int *x,

int *y,

int *dx,

int *dy,

int height,

int width,

void *buff)

{

static int k=1,h=1

if(k==1&&(*dx)>=(*x-width-1))

{ k=0}

else if(k==0&&(*dx)<1)

{ k=1}

else if(h==1&&(*dy)>=(*y-height-1))

{ h=0}

else if(h==0&&(*dy)<1)

{ h=1}

if(k)

{ putimage(*dx+1,*dy,buff,0)

(*dx)++

if(h) { putimage(*dx,*dy+1,buff,0) (*dy)++ }

else { putimage(*dx,*dy-1,buff,0) (*dy)-- } }

else { putimage(*dx-1,*dy,buff,0)