#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include "windows.h"
void gotoxy(int x,int y) /*定義gotoxy函式*/
{
COORD c;
c.X=x-1;
c.Y=y-1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}
int main()
struct point
int x, y;/*該點的位置,包括x座標和y座標*/
int xv, yv;/*該點在x軸,y軸的速度*/
}man;
long p;
man.x=man.y=20;
man.xv=man.yv=1;
system("cls");
p=1000000000000000;
while(p--)
if(p%50000)
continue;
gotoxy(man.x, man.y);/*把游標移到指定的座標*/
printf(" ");/*輸出一個空格,把先前的字元擦去*/
man.x += man.xv;/*水平方向按x軸的速度運動*/
man.y += man.yv;/*垂直方向按y軸的速度運動*/
if(man.x==0||man.x==80)
man.xv*=-1;
if(man.y==0||man.y==80)
man.yv*=-1;
gotoxy(man.x, man.y);
printf("%c\b", 2); /*輸出ASCII碼值為2的"笑臉"字元*/
getchar ();
return 0;
這個是一個會動的笑臉,你可以從最簡單開始
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include "windows.h"
void gotoxy(int x,int y) /*定義gotoxy函式*/
{
COORD c;
c.X=x-1;
c.Y=y-1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}
int main()
{
struct point
{
int x, y;/*該點的位置,包括x座標和y座標*/
int xv, yv;/*該點在x軸,y軸的速度*/
}man;
long p;
man.x=man.y=20;
man.xv=man.yv=1;
system("cls");
p=1000000000000000;
while(p--)
{
if(p%50000)
continue;
gotoxy(man.x, man.y);/*把游標移到指定的座標*/
printf(" ");/*輸出一個空格,把先前的字元擦去*/
man.x += man.xv;/*水平方向按x軸的速度運動*/
man.y += man.yv;/*垂直方向按y軸的速度運動*/
if(man.x==0||man.x==80)
man.xv*=-1;
if(man.y==0||man.y==80)
man.yv*=-1;
gotoxy(man.x, man.y);
printf("%c\b", 2); /*輸出ASCII碼值為2的"笑臉"字元*/
}
getchar ();
return 0;
}
這個是一個會動的笑臉,你可以從最簡單開始