Skip to content

Instantly share code, notes, and snippets.

@tiltedlistener
Created October 7, 2015 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiltedlistener/89ed35761f6c79347c04 to your computer and use it in GitHub Desktop.
Save tiltedlistener/89ed35761f6c79347c04 to your computer and use it in GitHub Desktop.
NU: Hangman Partway Wrong
public class Hangman {
private String wordToGuess = "t";
private boolean gameRunning = true;
private int guessCount = 4;
public void playGame() {
while (gameRunning) {
// Fake player guess
String guess = "z";
if (wordToGuess.indexOf(guess) != -1) {
wordToGuess = wordToGuess.replace(guess, "");
if (wordToGuess.length() == 0) {
System.out.println("You Won");
break;
}
} else {
guessCount--;
if (guessCount == 0) {
System.out.println("You Lost :(");
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment