Created
October 7, 2015 23:31
-
-
Save tiltedlistener/89ed35761f6c79347c04 to your computer and use it in GitHub Desktop.
NU: Hangman Partway Wrong
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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