Advertisement
Guest User

ForJord

a guest
Nov 11th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. //System.out.println(" |\n |\n |\n |\n__/\\__");
  2. Scanner scan=new Scanner(System.in);
  3. String[]words=new String[5];
  4.  
  5. char help=' ';
  6.  
  7. int player=2,score_1=0,score_2=0,i,lives=7,count=0,wrong=0, bre=0;;
  8.  
  9. String word=" ",guess=" ",check=" ", answer=" ";
  10.  
  11. System.out.println("WELCOME TO HANGMAN\n");
  12.  
  13. while(count<5) {
  14. if (player==2)
  15. player--;
  16. else
  17. player++;
  18.  
  19. System.out.println("PLAYER 1: "+score_1+"\tPLAYER 2: "+score_2);
  20. System.out.println("Player "+player+" enter the secret word ");
  21. word=scan.nextLine();
  22. System.out.println("\n\n\n\n\n\n\n\n");
  23.  
  24. words[count]=word;
  25. String[] output=new String[word.length()];
  26. String[] input=new String[word.length()];
  27. for (i=0;i<word.length();i++)
  28. input[i]="_";
  29. for (i=0;i<word.length();i++)
  30. output[i]=String.valueOf(word.charAt(i));
  31.  
  32. count++;
  33. lives=7;
  34. bre=0;
  35.  
  36. while(true) {
  37.  
  38. if (lives==0) {
  39. System.out.println("GAME OVER!\n\n\n");
  40. if(player==1)
  41. score_1++;
  42. else
  43. score_2++;
  44. break;
  45. }
  46. for (i=0;i<output.length;i++) {
  47. if (!(output[i].equals(input[i])))
  48. break;
  49. if (i==(output.length-1))
  50. bre++;
  51.  
  52. }
  53. if (bre==1) {
  54. System.out.println("THAT'S THE ANSWER!\n\n\n");
  55. if (player==1)
  56. score_2++;
  57. else
  58. score_1++;
  59. break;
  60. }
  61.  
  62. for (i=0;i<input.length;i++)
  63. System.out.print(input[i]+" ");
  64.  
  65. System.out.println();
  66. System.out.printf("Guess a letter (%d tries left) ", lives);
  67. guess=scan.nextLine();
  68. wrong=0;
  69.  
  70. for (i=0;i<word.length();i++) {
  71. help=word.charAt(i);
  72. check=String.valueOf(help);
  73. if (check.equals(guess)) {
  74. input[i]=check;
  75. wrong++;
  76. }
  77.  
  78. if (i==(word.length()-1)&&wrong==0) {
  79. lives--;
  80. System.out.println("Wrong!");
  81. break;
  82. }
  83. if (i==(word.length()-1)&&wrong>0)
  84. System.out.println("Correct!");
  85.  
  86.  
  87. }
  88.  
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement