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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| #include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include<string.h>
void dessiner_grille()
{
for(int i=0;i<=8;i++)
line(20,20+i*40,340,20+i*40);
for(int i=0;i<=8;i++)
line(20+i*40,20,20+i*40,340);
}
////
void deplacer(int couleur,int *x,int *y)
{
setcolor (0); //la couleur cu contour
if(*x>340) //retour a la ligne
{
*y=*y+40;*x=*x-320; }
if(*y<=350)
{
setfillstyle (SOLID_FILL,couleur);
fillellipse (*x,*y,10,10);
}
else {setcolor(15);
outtextxy(450,300,"vous avez perdu !!");
getch();exit(0);}
}
////
void cacher(int *x,int *y)
{
setfillstyle (SOLID_FILL,0);
fillellipse (*x,*y,15,15);
setcolor(5);
dessiner_grille();
}
/////
void calculer_posi()
{
}
int lancer_des()
{
return 1+rand()%6;
}
///
int main(void)
{
int y=40;
int x=-3;
time_t t;
srand((unsigned) time(&t)); //initialiser le génerateur des nombres aléatoires
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "C:\\BC5\\BGI");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("appuyer sur une touche pour quitter:");
getch();
exit(1);
}
cleardevice();
setcolor(5);
dessiner_grille();
setcolor(2);
setfillstyle (SOLID_FILL,2);
fillellipse (40,40,10,10);
setcolor(15);
outtextxy(450,60,"JEU DE L'OIE:");
outtextxy(400,80,"1-nouvelle partie");
outtextxy(400,90,"2-Regles du jeu");
outtextxy(400,100,"3-Quitter");
outtextxy(277,80,"B");
outtextxy(350,230,"le resultat du lance est: 2");
int k=lancer_des();
while(k<=6) //boucle infinie
{
k=lancer_des();
x=x+k*40;
if(x==277)
{x=197;
y=y+40;
deplacer(RED,&x,&y);
}
deplacer(RED,&x,&y);
getch();
int a=x,b=y;
cacher(&a,&b);
getch();
if(x==470&&y==435)
{ setcolor(13);
outtextxy(450,300,"BRAVO!! vous avez gange ");
getch(); exit(0);
}
}
closegraph();
return 0;
} |
Partager