SHOW:
|
|
- or go back to the newest paste.
1 | - | #V5 21/9/14 16:52:04 Bug fixes |
1 | + | #V6 22/9/14 10:00:04 Bug fixes |
2 | import random | |
3 | import os | |
4 | MAX = 10 | |
5 | ||
6 | def drawStick(lvl): | |
7 | if lvl <= 0: stage = "\n\n\n\n\n\n\n" | |
8 | elif lvl == 1: stage = "\n\n\n\n\n\n\n /_\\" | |
9 | elif lvl == 2: stage = " |\n |\n |\n |\n |\n |\n |\n /_\\" | |
10 | elif lvl == 3: stage = " -------|\n |\n |\n |\n |\n |\n |\n /_\\" | |
11 | elif lvl == 4: stage = " |-------|\n | |\n |\n |\n |\n |\n |\n /_\\" | |
12 | elif lvl == 5: stage = " |-------|\n | |\n ( ) |\n |\n |\n |\n |\n /_\\" | |
13 | elif lvl == 6: stage = " |-------|\n | |\n ( ) |\n | |\n | |\n |\n |\n /_\\" | |
14 | elif lvl == 7: stage = " |-------|\n | |\n ( ) |\n |- |\n | |\n |\n |\n /_\\" | |
15 | elif lvl == 8: stage = " |-------|\n | |\n ( ) |\n -|- |\n | |\n |\n |\n /_\\" | |
16 | elif lvl == 9: stage = " |-------|\n | |\n ( ) |\n -|- |\n | |\n \ |\n |\n /_\\" | |
17 | else: stage = " |-------|\n | |\n ( ) |\n -|- |\n | |\n / \ |\n |\n /_\\" | |
18 | return stage | |
19 | while 1: | |
20 | try: | |
21 | path = os.path.dirname(os.path.realpath(__file__)) + "/wordlist.txt" | |
22 | wordList = open(path).read().splitlines() | |
23 | except IOError: | |
24 | print "Cant find Word List" | |
25 | raise SystemExit(0) | |
26 | totalLength = len(wordList) | |
27 | while 1: | |
28 | wordID = random.randint(0,totalLength) | |
29 | word2guess = wordList[wordID].lower() | |
30 | wordLength = len(word2guess) | |
31 | if wordLength <= MAX:break | |
32 | print " Word #%d\n %d letters\n----------------------" %(wordID, wordLength) | |
33 | - | #print word2guess |
33 | + | print word2guess |
34 | guessed = [] | |
35 | full = False | |
36 | lettersUsed = "" | |
37 | for num in range(wordLength): | |
38 | guessed.append('*') | |
39 | ALLOWED = 10 | |
40 | remainingGuesses = ALLOWED | |
41 | while remainingGuesses > 0: | |
42 | numberOf = 0 | |
43 | word = "" | |
44 | for num in range(0,wordLength): | |
45 | word = word + guessed[num] | |
46 | print " " + word + "\n\n" + drawStick(ALLOWED - remainingGuesses) + "\n\n%d lives left\nEnter a letter\nUsed: %s"%(remainingGuesses,lettersUsed) | |
47 | while 1: | |
48 | guess = raw_input() | |
49 | guess = guess.lower() | |
50 | if len(guess) > 0: | |
51 | if lettersUsed.find(guess.upper()) == -1: | |
52 | if guess.isalpha():break | |
53 | else: print "Letters only!" | |
54 | else: print "You've used that before!" | |
55 | else: print "You didn\'t enter anything!" | |
56 | if guess == word2guess: | |
57 | full = True | |
58 | break | |
59 | - | guess = guess[0] |
59 | + | if len(guess) == 1: |
60 | - | lettersUsed = lettersUsed + guess.upper() + " " |
60 | + | guess = guess[0] |
61 | - | if len(lettersUsed) % 10 == 0: lettersUsed = lettersUsed + "\n" |
61 | + | lettersUsed = lettersUsed + guess.upper() + " " |
62 | if len(lettersUsed) % 10 == 0: lettersUsed = lettersUsed + "\n" | |
63 | - | if guess == word2guess[num]: |
63 | + | for num in range(0,wordLength): |
64 | - | guessed[num] = word2guess[num] |
64 | + | if guess == word2guess[num]: |
65 | - | numberOf = numberOf + 1 |
65 | + | guessed[num] = word2guess[num] |
66 | - | gotIt = guessed == list(word2guess) |
66 | + | numberOf = numberOf + 1 |
67 | - | if guessed == list(word2guess):break |
67 | + | gotIt = guessed == list(word2guess) |
68 | if guessed == list(word2guess):break | |
69 | print "----------------------" | |
70 | if numberOf == 0: | |
71 | - | print "There are no \'%s\'s"%(guess) |
71 | + | |
72 | - | else: |
72 | + | if len(guess) == 1: print "There are no \'%s\'s"%(guess) |
73 | - | print "There is %d \'%s\'"%(numberOf,guess) |
73 | + | else: print "That is not the word!" |
74 | - | if guessed == list(word2guess) or full: |
74 | + | else: print "There is %d \'%s\'"%(numberOf,guess) |
75 | - | print "Well done, you got \'%s\' with %d lives left!"%(word2guess,remainingGuesses) |
75 | + | if guessed == list(word2guess) or full: print "Well done, you got \'%s\' with %d lives left!"%(word2guess,remainingGuesses) |
76 | - | else: |
76 | + | else: print "Oh noes... The word was \""+word2guess+"\"\n" + drawStick(10) |
77 | - | print "Oh noes... The word was \""+word2guess+"\"\n" + drawStick(10) |
77 | + | |
78 | print "Bye" | |
79 | break |