Merge pull request #581 from ironleman/main

Hangman Java Update
This commit is contained in:
Jeff Atwood
2022-02-22 11:10:40 -06:00
committed by GitHub

View File

@@ -10,6 +10,7 @@ import java.util.stream.Collectors;
*
* Converted from BASIC to Java by Aldrin Misquitta (@aldrinm)
*/
public class Hangman {
//50 word list
@@ -32,7 +33,7 @@ public class Hangman {
int[] usedWords = new int[50];
int roundNumber = 1;
int totalWords = words.size();
boolean continueGame;
boolean continueGame = false;
do {
if (roundNumber > totalWords) {
@@ -53,7 +54,10 @@ public class Hangman {
System.out.print("\nWANT ANOTHER WORD? ");
}
final String anotherWordChoice = scan.next();
continueGame = "YES".equals(anotherWordChoice);
if (anotherWordChoice.toUpperCase().equals("YES") || anotherWordChoice.toUpperCase().equals("Y")) {
continueGame = true;
}
roundNumber++;
} while (continueGame);
@@ -99,7 +103,7 @@ public class Hangman {
System.out.print("WHAT IS YOUR GUESS? ");
var tmpRead = scan.next();
guessLetter = tmpRead.charAt(0);
guessLetter = Character.toUpperCase(tmpRead.charAt(0));
if (lettersUsed.contains(guessLetter)) {
System.out.println("YOU GUESSED THAT LETTER BEFORE!");
} else {
@@ -132,7 +136,7 @@ public class Hangman {
printDiscoveredLetters(discoveredLetters);
System.out.print("WHAT IS YOUR GUESS FOR THE WORD? ");
final String wordGuess = scan.next();
if (wordGuess.equals(word)) {
if (wordGuess.toUpperCase().equals(word)) {
System.out.printf("RIGHT!! IT TOOK YOU %s GUESSES!", totalWordGuesses);
return true;
} else {
@@ -241,5 +245,3 @@ public class Hangman {
}
}