Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package training;
  2. import java.util.Scanner;
  3.  
  4. public class Pendu {
  5.  
  6. public static void main(String[] args) {
  7. int vie = 10;
  8. String mot1 = "petasse";
  9. String tableauresultat[] = new String[mot1.length()];
  10. String tableaumot[] = new String[mot1.length()];
  11. Scanner sc = new Scanner(System.in);
  12. for (int i = 0; i < mot1.length(); i++ ) {
  13. tableauresultat[i] = "*";
  14. tableaumot[i] = mot1.substring(i, i+1);
  15. }
  16. while (vie > 0) {
  17. System.out.println("Choissisez une lettre");
  18. String str = sc.nextLine();
  19. System.out.println("Vous avez saisi : " + str);
  20.  
  21. String motactuel = "0";
  22. for (int i = 0; i < mot1.length(); i++ ) {
  23. if (str.equals(tableaumot[i])) {
  24. tableauresultat[i] = tableaumot[i];
  25. }
  26. motactuel = motactuel + tableauresultat[i];
  27. }
  28. motactuel = motactuel.replaceAll("[\\d]", "");
  29. vie = vie - 1;
  30. if (motactuel.equals(mot1)) {
  31. System.out.println("T'as gagné");
  32. System.out.println("le mot était bel et bien: " +mot1);
  33. break;
  34. }
  35. if (vie == 0) {
  36. System.out.println("tu as perdu");
  37. System.out.println("le mot était: " +mot1);
  38. System.out.println("try again");
  39. break;
  40. }
  41. System.out.println("Vous avez trouvé pour l'instant: "+ motactuel + " et il vous reste: " + vie + " vie(s) ");
  42.  
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement