1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,100 +0,0 @@ |
1 |
-come |
|
2 |
-get |
|
3 |
-give |
|
4 |
-go |
|
5 |
-keep |
|
6 |
-let |
|
7 |
-make |
|
8 |
-put |
|
9 |
-seem |
|
10 |
-take |
|
11 |
-be |
|
12 |
-do |
|
13 |
-have |
|
14 |
-say |
|
15 |
-see |
|
16 |
-send |
|
17 |
-may |
|
18 |
-will |
|
19 |
-about |
|
20 |
-across |
|
21 |
-after |
|
22 |
-against |
|
23 |
-among |
|
24 |
-at |
|
25 |
-before |
|
26 |
-between |
|
27 |
-by |
|
28 |
-down |
|
29 |
-from |
|
30 |
-in |
|
31 |
-off |
|
32 |
-on |
|
33 |
-over |
|
34 |
-through |
|
35 |
-to |
|
36 |
-under |
|
37 |
-up |
|
38 |
-with |
|
39 |
-as |
|
40 |
-for |
|
41 |
-of |
|
42 |
-till |
|
43 |
-than |
|
44 |
-a |
|
45 |
-the |
|
46 |
-all |
|
47 |
-any |
|
48 |
-every |
|
49 |
-no |
|
50 |
-other |
|
51 |
-some |
|
52 |
-such |
|
53 |
-that |
|
54 |
-this |
|
55 |
-I |
|
56 |
-he |
|
57 |
-you |
|
58 |
-who |
|
59 |
-and |
|
60 |
-because |
|
61 |
-but |
|
62 |
-or |
|
63 |
-if |
|
64 |
-though |
|
65 |
-while |
|
66 |
-how |
|
67 |
-when |
|
68 |
-where |
|
69 |
-why |
|
70 |
-again |
|
71 |
-ever |
|
72 |
-far |
|
73 |
-forward |
|
74 |
-here |
|
75 |
-near |
|
76 |
-now |
|
77 |
-out |
|
78 |
-still |
|
79 |
-then |
|
80 |
-there |
|
81 |
-together |
|
82 |
-well |
|
83 |
-almost |
|
84 |
-enough |
|
85 |
-even |
|
86 |
-little |
|
87 |
-much |
|
88 |
-not |
|
89 |
-only |
|
90 |
-quite |
|
91 |
-so |
|
92 |
-very |
|
93 |
-tomorrow |
|
94 |
-yesterday |
|
95 |
-north |
|
96 |
-south |
|
97 |
-east |
|
98 |
-west |
|
99 |
-please |
|
100 |
-yes |
101 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,123 +0,0 @@ |
1 |
-''' |
|
2 |
-A game of hangman |
|
3 |
-''' |
|
4 |
- |
|
5 |
-import random |
|
6 |
- |
|
7 |
-def getword(): |
|
8 |
- ''' |
|
9 |
- Choose a word |
|
10 |
- ''' |
|
11 |
- global word |
|
12 |
- global letters |
|
13 |
- global corrguesses |
|
14 |
- global wrong |
|
15 |
- |
|
16 |
- # Create lists of correct and incorrect letters |
|
17 |
- corrguesses = list() |
|
18 |
- wrong = list() |
|
19 |
- |
|
20 |
- # Get a random word from a list file |
|
21 |
- word_file = "dict.txt" |
|
22 |
- dictwords = open(word_file).read().splitlines() |
|
23 |
- word = dictwords[random.randint(0, 99)].lower() |
|
24 |
- |
|
25 |
- # Add unique letters to a set |
|
26 |
- letters = set() |
|
27 |
- for i in word: |
|
28 |
- letters.add(i) |
|
29 |
- |
|
30 |
-def drawman(parts): |
|
31 |
- ''' |
|
32 |
- Draws the appropriate number of body parts |
|
33 |
- ''' |
|
34 |
- # Define the parts of the men |
|
35 |
- man = ["___", "| |","| o", "|-|-", "|| |", "|", "----"] |
|
36 |
- |
|
37 |
- # Draw the appropriate number of parts of the man |
|
38 |
- for i in range(parts): |
|
39 |
- print(man[i]) |
|
40 |
- print() |
|
41 |
- |
|
42 |
-def drawword(word, guesses, wrong): |
|
43 |
- ''' |
|
44 |
- Draws guessed letters, empty spaces, and incorrect guesses |
|
45 |
- ''' |
|
46 |
- # List of spaces to fill |
|
47 |
- spaces = list() |
|
48 |
- # For each letter in the word, either add a blank space or a guessed letter |
|
49 |
- for i in word: |
|
50 |
- if i in guesses: |
|
51 |
- spaces.append(i) |
|
52 |
- else: |
|
53 |
- spaces.append("_") |
|
54 |
- |
|
55 |
- # Print out the spaces and incorrect guesses |
|
56 |
- print(" ".join(spaces)) |
|
57 |
- print(" ".join(wrong)) |
|
58 |
- print() |
|
59 |
- |
|
60 |
-def getguess(): |
|
61 |
- ''' |
|
62 |
- Gets the user's guess |
|
63 |
- ''' |
|
64 |
- # Get the user's input |
|
65 |
- guess = input("Letter? : ").lower() |
|
66 |
- |
|
67 |
- # Check if it is a valid letter |
|
68 |
- if guess not in "abcdefghijklmnopqrstuvwxyz": |
|
69 |
- print("Invalid guess.") |
|
70 |
- getguess() |
|
71 |
- # Check if it has already been guessed |
|
72 |
- elif (guess in corrguesses) or (guess in wrong): |
|
73 |
- print("You've already guessed that!") |
|
74 |
- getguess() |
|
75 |
- # Check if it is in the word |
|
76 |
- elif guess in letters: |
|
77 |
- corrguesses.append(guess) |
|
78 |
- # If not, add to wrong guesses |
|
79 |
- else: |
|
80 |
- wrong.append(guess) |
|
81 |
- |
|
82 |
-def checklose(num): |
|
83 |
- ''' |
|
84 |
- Checks if the user has lost |
|
85 |
- ''' |
|
86 |
- if num > 6: |
|
87 |
- print(f"You lost; the word was '{word}.'") |
|
88 |
- playagain() |
|
89 |
- |
|
90 |
-def checkwin(): |
|
91 |
- ''' |
|
92 |
- Check if the player has won |
|
93 |
- ''' |
|
94 |
- # Check if the number of correct guesses equals unique letters |
|
95 |
- if len(letters) == len(corrguesses): |
|
96 |
- print("Congratulations! You have won.") |
|
97 |
- playagain() |
|
98 |
- |
|
99 |
-def playagain(): |
|
100 |
- ''' |
|
101 |
- Ask the user to play again |
|
102 |
- ''' |
|
103 |
- if input("Play again? Y/N: ").lower() == "y": |
|
104 |
- print() # Draw a blank line |
|
105 |
- gameloop() # Initialize the game loop |
|
106 |
- else: |
|
107 |
- quit() |
|
108 |
- |
|
109 |
-def gameloop(): |
|
110 |
- ''' |
|
111 |
- The main game loop |
|
112 |
- ''' |
|
113 |
- print("H A N G M A N\nHayden Walker, 5 Aug/19") |
|
114 |
- getword() |
|
115 |
- |
|
116 |
- while True: |
|
117 |
- drawman(len(wrong)) |
|
118 |
- drawword(word, corrguesses, wrong) |
|
119 |
- checklose(len(wrong)) |
|
120 |
- checkwin() |
|
121 |
- getguess() |
|
122 |
- |
|
123 |
-gameloop() # Initialize the game loop |