Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Hangman
- Plays a basic game of hangman
- Author: JJ Programmer
- Version: 0.01
- Date: 11/07/2017
- """
- import random
- def makeArt():
- art = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
- art[0] = ' +---------+'
- art[1] = ' | |'
- art[2] = ' |'
- art[3] = ' |'
- art[4] = ' |'
- art[5] = ' |'
- art[6] = ' |'
- art[7] = ' |'
- art[8] = ' |'
- art[9] = ' |'
- art[10] = ' |'
- art[11] = ' |'
- art[12] = ' |'
- art[13] = ' |'
- art[14] = ' |'
- art[15] = ' ------------------+'
- return art
- def readWords():
- wordList = []
- with open('wordlist.10000.txt') as wordFile:
- count = 0
- for line in wordFile:
- if len(line) > 4 and len(line) < 7:
- wordList.append(line[0:-1])
- return wordList
- def printArt(art):
- for line in art:
- print(line)
- def setParts():
- parts = {
- 1 : head,
- 2 : body,
- 3 : leftArm,
- 4 : rightArm,
- 5 : leftLeg,
- 6 : rightLeg,
- }
- return parts
- def head(art):
- art[2] = ' +---+ |'
- art[3] = ' + + |'
- art[4] = ' +---+ |'
- def body(art):
- art[5] = ' + |'
- art[6] = ' +-----+ |'
- art[7] = ' + + |'
- art[8] = ' + + |'
- art[9] = ' + + |'
- art[10] = ' +-----+ |'
- def leftArm(art):
- art[7] = ' -----+ + |'
- pass
- def rightArm(art):
- art[7] = ' -----+ +----- |'
- pass
- def leftLeg(art):
- art[11] = ' | |'
- art[12] = ' | |'
- art[13] = ' | |'
- pass
- def rightLeg(art):
- art[11] = ' | | |'
- art[12] = ' | | |'
- art[13] = ' | | |'
- pass
- def init():
- bodyParts = setParts()
- art = makeArt()
- words = readWords()
- return bodyParts, art, words
- def main():
- bodyParts, art, words = init()
- misses = 1
- bodyParts[misses](art)
- misses = 2
- bodyParts[misses](art)
- misses = 3
- bodyParts[misses](art)
- misses = 4
- bodyParts[misses](art)
- misses = 5
- bodyParts[misses](art)
- misses = 6
- bodyParts[misses](art)
- printArt(art);
- for i in range(20):
- print(random.choice(words))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement