program allo;
uses crt,graph;
var Pilote,mode,x,y,z,a,b,c,u,i,s,k,l,g,score,speed,finalscore,finito:integer;
var nom,movie,q1,q2,q3,q4,q5:string;
reponse1,reponse2:string[1];
var mvt:char;

(*procedures permettant que lorsque la balle touche un mur, elle rebondisse dans la bonne direction*)
procedure a1b2; begin a:=1; b:=2; sound(220); delay(1); nosound;end;
procedure a1b1; begin a:=1; b:=1; sound(220); delay(1); nosound;end;
procedure a2b1; begin a:=2; b:=1; sound(220); delay(1); nosound;end;
procedure a2b2; begin a:=2; b:=2; sound(220); delay(1); nosound;end;
procedure a3b1; begin a:=3; b:=1; sound(220); delay(1); nosound;end;
procedure a3b2; begin a:=3; b:=2; sound(220); delay(1); nosound;end;
procedure a4b1; begin a:=4; b:=1; sound(220); delay(1); nosound;end;
procedure a4b2; begin a:=4; b:=2; sound(220); delay(1); nosound;end;

procedure question1;                    (*question numero 1*)
begin closegraph; clrscr;
textcolor(green+blink);
gotoXY(15,2);  write('Question 1');
textcolor(green);
gotoXY(20,5); writeln('*Le cheval ne se couche jamais,sauf quand il est malade*');
gotoXY(25,7); writeln('a - VRAI');
gotoXY(25,9); writeln('b - FAUX');
gotoXY(10,15);
textcolor(red);
q1:=readkey;
if q1='a' then
 writeln('Ce n''est pas la bonne reponse vous n''aurez pas les points bonus')
else if q1='b' then
     writeln(' Vous avez raison ! on vous accorde des points bonis');
      delay(5000);
     finalscore:=finalscore+250;
      end;

procedure question2;                 (*question numero 2*)
begin closegraph; clrscr;
textcolor(magenta+blink);
gotoXY(15,2);  write('Question 2');
textcolor(magenta);
gotoXY(20,5); writeln('*Quelle est la ville la plus peuplee au monde?*');
gotoXY(25,7); writeln('a - Tokyo');
gotoXY(25,9); writeln('b - Montreal');
gotoXY(25,11); writeln('c - New York');
gotoXY(25,13); writeln('d - Beijing');
gotoXY(10,20);
textcolor(red);
q2:=readkey;
if (q2='b') or (q2='c') or (q2='d') then
 writeln('Ce n''est pas la bonne reponse vous n''aurez pas les points bonus')
else if (q2='a') then
     writeln(' Vous avez raison ! on vous accorde des points bonis');
     delay(5000);
 finalscore:=finalscore+250; end;


procedure question3;                   (*question numero 3*)
begin closegraph; clrscr;
textcolor(lightred+blink);
gotoXY(15,2);  write('Question 3');
textcolor(lightred);
gotoXY(10,5); writeln('*Le volcan qui contribua a declencher la revolution francaise?*');
gotoXY(25,7); writeln('a - Montroyal');
gotoXY(25,9); writeln('b - Gomera');
gotoXY(25,11); writeln('c - Laki');
gotoXY(25,13); writeln('d - Vesuve');
gotoXY(10,20);
textcolor(red);
q3:=readkey;
if (q3='b') or (q2='a') or (q2='d') then
 writeln('Ce n''est pas la bonne reponse vous n''aurez pas les points bonus')
else if (q3='c') then
     writeln(' Vous avez raison ! on vous accorde des points bonis');
     delay(5000);

finalscore:=finalscore+250; end;

procedure question4;                  (*question numero 4*)
begin closegraph; clrscr;
textcolor(yellow+blink);
gotoXY(15,2);  write('Question 4');
textcolor(yellow);
gotoXY(20,5); writeln('*Quelle est la capitale du Liechtenstein?*');
gotoXY(25,7); writeln('a - Lisbonne');
gotoXY(25,9); writeln('b - Vaduz');
gotoXY(25,11); writeln('c - Liechtenstein');
gotoXY(25,13); writeln('d - Vitters');
gotoXY(10,20);
textcolor(red);
q4:=readkey;
if (q4='a') or (q2='c') or (q2='d') then
 writeln('Ce n''est pas la bonne reponse vous n''aurez pas les points bonus')
else if (q4='b') then
     writeln(' Vous avez raison ! on vous accorde des points bonis');
     delay(5000);

 finalscore:=finalscore+250; end;

procedure question5;               (*question numero 5*)
begin closegraph; clrscr;
textcolor(lightblue+blink);
gotoXY(15,2);  write('Question 5');
textcolor(lightblue);
gotoXY(20,5); writeln('*Comment dit-on ''Merci'' en mandarin ?*');
gotoXY(25,7); writeln('a - Arigato');
gotoXY(25,9); writeln('b - Camon');
gotoXY(25,11); writeln('c - Chokran');
gotoXY(25,13); writeln('d - Kansa Mida');
gotoXY(25,15); writeln('e - Xie xie');
gotoXY(10,20);
textcolor(red);
q5:=readkey;
if (q5='b') or (q5='c') or (q5='d') or (q5='a') then
 writeln('Ce n''est pas la bonne reponse vous n''aurez pas les points bonus')
else if (q5='e') then
     writeln(' Vous avez raison ! on vous accorde des points bonis');
     delay(5000);
finalscore:=finalscore+250; end;

procedure gagneunegame;
begin
g:=g+1; finalscore:=finalscore+score; speed:=speed-1;
end;

procedure bye;
begin;               (*procedure d'au-revoir du programme*)
clrscr;
textcolor(cyan);
 gotoXY(23,7);    write('Merci');           delay(1000);
 gotoXY(28,8);    write('pour');            delay(1000);
 gotoXY(32,9);    write('votre');           delay(1000);
 gotoXY(37,10);    write('participation');  delay(1000);
 gotoXY(50,11);    write(nom);              delay(1000);
 gotoXY(55,12);    write('ADIEU');          delay(1000);
 gotoXY(60,13);    write(':)');             delay(1000);
delay(2000);
end;

procedure premiere;         (*demande a l'usager si il veut jouer*)
begin
repeat
clrscr;
textcolor(yellow); delay(1000);
 gotoXY(18,7);    write('Voulez');    delay(1000);
 gotoXY(24,8);    write('-');         delay(1000);
 gotoXY(25,9);    write('vous');      delay(1000);
 gotoXY(29,10);    write('jouer');        delay(1000);
 gotoXY(34,11);    write(' a');    delay(1000);
 gotoXY(35,12);    write('  un');      delay(1000);
 gotoXY(37,13);    write('    jeu');       delay(1000);
 gotoXY(40,14);    write('      de');       delay(1000);
 gotoXY(42,15);    write('         BALL BOUNCE?');   delay(1000);
 gotoXY(55,17);    write('O/N');
  (*jusqua ce que la personne pesse sur o la procedure va rejouer*)
   reponse1:=UPCASE(READKEY);
 until reponse1 = 'O';
End;

procedure deuxieme;
Begin
clrscr;
 pilote:=detect;
initgraph(pilote,mode,'m:/bgi');
setfillstyle(1,red);                      (*c'est ici que l'intro commence*)
bar(1,1,1000,1000);
setcolor(green);
settextstyle(1,0,5);
outtextXY(225,25,'BONJOUR!');
outtextXY(40,100,'Bienvenue au jeu ');
setcolor(lightgreen);
settextstyle(4,0,8);
outtextXY(20,190,'BALL BOUNCE');
settextstyle(1,0,1);
setcolor(green);
outtextXY(350,340,'Les createurs du jeu sont:');
outtextXY(400,370,'Jean Pierre Delorme');
outtextXY(475,390,'et');
outtextXY(400,410,'Romy Abou-Jaoude');
sound(262); delay(400); nosound; delay(50);    (*petite musique de noel*)
sound(349); delay(400); nosound; delay(50);
sound(349); delay(200); nosound; delay(25);
sound(392); delay(200); nosound; delay(25);
sound(349); delay(200); nosound; delay(25);
sound(330); delay(200); nosound; delay(25);
sound(294); delay(400); nosound; delay(50);
sound(294); delay(400); nosound; delay(50);
sound(294); delay(400); nosound; delay(50);
sound(392); delay(400); nosound; delay(50);
sound(392); delay(200); nosound; delay(25);
sound(440); delay(200); nosound; delay(25);
sound(392); delay(200); nosound; delay(25);
sound(349); delay(200); nosound; delay(25);
sound(330); delay(400); nosound; delay(50);
sound(262); delay(400); nosound; delay(50);
sound(262); delay(400); nosound; delay(50);
sound(440); delay(400); nosound; delay(50);
sound(440); delay(200); nosound; delay(25);
sound(467); delay(200); nosound; delay(25);
sound(440); delay(200); nosound; delay(25);
sound(392); delay(200); nosound; delay(25);
sound(349); delay(400); nosound; delay(50);
sound(294); delay(400); nosound; delay(50);
sound(262); delay(200); nosound; delay(25);
sound(262); delay(200); nosound; delay(25);
sound(294); delay(400); nosound; delay(50);
sound(392); delay(400); nosound; delay(50);
sound(330); delay(400); nosound; delay(50);
sound(349); delay(800); nosound;
cleardevice;
closegraph;

end;

Procedure pointage;
begin
cleardevice;
closegraph;                      (*affiche les points obtenus au total*)
clrscr;

 textcolor(blue);    gotoXY(25,9);  writeln('****************************');
GotoXY(25,10);        write('*');
 Textcolor(Magenta); gotoXY(27,10);  write(nom,' votre Pointage est:');
 Textcolor(blue);    gotoXY(52,10);  writeln('*');
GotoXY(25,11);        write('*');
 Textcolor(green);   gotoXY(37,11);  write(finalscore);
 textcolor(blue);    gotoXY(52,11);  writeln('*');
GotoXY(25,12);         writeln('****************************');
delay(10000);
   end;

procedure fail;
begin
cleardevice;
closegraph;
clrscr;                              (*procedure permettant d'indiquer a quelqu'un
                                     qu'il a perdu*)
 pilote:=detect;
initgraph(pilote,mode,'m:/bgi');
setbkcolor(white);
setcolor(red);
settextstyle(3,0,30);
OuttextXY(50,100,'YOU FAIL');
settextstyle(3,0,3);
outtextxy(50,280,'PS : vous devez maintenant recommencer');
outtextxy(55,300,' des le premier niveau et vous perdez');
outtextxy(55,320,' tous vos points');
sound(220); delay(200); nosound; delay(25);
sound(220); delay(200); nosound; delay(25);
sound(220); delay(200); nosound; delay(25);
sound(176); delay(500); nosound; delay(200);
sound(196); delay(200); nosound; delay(25);
sound(196); delay(200); nosound; delay(25);
sound(196); delay(200); nosound; delay(25);
sound(165); delay(500); nosound; delay(200);
delay(3000);
finalscore:=finalscore+score;
g:=6;
c:=26;
end;

procedure aparaitgauche;
begin
k:=120;                            (*barre qui change de cote quand on touche a droite*)
setfillstyle(1,magenta);
bar((k-25),365,(k+25),370);
end;

procedure aparaitdroite;
begin                              (*barre qui change de cote quand on touche a gauche*)
k:=530;
setfillstyle(1,magenta);
bar((k-25),365,(k+25),370);
end;

procedure aparait;
begin
setfillstyle(1,magenta);          (*barre qui apparait un peu plus loin a droite ou a gauche de sa position initiale*)
bar((k-25),365,(k+25),370);
end;



procedure a3b1score; begin score:=score+10; a:=3; b:=1; sound(330); delay(1); nosound;end;
procedure a2b1score; begin score:=score+10; a:=2; b:=1; sound(330); delay(1); nosound;end;
(*procedures qui augmentent le score quand la balle touche la barre et la fait rebondir*)

procedure basdroite;
begin                   (*mouvement vers le bas et vers la droite de la balle*)
repeat setfillstyle(1,4);fillellipse(x,y,5,5); delay(speed); setfillstyle(1,black);
fillellipse(x,y,5,5);
inc(x); inc(y);
until (x=545) or (y=390) or keypressed or (k-26<x) and (x<k+26) and (y=360);

if (x=545) and (y=390) then fail
else if (k-26<x) and (x<k+26) and (y=360) then a3b1score else
if x=545 then a1b2 else
if y=390 then fail else
if keypressed then mvt:=readkey;
setfillstyle(1,0);
bar((k-35),365,(k+35),370);
case mvt of
'3':k:=k+10;
'1':k:=k-10;
end;
if k=540 then aparaitgauche else
if k=110 then aparaitdroite else
if (k<540) and (k>110) then aparait;
end; (*140 500*)

procedure hautdroite;
begin                     (*mouvement vers le haut et vers la droite de la balle*)
repeat setfillstyle(1,4);fillellipse(x,y,5,5); delay(speed); setfillstyle(1,black);
 fillellipse(x,y,5,5);
inc(x); dec(y);
until (x=545) or (y=75) or keypressed;

if (x=545) and (y=75) then a1b2 else
if x=545 then a2b1 else
if y=75 then a2b2 else
if keypressed then mvt:=readkey;
setfillstyle(1,0);
bar((k-35),365,(k+35),370);
case mvt of
'3':k:=k+10;
'1':k:=k-10;
end;
if k=540 then aparaitgauche else
if k=110 then aparaitdroite else
if (k<540) and (k>110) then aparait;
end; (*140 500*)


procedure hautgauche;
begin                 (*mouvement vers le haut et vers la gauche de la balle*)
repeat setfillstyle(1,4);fillellipse(x,y,5,5); delay(speed); setfillstyle(1,black);
 fillellipse(x,y,5,5);
dec(x); dec(y);
until (x=105) or (y=75) or keypressed;

if (x=105) and (y=75) then a2b2 else
if x=105 then a3b1 else
if y=75 then a3b2 else
if keypressed then mvt:=readkey;
setfillstyle(1,0);
bar((k-35),365,(k+35),370);
case mvt of
'3':k:=k+10;
'1':k:=k-10;
end;
if k=540 then aparaitgauche else
if k=110 then aparaitdroite else
if (k<540) and (k>110) then aparait;
end; (*140 500*)

procedure basgauche;
begin               (*mouvement vers le bas et vers la gauche de la balle*)
repeat setfillstyle(1,4);fillellipse(x,y,5,5); delay(speed); setfillstyle(1,black);
 fillellipse(x,y,5,5);
dec(x); inc(y);
until (x=105) or (y=390) or keypressed or (k-26<x) and (x<k+26) and (y=360);

if (x=105) and (y=390) then fail else
if (k-26<x) and (x<k+26) and (y=360) then a2b1score else
if x=105 then a4b1 else
if y=390 then fail else
if keypressed then mvt:=readkey;
setfillstyle(1,0);
bar((k-35),365,(k+35),370);
case mvt of
'3':k:=k+10;
'1':k:=k-10;
end;
if k=540 then aparaitgauche else
if k=110 then aparaitdroite else
if (k<540) and (k>110) then aparait;
end; (*140 500*)

procedure tableau;
                              (*le jeu en tant que tel incluant les murs, la barre et la balle*)
begin
clrscr;
 pilote:=detect;
initgraph(pilote,mode,'m:/bgi');
cleardevice;
x:=120;
y:=200;
u:=200;
i:=350;
setcolor(black);
hautdroite;
setcolor(blue);
setfillstyle(solidfill,blue);
fillellipse(110,400,20,10); fillellipse(137,400,20,10); fillellipse(164,400,20,10);
fillellipse(191,400,20,10); fillellipse(218,400,20,10); fillellipse(245,400,20,10);
fillellipse(272,400,20,10); fillellipse(299,400,20,10); fillellipse(326,400,20,10);
fillellipse(353,400,20,10); fillellipse(380,400,20,10); fillellipse(407,400,20,10);
fillellipse(434,400,20,10); fillellipse(461,400,20,10); fillellipse(488,400,20,10);
fillellipse(515,400,20,10); fillellipse(542,400,20,10); fillellipse(569,400,20,10);
setcolor(black);
setfillstyle(solidfill,black);
bar(75,420,105,560);
bar(560,380,600,480);
bar(75,420,560,420);
setcolor(red);
OuttextXY(90,65, '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **');
OuttextXY(90,410,'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **');
OuttextXY(90,75,'*');  OuttextXY(560,75,'*');
OuttextXY(90,87,'*');  OuttextXY(560,87,'*');
OuttextXY(90,104,'*'); OuttextXY(560,104,'*');
OuttextXY(90,121,'*'); OuttextXY(560,121,'*');
OuttextXY(90,138,'*'); OuttextXY(560,138,'*');
OuttextXY(90,155,'*'); OuttextXY(560,155,'*');
OuttextXY(90,172,'*'); OuttextXY(560,172,'*');
OuttextXY(90,189,'*'); OuttextXY(560,189,'*');
OuttextXY(90,206,'*'); OuttextXY(560,206,'*');
OuttextXY(90,223,'*'); OuttextXY(560,223,'*');
OuttextXY(90,240,'*'); OuttextXY(560,240,'*');
OuttextXY(90,257,'*'); OuttextXY(560,257,'*');
OuttextXY(90,274,'*'); OuttextXY(560,274,'*');
OuttextXY(90,291,'*'); OuttextXY(560,291,'*');
OuttextXY(90,308,'*'); OuttextXY(560,308,'*');
OuttextXY(90,325,'*'); OuttextXY(560,325,'*');
OuttextXY(90,342,'*'); OuttextXY(560,342,'*');
OuttextXY(90,359,'*'); OuttextXY(560,359,'*');
OuttextXY(90,376,'*'); OuttextXY(560,376,'*');
OuttextXY(90,390,'*'); OuttextXY(560,390,'*');
OuttextXY(90,400,'*'); OuttextXY(560,400,'*');
k:=510;
score:=0;
c:=0;
setfillstyle(1,magenta);
bar((k-25),365,(k+25),370);
setcolor(black);
repeat                           (*ce repeat fait que le mouvement de rebondissement soit continu*)
if (a=1) and (b=1) then hautdroite else
if (a=1) and (b=2) then basgauche else
if (a=2) and (b=1) then hautgauche else
if (a=2) and (b=2) then basdroite else
if (a=3) and (b=1) then hautdroite else
if (a=3) and (b=2) then basgauche else
if (a=4) and (b=1) then basdroite else
if (a=4) and (b=2) then hautgauche;
until (c=26) or (score=150);
end;


procedure give_name;
begin                   (*procedure demandant le nom de l'usager*)
clrscr;
textcolor(magenta); delay(1000);
 gotoXY(18,7);    write('Veuillez');    delay(1000);
 gotoXY(26,8);    write('s''il ');         delay(1000);
 gotoXY(30,9);    write('-');    delay(1000);
 gotoXY(31,10);    write('vous');      delay(1000);
 gotoXY(35,11);    write('-');    delay(1000);
 gotoXY(36,12);    write('plait');        delay(1000);
 gotoXY(41,13);    write('entrer');    delay(1000);
 gotoXY(47,14);    write('votre');      delay(1000);
 gotoXY(52,15);    write('nom');       delay(1000);
 gotoXY(55,16);    write('de');       delay(1000);
 gotoXY(57,18);    writeln('BALL BOUNCE');
 gotoXY(62,20);
 readln(nom);
 end;





procedure consigne_de_jeu;
begin                    (*procedure expliquant les consignes*)
clrscr;
textcolor(lightblue);
Gotoxy(10,2); write('Bonjour ',nom,',');
Gotoxy(1,4); write('Nous esperons que vous etes prets a jouer BALL BOUNCE!');
GotoXy(5,6); write('Voici les consignes et les regles de notre jeu :');
Gotoxy(1,8); write('* 1 * Pour pouvoir bouger la barre vers la droite peser sur le 3');
Gotoxy(1,9); write('* 2 * Pour pouvoir bouger la Barre vers la gauche peser sur le 1');
Gotoxy(1,10); write('* 3 * Faire rebondir la balle 15 fois sur la bar pour reussir le niveau');
GotoXy(1,11); write('* 4 * Lorsque la balle tombe a l''eau vous devez recommencer le jeu ou quitter');
GotoXY(1,12); write('* 5 * Si la barre atteind la limite a droite elle se retrouve a la limite gauche');
GotoXY(1,13); write('* 6 * Et vice versa si la barre atteind la limite gauche');
GotoXY(1,14); write('* 7 * Les Questions entre chaques niveaux content comme des points bonus');
Gotoxy(1,15); write('* 8 * Le plus vous avancez dans les niveaux plus la vitesse de la balle augmente');
GotoXY(1,16); write('* 9 * Vous verrez votre score a la fin de la partie');
GotoXY(1,17); write('* 10 * Vous avez une seule vie a travers ce jeu faites attention!');
GotoXY(1,18); write('* 11 * Le plus important : AMUSEZ-VOUS!');
textcolor(lightblue+blink);
Gotoxy(20,22); write('* Si vous avez fini de lire et vous etes prets *');
gotoxy(30,23); write('* APUYER SUR ENTREE*');
    readln;
    end;

procedure recommencer_le_jeu ;
begin                       (*procedure demandant a l'usager si il veut recommencer a jouer*)
clrscr;
textcolor(lightred); delay(1000);
 gotoXY(18,7);    write('Voulez');    delay(1000);
 gotoXY(24,8);    write('-');         delay(1000);
 gotoXY(25,9);    write('vous');      delay(1000);
 gotoXY(29,10);    write('rejouer');        delay(1000);
 gotoXY(37,11);    write('BALL BOUNCE?');   delay(1000);
 gotoXY(55,13);    write('O/N');
  (*jusqua ce que la personne pese sur o la procedure va rejouer*)
   reponse2:=UPCASE(READKEY);
 if reponse2 = 'O'then finito:=0
 else if reponse2 = 'N' then finito:=1;
end;

 begin
 deuxieme;                (*le programme commence ici*)
  repeat
 speed:=10; finalscore:=0; g:=0;
 premiere; give_name; consigne_de_jeu;

 repeat
 tableau;
 if score=150 then gagneunegame;
 if g=1 then question1 else
 if g=2 then question2 else
 if g=3 then question3 else
 if g=4 then question4 else
 if g=5 then question5;
 until g=6;
 pointage;
 recommencer_le_jeu;
until finito=1;
bye;
end.