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
| #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*55,500,20+i*55);
for(int i=0;i<=8;i++)
line(20+i*60,20,20+i*60,460);
}
////
void deplacer(int couleur,int *x,int *y)
{
setcolor (0); //la couleur cu contour
if(*x>470)
{
*y=*y+55;*x=*x-420; }
if(*y<=435)
{
setfillstyle (SOLID_FILL,couleur);
fillellipse (*x,*y,15,15);
}
else {setcolor(15);
outtextxy(500,60,"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=50;
int x=-10;
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 (50,50,15,15);
int k=lancer_des();
while(k<=6) //boucle infinie
{
k=lancer_des();
x=x+k*60;
deplacer(RED,&x,&y);
getch();
int a=x,b=y;
cacher(&a,&b);
getch();
if(x==470&&y==435)
{ setcolor(13);
outtextxy(500,60,"gagné !!");
getch(); exit(0);
}
}
closegraph();
return 0;
} |
Partager