Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class penduTableauVersion
  4. {
  5.    
  6.     public static void main(String[] args)
  7.     {
  8.         Scanner lire=new Scanner(System.in);
  9.        
  10.        
  11.         System.out.print("Joueur 1, saisissez un mot a faire deviner ( sans espace ) : ");
  12.         String mot = lire.nextLine();
  13.         int longMot = mot.length();
  14.         char[]tableau = new char[longMot];
  15.         char tireDu6 = '-';
  16.         boolean perdu = false;
  17.         int conteurPerte = 0;
  18.        
  19.         //-----------------------------on rempli le tableau de " - "
  20.        
  21.         for(int j = 0; j<=longMot - 1; j++)
  22.         {
  23.             tableau[j] = tireDu6 ;
  24.         }  
  25.        
  26.         //-----------------------------on initialise le tableau avec la premier et derniere lettre
  27.        
  28.         for(int i = 0; i<=longMot-1; i++)
  29.         {
  30.             if(mot.charAt(i) == mot.charAt(0))
  31.             {
  32.                 tableau[i] = mot.charAt(0);
  33.             }
  34.             else if(mot.charAt(i) == mot.charAt(longMot -1))
  35.             {
  36.                 tableau[i] = mot.charAt(longMot -1);
  37.             }
  38.         }
  39.         System.out.println(tableau);
  40.        
  41.         System.out.println(" ");
  42.         System.out.println("Joueur 2, essayez de deviner les lettres composant ce mot. vous avez 10 erreurs possible avant d'etre pendu.");
  43.        
  44.         //-----------------------------on test si le caractere saisi est dans le mot
  45.        
  46.         while(conteurPerte < 10)
  47.         {
  48.             System.out.print("Saisisez un caractere : ");
  49.             char caracPotentiel = lire.nextLine().charAt(0);
  50.        
  51.             for(int p = 0; p<=longMot-1; p++)
  52.             {
  53.                 if(caracPotentiel == tableau[p])
  54.                 {
  55.                     perdu = true;
  56.                 }
  57.             }
  58.             for(int w = 0; w<=longMot-1; w++)
  59.             {
  60.                 if(caracPotentiel == mot.charAt(w))
  61.                 {
  62.                     tableau[w] = caracPotentiel;
  63.                 }
  64.             }  
  65.            
  66.             System.out.println(tableau);
  67.            
  68.             if(perdu = false)
  69.             {
  70.                 System.out.println("perdu");
  71.                 conteurPerte++;
  72.             }
  73.             perdu = false;
  74.             System.out.println(" ");
  75.         }
  76.        
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement