program pendufinal;

uses graph,Crt; (*activer le graphique et les varibles necessaires de turbopascal*)

var mot, u, n1, solution, text : string;
    x, erreur, c, y, p, pilote, mode : integer;
    lettre,fin,calembredaine,t : char;
    clef : boolean;


{mots au hasard joueur solo}

procedure dictionnaire (var mot:string);
var    x:integer;
begin
 randomize; {choisir les mots au hasard}
 x:=random(100)+1;
 case x of
 {bibliotheque de mots}

 1: mot:='litteraire';
 2: mot:='anthologie';
 3: mot:='bateau';
 4: mot:='manteau';
 5: mot:='bague';
 6: mot:='ordinateur';
 7: mot:='parapluie';
 8: mot:='homozygote';
 9: mot:='atomique';
 10: mot:='dragon';
 11: mot:='fantome';
 12: mot:='couverture';
 13: mot:='tasse';
 14: mot:='rouleau';
 15: mot:='soldat';
 16: mot:='television';
 17: mot:='yogourt';
 18: mot:='tapis';
 19: mot:='the';
 20: mot:='sarrau';
 21: mot:='medecin';
 22: mot:='notaire';
 23: mot:='pompier';
 24: mot:='liberte';
 25: mot:='gateau';
 26: mot:='voiture';
 27: mot:='minute';
 28: mot:='acceleration';
 29: mot:='acide';
 30: mot:='sport';
 31: mot:='trompette';
 32: mot:='noel';
 33: mot:='photographie';
 34: mot:='soulier';
 35: mot:='foulard';
 36: mot:='chocolat';
 37: mot:='suspense';
 38: mot:='avion';
 39: mot:='pilote';
 40: mot:='printemps';
 41: mot:='doublure';
 42: mot:='bagarre';
 43: mot:='plante';
 44: mot:='reliure';
 45: mot:='mot';
 46: mot:='autoportrait';
 47: mot:='theiere';
 48: mot:='fourchette';
 49: mot:='internet';
 50: mot:='informatique';
 51: mot:='libellule';
 52: mot:='boucle';
 53: mot:='olibrius';
 54: mot:='mordore';
 55: mot:='cafard';
 56: mot:='psychanalyse';
 57: mot:='portail';
 58: mot:='sofa';
 59: mot:='divan';
 60: mot:='capsule';
 61: mot:='gouvernement';
 62: mot:='poutine';
 63: mot:='sauvegarder';
 64: mot:='coeur';
 65: mot:='electricite';
 66: mot:='miroir';
 67: mot:='garcon';
 68: mot:='chandail';
 69: mot:='masque';
 70: mot:='document';
 71: mot:='lunettes';
 72: mot:='action';
 73: mot:='chameau';
 74: mot:='etoile';
 75: mot:='guitare';
 76: mot:='demaquillant';
 77: mot:='rideau';
 78: mot:='castor';
 79: mot:='pendu';
 80: mot:='reve';
 81: mot:='chateau';
 82: mot:='geek';
 83: mot:='football';
 84: mot:='amour';
 85: mot:='yeux';
 86: mot:='orteil';
 87: mot:='energisant';
 88: mot:='thermometre';
 89: mot:='cellulaire';
 90: mot:='pantalon';
 91: mot:='fifrelin';
 92: mot:='calembredaine';
 93: mot:='faribole';
 94: mot:='surprise';
 95: mot:='abscons';
 96: mot:='genitrice';
 97: mot:='serpilliere';
 98: mot:='zut';
 99: mot:='patawawa';
 100: mot:='malus';

 end;{of case}

end; {fin procedure dico}
{**************************************************************}
procedure pendu; {tout le pendu}

 var mot, u,n2, solution : string;
     x, erreur,c : integer;
     lettre,fin,choix : char;
     clef : boolean;
begin
repeat;             {choix nombre joueur,page2}
 clrscr;
 gotoxy(10,3);
 write('                     ---Pendu ---');
 gotoxy(8,5);
 write('___________________________________________________________________');
 gotoxy(8,10);
 write('                Jouez vous a 1 ou a 2 ?');
 gotoxy(8,14);
 write('                         Mode Solo: 1');
 gotoxy(8,16);
 write('                  Mode Multijoueur: 2');
 gotoxy(8,23);
 write('                              ',n1,' votre score est de ',p,' points');
 readln(choix);
 if choix='1' then
  dictionnaire(mot)  {si joueur solo}
 else

 begin            {si multi joueurs}
  clrscr;
  gotoxy(10,3);
  write('                 ---Pendu---');
  gotoxy(8,5);
  write('__________________________________________________________________');
  gotoxy(8,8);
  write('Joueur 2, quel est ton nom?');
  readln(n2);
  clrscr;
  gotoxy(10,3);
  write('                 ---Pendu---');
  gotoxy(8,5);
  write('__________________________________________________________________');
  gotoxy(8,8);
  write(n2,' : Entre le mot a trouver:  ');
   readln (mot);
 end;                               {choix du mot a trouver par joueur2}
  clrscr;
   u:='';
   for x:= 1 to length(mot) do {tirets pour longueur mot}
    insert (' ',u,x);
    gotoxy (5,10);
   for x:= 1 to length(mot)do
    write ('-');
   erreur:= 0;

      {dessin ascii potence}
     gotoxy (40,17);
     write('I');
     gotoxy(41,16);
     write('_|_');
     gotoxy(44,17);
     write('I');
     gotoxy(41,15);
     write(' |');
     gotoxy(41,14);
     write(' |');
     gotoxy(41,13);
     write(' |');
     gotoxy(42,12);
     write('|/  |');
     gotoxy(42,11);
     write('_____');
  repeat        {debut jeu}
     gotoxy(3,2);
     write('---Pendu---');
     gotoxy(3,3);
     write('_________________________________________________________________');
     gotoxy (3,4);
     writeln (n1,': Essaye de deviner le mot! Tu as 6 chances');
     gotoxy(3,5);
     write ('Lettre choisie: ');


    {Resolution}

    if lettre ='1' then
     begin
        gotoxy (3,6);
        write('La lettre precedente etait ');
        readln (solution);
        writeln;
        writeln;
      if solution = mot then write ('!!Felicitation!!')
      else write ('Desole cest faux! La solution etait "',mot,'".');
     end;

    readln (lettre);
    clef:=false;
    for x:=1 to length(mot) do
     if mot[x]=lettre then
        begin
         u[x]:= lettre;
         clef:=true;
        end;
     if clef= false then     {lorsque choix = bien}
       begin
         erreur:=erreur+1;
         gotoxy (5,17+erreur);
         write('Mauvaise lettre!:--->  ', lettre,'  <---');
       end;

        if erreur =1 then    {lorsque choix pas bien1}
        begin
         gotoxy(46,13);
         write('ö');
         sound(176); delay(600);
         sound(60);  delay(800);
         nosound;    delay(50);
        end;

        if erreur =2 then    {lorsque choix pas bien2}
        begin
         gotoxy(45,13);
         write('\');
         sound(176); delay(600);
         sound(60);  delay(800);
         nosound;    delay(50);
        end;

        if erreur =3 then    {lorsque choix pas bien3}
        begin
         gotoxy(47,13);
         write('/');
         sound(176); delay(600);
         sound(60);  delay(800);
         nosound;    delay(50);
        end;

        if erreur =4 then   {lorsque choix pas bien4}
        begin
         gotoxy(46,14);
         write('I');
         sound(176); delay(600);
         sound(60);  delay(800);
         nosound;    delay(50);
        end;

        if erreur =5 then   {lorsque choix pas bien5}
        begin
         gotoxy(45,15);
         write('/');
         sound(176); delay(600);
         sound(60);  delay(800);
         nosound;    delay(50);
        end;

        if erreur =6 then    {derniere chance pas bien}
        begin
         gotoxy(47,15);
         write('\');
         sound(176); delay(600);
         sound(60);  delay(800);
         nosound;    delay(50);
        end;

      gotoxy(5,9);
      write(u);

      until (u=mot) or (erreur=6); {fin pendu car gagne ou perdu}

      gotoxy(30,23);
      write('Presser nimporte quelle touche.');

      repeat until keypressed;
      calembredaine:=readkey;

      if (u=mot) or (erreur=6) then
      clrscr;

      if u=mot then    {REUSSITE + nombre de point+ toune bravo}
       begin
        gotoxy(3,8);
        write ('                !! Vous avez reussi avec ',erreur,' erreur(s)!!');
        gotoxy(3,9);
        write('                        ',n1,' , tu gagnes 20 points!');
        p:=p+20;
          sound(392); delay(350); nosound; delay(80);
          sound(392); delay(150); nosound; delay(50);
          sound(392); delay(200); nosound; delay(50);
          sound(440); delay(250); nosound; delay(50);
          sound(392); delay(250); nosound; delay(50);
          sound(440); delay(250); nosound; delay(50);
          sound(494); delay(1200);nosound; delay(50);
           end;


      if erreur=6 then  {echec + nombre de point + toune =( }
       begin
        gotoxy(10,10);
        write('Le bon mot etait:  "',mot, '"');
        gotoxy(10,11);
        write(n1,', tu perds 10 points!');
        sound(1976); delay(100);  sound(1720); delay(100);
        sound(1568); delay(100);  sound(1397); delay(100);
        sound(1319); delay(100);  sound(1175); delay(100);
        sound(1047); delay(100);  sound(988);  delay(100);
        sound(880);  delay(100);  sound(784);  delay(100);
        sound(698);  delay(100);  sound(659);  delay(100);
        sound(587);  delay(100);  sound(523);  delay(100);
        sound(494);  delay(100);  sound(440);  delay(100);
        sound(392);  delay(100);  sound(349);  delay(100);
        sound(330);  delay(100);  sound(294);  delay(100);
        sound(262);  delay(100);  sound(247);  delay(100);
        sound(220);  delay(100);  sound(196);  delay(100);
        sound(176);  delay(100);  sound(165);  delay(100);
        sound(147);  delay(100);  sound(131);  delay(100);
        nosound;     delay(150);  sound(60);   delay(1000);
        nosound;
        p:=p-10;
        end;
     gotoxy(10,15);    {choix byebye ou recommencer jouer}
     write (' Appuyez sur Y pour quitter le programme ou enter pour recommencer');
     readln(fin);
   until fin='y';
   if fin='y' then     {dessin pendu au revoir}
    begin       {page douverture}
pilote:=detect;
initgraph(pilote,mode, 'm:\bgi');
outtextxy(390,100, 'Alors tu reviendras');
outtextxy(390,120, '  me pendre une');
outtextxy(390,140, ' prochaine fois!!!');
circle(310,300,100);
settextstyle(sansseriffont,  horizdir, 2);
outtextxy(260,250, 'X        X');
ellipse(310,310,180,360,40,40);
circle(380,210,5);
circle(400,190,15);
ellipse(470,120,0,360,100,70);
line(310,400,310,480); (*reste du corps*)
setlinestyle(solidln, $c3, thickwidth);
line(310,200,310,150);  (*line verti au dessus de la tete (corde)*)
line(310,150,100,150);  (*ligne horiz*)
line(100,150,100,480); (*baton pour le pendre*)
sound(392); delay(150);nosound;delay(50);{5e symphonie}
sound(392);delay(150);nosound;delay(50);
sound(392);delay(150);nosound;delay(50);
sound(315);delay(800);nosound;delay(600);
sound(349);delay(150);nosound;delay(50);
sound(349);delay(150);nosound;delay(50);
sound(349);delay(150);nosound;delay(50);
sound(294);delay(900);nosound;delay(600);

readln;
closegraph;
     repeat until keypressed;
    calembredaine:=readkey;
     clrscr;
    end;

end;{procedure pendu}

{page douverture}

procedure debut(var calembdredaine:char);

 begin
  pilote:=detect;
  initgraph(pilote,mode, 'm:\bgi');
  outtextxy(300,400, 'Par Emilie M.L. Joly et Etienne Sakr');
  settextstyle(gothicfont, horizdir,6);
  outtextxy(50,80, 'Jeu de Bonhomme Pendu');
  delay(500);
           sound(262);
           line(100,380,140,380); (*base*)
           delay(500); sound(294);
           line(120,380,120,160);  (*ligne vertical grosse*)
           delay(500); sound(330);
           line(120,160,200,160); (*ligne du haut horizontal*)
           delay(500); sound(349);
           line(200,180,200,160); (*mini corde*)
           delay(500); sound(392);
           circle(200,200,20);       (*tete*)
           delay(500); sound(440);
           line(200,220,200,295); (*corps*)
           delay(500); sound(494);
           line(200,239,230,230);  (*bras a droite*)
           line(200,239,170,230); (*bras a gauche*)
           delay(500); sound(523);
           line(200,295,230,310); (*pied a droite*)
           line(200,295,170,310); (*pied a droite*)
           delay(500); sound(131);
           settextstyle(defaultfont, horizdir, 0);
           outtextxy(190,190, 'x');    (*oeil a droite*)
           outtextxy(205,190, 'x');    (*oeil a gauche*)
           ellipse(200,210,0,180,10,5); (*sourire triste*)
           delay(1000); nosound;
           settextstyle(sansseriffont, horizdir, 2);
           outtextxy(270,200, 'Bonjour Joueur 1! Quel est ton nom?');
           readln(n1);
           outtextxy(270,250, 'Enchante, '+n1);
           outtextxy(270,300, 'Presser ENTER pour acceder');
           outtextxy(270,320, 'au menu');
readln;
closegraph;
  repeat until keypressed;
  calembredaine:=readkey;
  clrscr;

end;{procedure debut}




 {programme principale}


 begin
  debut(calembredaine);
  pendu;
 end.        {FIN}