Skip to content

Commit 42b545c

Browse files
authored
main file
0 parents  commit 42b545c

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

hangman.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import linecache
2+
import random
3+
import time
4+
5+
# base
6+
word = ''
7+
used = []
8+
correct = 0
9+
fullWord = []
10+
# stats
11+
attempts = 12
12+
13+
14+
def info():
15+
print('---< commands >---')
16+
print('enter any letter as your guess')
17+
print('enter !guess to guess the whole word')
18+
print('enter !used at any time during the game to see the letters you already used')
19+
print('\n')
20+
21+
22+
def stats(): # stats for end of game
23+
wrongLetter()
24+
print('=-=-=-=-=-=-=-=-=-=-=-=-=-=')
25+
print(f'word: {word[:-1]}\nlives left: {attempts}\nwrong letters: {wrongGuess}\nused letters: {len(used)}')
26+
time.sleep(1)
27+
print('\ncheck out my github: https://github.com/cqb13')
28+
print('=-=-=-=-=-=-=-=-=-=-=-=-=-=')
29+
time.sleep(20)
30+
exit()
31+
32+
33+
def wrongLetter(): # finds the amount of wrong letter I think
34+
global wrongGuess
35+
num = 0
36+
wrongGuess = (len(used))
37+
for i in used:
38+
if used[num] in word:
39+
wrongGuess -= 1
40+
else:
41+
pass
42+
num += 1
43+
44+
45+
def options():
46+
global fullWord, word, correct, attempts
47+
word = linecache.getline('words', random.randrange(0, 8749))
48+
wordlength = len(word)
49+
while wordlength != 0: # creates the word visual
50+
fullWord.append('_')
51+
wordlength -= 1
52+
fullWord.pop() # fix's weird glitch with word visual
53+
print(fullWord)
54+
print(f'word length: {len(word) - 1}') # idk whats wrong with this, but it needs to be like this
55+
print(f'lives: {attempts}')
56+
57+
while attempts > 0:
58+
option = input('enter a guess')
59+
60+
if option == '!used':
61+
print(f'used letters: {used}')
62+
elif option == '!guess': # option to guess the full word
63+
print('if you get the word wrong you will lose.\npress y to continue '
64+
'or x to skip')
65+
option = input('y to continue, or any key to skip')
66+
word = word[:-1] # something wrong with word, idk anymore
67+
if option == 'y': # makes sure that you actually want to do it
68+
option = input('enter word')
69+
if option == word: # checks if the word is right
70+
print('you won')
71+
stats()
72+
else:
73+
print('you lost')
74+
stats()
75+
else:
76+
print('skipped')
77+
else:
78+
if len(option) > 1: # checks that you only entered 1 letter
79+
print('enter !full to guess the word')
80+
else:
81+
letterUsed = False # I don't fucking know, it does something I think
82+
num = 0
83+
for i in used: # checks if letter has been used before
84+
if option == used[num]:
85+
print(f'letter {option} has already been used')
86+
print('enter !used to see all used letters')
87+
letterUsed = True
88+
pass
89+
else:
90+
pass
91+
num += 1
92+
93+
num = 0
94+
for i in word: # adds letter to its spot in hidden word
95+
if letterUsed is True:
96+
pass
97+
elif option == word[num]: # weird word symbol thing
98+
temp = list(fullWord)
99+
temp[num] = option
100+
fullWord = ''.join(temp)
101+
correct += 1
102+
else:
103+
pass
104+
num += 1
105+
106+
if option not in word and option not in used: # checks if it should take away a life
107+
attempts -= 1
108+
else:
109+
pass
110+
111+
print(fullWord)
112+
113+
if letterUsed is True: # adds letter to used list
114+
pass
115+
else: # adds every letter to list
116+
used.append(option)
117+
if correct == len(word) - 1: # checks if you won
118+
print('you won')
119+
stats()
120+
elif attempts <= 0: # checks if you have too many wrong letters
121+
print('you lost')
122+
stats()
123+
else:
124+
pass
125+
126+
print(f'lives: {attempts}')
127+
print('=-=-=-=-=-=-=-=-=-=-=-=-=-=')
128+
129+
130+
print('---< welcome to hangman >---')
131+
print('---< made by: cqb13 >---')
132+
print('\n')
133+
time.sleep(1)
134+
info()
135+
time.sleep(1)
136+
options()

0 commit comments

Comments
 (0)