IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Pascal Discussion :

Jeu du pendu


Sujet :

Pascal

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2012
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2012
    Messages : 1
    Points : 3
    Points
    3
    Par défaut Jeu du pendu
    Bonjour,

    je n'arrive pas à trouver un algo pour mon projet intitulé "jeu du pendu". Avec des commentaires appropriés, voilà ce que j'ai trouvé pour l'instant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    program pendu;
    uses crt;
    var
    TabMots : array [0..19] of string;
    imot,i,t,lm,posX,posY : integer;
    s:char;
    trouve : boolean;
     
    begin
    tabMots[0]:='cartographie';
    tabMots[1]:='combinaison';
    tabmots[2]:='conjuration';
    tabmots[3]:='diplomatie';
    tabMots[4]:='enthousiasme';
    tabmots[5]:='fermentation';
    tabmots[6]:='gasteropode';
    tabMots[7]:='alterophile';
    tabmots[8]:='humoristique';
    tabmots[9]:='penitencier';
    tabMots[10]:='avanturier';
    tabMots[11]:='chlorophile';
    tabmots[12]:='temperature';
    tabmots[13]:='prevaricateur';
    tabMots[14]:='paleantologue';
    tabmots[15]:='melancolique';
    tabmots[16]:='blasphematoire';
    tabMots[17]:='lycanthropie';
    tabmots[18]:='pharmaceutique';
    tabmots[19]:='incomprehension';
    repeat
    randomize;
    imot:=random(19);
    clrscr;
    write(imot);
    t:=10;
    gotoxy(1,7);
    write('Vous avez 10 essais pour trouver le mot');
    gotoxy(15,12);
    lm:=length(tabmots[imot]);
    for i:=1 to length(tabmots[imot]) do
        write('_ ');
    posX:=whereX; posY:=whereY;
    write('  ' , t, ' essais    ');
    repeat
    gotoxy(1,9);
    clreol;
    gotoxy(1,9);
    write('Votre lettre : ');
    readln(s);
    s:=upcase(s);
    trouve:=false;
    for i:=1 to length(tabmots[imot]) do
        begin
        if s=upcase(tabmots[imot][i]) then
           begin
           gotoxy(15+((i-1)*2),12);
           write(s);
           tabmots[imot][i]:=' ';
           trouve:=true;
           lm:=lm-1;
           end;
        end;
    if not trouve then
       begin
       t:=t-1;
       gotoxy(posX,posY);
       write('  ' , t, ' essais    ');
       end;
    until (t=0) or (lm=0);
    gotoxy(1,14);
    if lm=0 then
       writeln('Bravo, vous avez gagn‚');
    if t=0 then
       begin
       writeln('D‚sol‚, vous avez perdu');
       textcolor(4);
       for i:=1 to length(tabmots[imot]) do
          begin
          if tabmots[imot][i] <> ' ' then
             begin
              gotoxy(15+((i-1)*2),12);
              s:=upcase(tabmots[imot][i]);
              write(s);
             end;
          end;
       end;
    textcolor(7);
    {readln; }
    gotoxy(1,16);
    Write('Une autre partie? ');
    read(s);
    until not ((s='o') or (s='O'));
    end.

  2. #2
    Membre éprouvé
    Avatar de EpiTouille
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2009
    Messages
    372
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2009
    Messages : 372
    Points : 917
    Points
    917
    Par défaut
    Comme tu le sais, une chaine de caractère est un tableau de char (légerment différentes des char* en c) .

    Tu peux donc parcourir la chaine avec une boucle.
    A partir de ça, tu peux savoir si le caractère est ou non dans la chaine.

    apres tu n'as plus qu'a bouclé et à afficher la lettre en conséquence

Discussions similaires

  1. Code en bourne shell du jeu Le "PENDU"
    Par piment dans le forum Shell et commandes GNU
    Réponses: 1
    Dernier message: 20/07/2007, 14h17
  2. Jeu Bonhomme pendu
    Par yinyann86 dans le forum Delphi
    Réponses: 11
    Dernier message: 14/11/2006, 17h03
  3. Le jeu du pendu.
    Par giggs dans le forum C
    Réponses: 5
    Dernier message: 31/10/2006, 13h40
  4. jeu du pendu
    Par krachik dans le forum Langage
    Réponses: 5
    Dernier message: 24/10/2006, 12h48
  5. Réponses: 4
    Dernier message: 24/03/2006, 13h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo