- //fait par m_msabri@caramail.com
-
- #include <graphics.h>
- #include <conio.h>
- #include <iostream.h>
- #include <dos.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- class losange
- {
- int x,y,dx,dy,couleur; //membres priv,s
- public: //membres publics
- losange();
- void deplace(int,int,int);
- void affiche();
- void efface();
- int test();
- };
-
- losange::losange() // constructeur
- {
- x=100;
- y=100;
- dx=80;
- dy=120;
- couleur=BLUE;
- }
-
- void losange::deplace(int depx,int depy,int coul)
- {
- x=x+depx;
- y=y+depy;
- couleur=coul;
- }
-
- void losange::affiche()
- {
- int tab[10];
- tab[0]=x;tab[1]=y; //On initialise le tableau par les coordonn,es du polyg"ne
- tab[2]=x+dx/2;tab[3]=y+dy/2;
- tab[4]=x;tab[5]=y+dy;
- tab[6]=x-dx/2;tab[7]=y+dy/2;
- tab[8]=x;tab[9]=y;
- setfillstyle(SOLID_FILL,couleur);
- fillpoly(5,tab);
- }
-
- void losange::efface()
- {
- int tab[10];
- tab[0]=x;tab[1]=y; //on initialise le tableau par les coordonn,es des points du polyg"ne
- tab[2]=x+dx/2;tab[3]=y+dy/2;
- tab[4]=x;tab[5]=y+dy;
- tab[6]=x-dx/2;tab[7]=y+dy/2;
- tab[8]=x;tab[9]=y;
- setcolor(getbkcolor());
- setfillstyle(SOLID_FILL,getbkcolor());
- fillpoly(5,tab);
- }
-
- int losange::test()
- {
- if (x-dx/2<=0||x+dx/2>=640)
- return 1;
- else if (y+dy>=480||y<=0)
- return 2;
- else
- return 3;
- }
-
- void init_graph()
- {
- int gdriver = DETECT, gmode, errorcode;
- initgraph(&gdriver, &gmode, "");
- errorcode = graphresult();
- if (errorcode != grOk) //il y a une erreur
- {
- printf("Graphics error: %s\n", grapherrormsg(errorcode));
- printf("Press any key to halt:");
- getch();
- exit(1); // retour du code d'erreur
- }
- setbkcolor(3);
- }
-
- void main()
- {
- int a=10,b=10;
- losange l;
- init_graph();
- while(!kbhit())
- {
- l.affiche();
- delay(200);
- l.efface();
- l.deplace(a,b,BLUE);
- if (l.test()==1)
- a=-a;
- else if (l.test()==2)
- b=-b;
- }
- getch();
- closegraph();
- }
//fait par m_msabri@caramail.com
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
class losange
{
int x,y,dx,dy,couleur; //membres priv,s
public: //membres publics
losange();
void deplace(int,int,int);
void affiche();
void efface();
int test();
};
losange::losange() // constructeur
{
x=100;
y=100;
dx=80;
dy=120;
couleur=BLUE;
}
void losange::deplace(int depx,int depy,int coul)
{
x=x+depx;
y=y+depy;
couleur=coul;
}
void losange::affiche()
{
int tab[10];
tab[0]=x;tab[1]=y; //On initialise le tableau par les coordonn,es du polyg"ne
tab[2]=x+dx/2;tab[3]=y+dy/2;
tab[4]=x;tab[5]=y+dy;
tab[6]=x-dx/2;tab[7]=y+dy/2;
tab[8]=x;tab[9]=y;
setfillstyle(SOLID_FILL,couleur);
fillpoly(5,tab);
}
void losange::efface()
{
int tab[10];
tab[0]=x;tab[1]=y; //on initialise le tableau par les coordonn,es des points du polyg"ne
tab[2]=x+dx/2;tab[3]=y+dy/2;
tab[4]=x;tab[5]=y+dy;
tab[6]=x-dx/2;tab[7]=y+dy/2;
tab[8]=x;tab[9]=y;
setcolor(getbkcolor());
setfillstyle(SOLID_FILL,getbkcolor());
fillpoly(5,tab);
}
int losange::test()
{
if (x-dx/2<=0||x+dx/2>=640)
return 1;
else if (y+dy>=480||y<=0)
return 2;
else
return 3;
}
void init_graph()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk) //il y a une erreur
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); // retour du code d'erreur
}
setbkcolor(3);
}
void main()
{
int a=10,b=10;
losange l;
init_graph();
while(!kbhit())
{
l.affiche();
delay(200);
l.efface();
l.deplace(a,b,BLUE);
if (l.test()==1)
a=-a;
else if (l.test()==2)
b=-b;
}
getch();
closegraph();
}