Advertisement
TheRightGuy

Hmmmm

Feb 8th, 2022
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1. public void hangmanGame() {
  2.         int mistakes = -1;
  3.         while (true) {
  4.             if (correctCharsEntered.length() == sentence.length() + 2) break;
  5.             System.out.println("Enter the word you want to experiment hangman on ");
  6.             String human = input.next();
  7.             if (maskedSentence.toString().equals(sentence)) {
  8.                 System.out.println("The word was entered correctly");
  9.                 boardDisplay();
  10.                 System.out.println(maskedSentence);
  11.                 break;
  12.             } else if (human.equals(sentence)) {
  13.                 System.out.println(human);
  14.                 break;
  15.             }
  16.             while (human.length() != 1) {
  17.                 System.out.println("Enter one character");
  18.                 human = input.next();
  19.             }
  20.             correctCharsEntered.append(human);
  21.             if (isCorrectCharacter(sentence, correctCharsEntered)) {
  22.                 incorrectCharsEntered.append(correctCharsEntered.charAt(correctCharsEntered.length() - 1));
  23.                 mistakes++;
  24.                 for (int i = 0; i <= mistakes; i++) {
  25.                     printStart();
  26.                     if (i == 1) {
  27.                         System.out.println(hangman.get(i)); // left arm
  28.                         System.out.println(hangman.get(0)); // and |
  29.                     }else if (i == 2){
  30.                         System.out.println(hangman.get(i-1) + hangman.get(i)); // left arm and chest
  31.                         System.out.println(hangman.get(0)); // and |
  32.                     }else if(i == 3){
  33.                         System.out.println(hangman.get(i-2) + hangman.get(i-1) + hangman.get(i)); // left arm,chest,right arm
  34.                         System.out.println(hangman.get(0)); // and |
  35.                     }else if(i == 4){
  36.                         System.out.println(hangman.get(i-3) + hangman.get(i-2) + hangman.get(i-1)); // the same as above
  37.                         System.out.println(hangman.get(i)); // left leg
  38.                     } else if( i == 5){
  39.                         System.out.println(hangman.get(i-4) + hangman.get(i-3) + hangman.get(i-2)); // the same as above
  40.                         System.out.println(hangman.get(i-1) + " " + hangman.get(i));
  41.                         System.out.println("GAME OVER");
  42.                         break;
  43.                     } else {
  44.                         System.out.println(hangman.get(i));
  45.                         System.out.println(hangman.get(i));
  46.                     }
  47.                     System.out.println("/-\\");
  48.                 }
  49.                 System.out.println(maskedSentence);
  50.                 correctCharsEntered.deleteCharAt(correctCharsEntered.length() - 1);
  51.  
  52.             } else {
  53.                 for (int i = 0; i < sentence.length(); i++) {
  54.                     unMaskSentence(sentence, i);
  55.                 }
  56.             }
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement