Created
June 14, 2013 21:39
-
-
Save imjacobclark/5785523 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Hey Computer, we're talking in Python! | |
#!/usr/bin/python | |
# We'll need some random functionality in this game :-) | |
import random | |
# The list of words we want the computer to choose from | |
words = ['dog', 'cat', 'computer', 'science'] | |
rightGuessedLetters = [] | |
wrongGuessedLetters = [] | |
guesses = 0 | |
# ------------------------------ FUNCTIONS ---------------------------------------------------------- | |
# An instruction that tells the computer to get a random word from the word list | |
def getWord(): | |
return random.randint(0, len(words) - 1) | |
# An instruction to tell the computer to ask the player for their guess | |
def getGuess(): | |
for letter in wordLetters: | |
if(letter in rightGuessedLetters): | |
print letter, | |
else: | |
print "_", | |
guesses = guesses + 1 | |
return raw_input("\n\nGuess: ") | |
# ------------------------------ END FUNCTIONS ------------------------------------------------------ | |
word = getWord() | |
wordLetters = list(words[word]) | |
print "\n #define 2013 - H A N G M A N! \n" | |
print "Your word to guess is " + str(len(words[word])) + " letters long." | |
while True: | |
# Run the function that asks the player for a guess | |
guess = getGuess() | |
# If the guess was in our randomly chosen word, yay! | |
if(guess in words[word]): | |
rightGuessedLetters.append(guess) | |
print "Awesome, nice guess!" | |
if(len(rightGuessedLetters) == len(words[word])): | |
print "\n\nCongratulations! You guessed it :-)" | |
print "The word was... " + words[word] + "\n\n" | |
break | |
# If the guess wasn't in our randomly chosen word, damn! | |
else: | |
wrongGuessedLetters.append(guess) | |
if guesses == 0: | |
print "________ " | |
print "| | " | |
print "| " | |
print "| " | |
print "| " | |
print "| " | |
elif guesses == 1: | |
print "________ " | |
print "| | " | |
print "| 0 " | |
print "| " | |
print "| " | |
print "| " | |
elif guesses == 2: | |
print "________ " | |
print "| | " | |
print "| 0 " | |
print "| / " | |
print "| " | |
print "| " | |
elif guesses == 3: | |
print "________ " | |
print "| | " | |
print "| 0 " | |
print "| /| " | |
print "| " | |
print "| " | |
elif guesses == 4: | |
print "________ " | |
print "| | " | |
print "| 0 " | |
print "| /|\ " | |
print "| " | |
print "| " | |
elif guesses == 5: | |
print "________ " | |
print "| | " | |
print "| 0 " | |
print "| /|\ " | |
print "| / " | |
print "| " | |
else: | |
print "________ " | |
print "| | " | |
print "| 0 " | |
print "| /|\ " | |
print "| / \ " | |
print "| " | |
# The player has 7 lives, if they guess incorrectly 7 times, they're dead! | |
if(len(wrongGuessedLetters) == 7): | |
print "Dead!" | |
print "The word was... " + words[word] | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment