1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include <stdlib.h>
#include <stdio.h>
/*
*
* A f f i c h e _ P o i n t
*/
static void Affiche_Point ( int x, int y )
{
printf("\033[%d;%dH*",y,x);
fflush(stdout);
}
/*
* D e p l a c e_ P o i n t
*
*/
static void Deplace_Point ( int *x, int *y, int dx, int dy )
{
*x = *x + dx;
*y = *y + dy;
}
/*
*
* A j u s t e _ D e l t a
*
*/
static void Ajuste_Delta ( int x, int y, int *dx, int *dy )
{
if ( (x<1) || (x>100) )
{
*dx = -*dx;
}
if ( (y<1) || (y>30) )
{
*dy=-*dy;
}
}
/*
*
* E x e c u t e _ F o n c t i o n a l i t e
*
*/
static int Execute_Fonctionalite ( void )
{
//déclaration des variables
int x,y ;
int dx,dy ;
// initialisation des variables
x=5;
y=5;
dx=5;
dy=5;
// Affiche le point de départ
Affiche_Point ( x, y );
// Boucle
while(1)
{
Ajuste_Delta ( x, y, &dx, &dy );
Deplace_Point(&x, &y, dx, dy);
Affiche_Point ( x, y );
// Attente et reprise
usleep(50000);
printf("\033[H\033[2J");
}
return 0 ;
}
/*
*
* M a i n
*
*/
int main(void)
{
int statut ;
statut = Execute_Fonctionalite();
return statut ;
} |
Partager