Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class penduTableauVersion
- {
- public static void main(String[] args)
- {
- Scanner lire=new Scanner(System.in);
- System.out.print("Joueur 1, saisissez un mot a faire deviner ( sans espace ) : ");
- String mot = lire.nextLine();
- int longMot = mot.length();
- char[]tableau = new char[longMot];
- char tireDu6 = '-';
- boolean perdu = false;
- int conteurPerte = 0;
- //-----------------------------on rempli le tableau de " - "
- for(int j = 0; j<=longMot - 1; j++)
- {
- tableau[j] = tireDu6 ;
- }
- //-----------------------------on initialise le tableau avec la premier et derniere lettre
- for(int i = 0; i<=longMot-1; i++)
- {
- if(mot.charAt(i) == mot.charAt(0))
- {
- tableau[i] = mot.charAt(0);
- }
- else if(mot.charAt(i) == mot.charAt(longMot -1))
- {
- tableau[i] = mot.charAt(longMot -1);
- }
- }
- System.out.println(tableau);
- System.out.println(" ");
- System.out.println("Joueur 2, essayez de deviner les lettres composant ce mot. vous avez 10 erreurs possible avant d'etre pendu.");
- //-----------------------------on test si le caractere saisi est dans le mot
- while(conteurPerte < 10)
- {
- System.out.print("Saisisez un caractere : ");
- char caracPotentiel = lire.nextLine().charAt(0);
- for(int p = 0; p<=longMot-1; p++)
- {
- if(caracPotentiel == tableau[p])
- {
- perdu = true;
- }
- }
- for(int w = 0; w<=longMot-1; w++)
- {
- if(caracPotentiel == mot.charAt(w))
- {
- tableau[w] = caracPotentiel;
- }
- }
- System.out.println(tableau);
- if(perdu = false)
- {
- System.out.println("perdu");
- conteurPerte++;
- }
- perdu = false;
- System.out.println(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement