begin process at 2010 02 10 14:02:50
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

.Net

 > LOSANGE SE DÉPLAÇANT SUR L'ÉCRAN

LOSANGE SE DÉPLAÇANT SUR L'ÉCRAN


 Information sur la source

Note :
Aucune note
Catégorie :.Net Niveau :Débutant Date de création :18/08/2003 Date de mise à jour :18/08/2003 20:24:47 Vu :2 980

Auteur : sabrimed81

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

utilisation de la bibliotheque graphic.h

Source

  • //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();
	}



 Sources de la même categorie

Source avec Zip Source avec une capture MAP_MAKER_JEU par seekplus
Source avec Zip Source avec une capture Source .NET (Dotnet) EMISSION D'UN OCTET SUR LE PORT SÉRIE - CLASSE SERIALPORT par jmchatelet01
Source avec Zip Source .NET (Dotnet) RESOLV EQU DE DEGRES N par darckangel731
Source avec Zip Source avec une capture Source .NET (Dotnet) INTEROP XCHAT / .NET : CHARGEUR DE PLUGINS MANAGÉS par TeBeCo
Source avec Zip Source avec une capture Source .NET (Dotnet) SCANNER D'ADRESSES MAILS PRÉSENTENT SUR GOOGLE par Zaltez

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,702 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales