Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void hangmanGame() {
- int mistakes = -1;
- while (true) {
- if (correctCharsEntered.length() == sentence.length() + 2) break;
- System.out.println("Enter the word you want to experiment hangman on ");
- String human = input.next();
- if (maskedSentence.toString().equals(sentence)) {
- System.out.println("The word was entered correctly");
- boardDisplay();
- System.out.println(maskedSentence);
- break;
- } else if (human.equals(sentence)) {
- System.out.println(human);
- break;
- }
- while (human.length() != 1) {
- System.out.println("Enter one character");
- human = input.next();
- }
- correctCharsEntered.append(human);
- if (isCorrectCharacter(sentence, correctCharsEntered)) {
- incorrectCharsEntered.append(correctCharsEntered.charAt(correctCharsEntered.length() - 1));
- mistakes++;
- for (int i = 0; i <= mistakes; i++) {
- printStart();
- if (i == 1) {
- System.out.println(hangman.get(i)); // left arm
- System.out.println(hangman.get(0)); // and |
- }else if (i == 2){
- System.out.println(hangman.get(i-1) + hangman.get(i)); // left arm and chest
- System.out.println(hangman.get(0)); // and |
- }else if(i == 3){
- System.out.println(hangman.get(i-2) + hangman.get(i-1) + hangman.get(i)); // left arm,chest,right arm
- System.out.println(hangman.get(0)); // and |
- }else if(i == 4){
- System.out.println(hangman.get(i-3) + hangman.get(i-2) + hangman.get(i-1)); // the same as above
- System.out.println(hangman.get(i)); // left leg
- } else if( i == 5){
- System.out.println(hangman.get(i-4) + hangman.get(i-3) + hangman.get(i-2)); // the same as above
- System.out.println(hangman.get(i-1) + " " + hangman.get(i));
- System.out.println("GAME OVER");
- break;
- } else {
- System.out.println(hangman.get(i));
- System.out.println(hangman.get(i));
- }
- System.out.println("/-\\");
- }
- System.out.println(maskedSentence);
- correctCharsEntered.deleteCharAt(correctCharsEntered.length() - 1);
- } else {
- for (int i = 0; i < sentence.length(); i++) {
- unMaskSentence(sentence, i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement