Created
July 20, 2017 16:59
-
-
Save martyworm/98dabf9c08843fc14aab907b7064ddee to your computer and use it in GitHub Desktop.
Martyworm's hangman in python
This file contains 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
able | |
about | |
account | |
acid | |
across | |
act | |
addition | |
adjustment | |
advertisement | |
after | |
again | |
against | |
agreement | |
air | |
all | |
almost | |
among | |
amount | |
amusement | |
and | |
angle | |
angry | |
animal | |
answer | |
ant | |
any | |
apparatus | |
apple | |
approval | |
arch | |
argument | |
arm | |
army | |
art | |
as | |
at | |
attack | |
attempt | |
attention | |
attraction | |
authority | |
automatic | |
awake | |
baby | |
back | |
bad | |
bag | |
balance | |
ball | |
band | |
base | |
basin | |
basket | |
bath | |
be | |
beautiful | |
because | |
bed | |
bee | |
before | |
behaviour | |
belief | |
bell | |
bent | |
berry | |
between | |
bird | |
birth | |
bit | |
bite | |
bitter | |
black | |
blade | |
blood | |
blow | |
blue | |
board | |
boat | |
body | |
boiling | |
bone | |
book | |
boot | |
bottle | |
box | |
boy | |
brain | |
brake | |
branch | |
brass | |
bread | |
breath | |
brick | |
bridge | |
bright | |
broken | |
brother | |
brown | |
brush | |
bucket | |
building | |
bulb | |
burn | |
burst | |
business | |
but | |
butter | |
button | |
by | |
cake | |
camera | |
canvas | |
card | |
care | |
carriage | |
cart | |
cat | |
cause | |
certain | |
chain | |
chalk | |
chance | |
change | |
cheap | |
cheese | |
chemical | |
chest | |
chief | |
chin | |
church | |
circle | |
clean | |
clear | |
clock | |
cloth | |
cloud | |
coal | |
coat | |
cold | |
collar | |
colour | |
comb | |
come | |
comfort | |
committee | |
common | |
company | |
comparison | |
competition | |
complete | |
complex | |
condition | |
connection | |
conscious | |
control | |
cook | |
copper | |
copy | |
cord | |
cork | |
cotton | |
cough | |
country | |
cover | |
cow | |
crack | |
credit | |
crime | |
cruel | |
crush | |
cry | |
cup | |
cup | |
current | |
curtain | |
curve | |
cushion | |
damage | |
danger | |
dark | |
daughter | |
day | |
dead | |
dear | |
death | |
debt | |
decision | |
deep | |
degree | |
delicate | |
dependent | |
design | |
desire | |
destruction | |
detail | |
development | |
different | |
digestion | |
direction | |
dirty | |
discovery | |
discussion | |
disease | |
disgust | |
distance | |
distribution | |
division | |
do | |
dog | |
door | |
doubt | |
down | |
drain | |
drawer | |
dress | |
drink | |
driving | |
drop | |
dry | |
dust | |
ear | |
early | |
earth | |
east | |
edge | |
education | |
effect | |
egg | |
elastic | |
electric | |
end | |
engine | |
enough | |
equal | |
error | |
even | |
event | |
ever | |
every | |
example | |
exchange | |
existence | |
expansion | |
experience | |
expert | |
eye | |
face | |
fact | |
fall | |
false | |
family | |
far | |
farm | |
fat | |
father | |
fear | |
feather | |
feeble | |
feeling | |
female | |
fertile | |
fiction | |
field | |
fight | |
finger | |
fire | |
first | |
fish | |
fixed | |
flag | |
flame | |
flat | |
flight | |
floor | |
flower | |
fly | |
fold | |
food | |
foolish | |
foot | |
for | |
force | |
fork | |
form | |
forward | |
fowl | |
frame | |
free | |
frequent | |
friend | |
from | |
front | |
fruit | |
full | |
future | |
garden | |
general | |
get | |
girl | |
give | |
glass | |
glove | |
go | |
goat | |
gold | |
good | |
government | |
grain | |
grass | |
great | |
green | |
grey | |
grip | |
group | |
growth | |
guide | |
gun | |
hair | |
hammer | |
hand | |
hanging | |
happy | |
harbour | |
hard | |
harmony | |
hat | |
hate | |
have | |
he | |
head | |
healthy | |
hear | |
hearing | |
heart | |
heat | |
help | |
high | |
history | |
hole | |
hollow | |
hook | |
hope | |
horn | |
horse | |
hospital | |
hour | |
house | |
how | |
humour | |
I | |
ice | |
idea | |
if | |
ill | |
important | |
impulse | |
in | |
increase | |
industry | |
ink | |
insect | |
instrument | |
insurance | |
interest | |
invention | |
iron | |
island | |
jelly | |
jewel | |
join | |
journey | |
judge | |
jump | |
keep | |
kettle | |
key | |
kick | |
kind | |
kiss | |
knee | |
knife | |
knot | |
knowledge | |
land | |
language | |
last | |
late | |
laugh | |
law | |
lead | |
leaf | |
learning | |
leather | |
left | |
leg | |
let | |
letter | |
level | |
library | |
lift | |
light | |
like | |
limit | |
line | |
linen | |
lip | |
liquid | |
list | |
little | |
living | |
lock | |
long | |
look | |
loose | |
loss | |
loud | |
love | |
low | |
machine | |
make | |
male | |
man | |
manager | |
map | |
mark | |
market | |
married | |
mass | |
match | |
material | |
may | |
meal | |
measure | |
meat | |
medical | |
meeting | |
memory | |
metal | |
middle | |
military | |
milk | |
mind | |
mine | |
minute | |
mist | |
mixed | |
money | |
monkey | |
month | |
moon | |
morning | |
mother | |
motion | |
mountain | |
mouth | |
move | |
much | |
muscle | |
music | |
nail | |
name | |
narrow | |
nation | |
natural | |
near | |
necessary | |
neck | |
need | |
needle | |
nerve | |
net | |
new | |
news | |
night | |
no | |
noise | |
normal | |
north | |
nose | |
not | |
note | |
now | |
number | |
nut | |
observation | |
of | |
off | |
offer | |
office | |
oil | |
old | |
on | |
only | |
open | |
operation | |
opinion | |
opposite | |
or | |
orange | |
order | |
organization | |
ornament | |
other | |
out | |
oven | |
over | |
owner | |
page | |
pain | |
paint | |
paper | |
parallel | |
parcel | |
part | |
past | |
paste | |
payment | |
peace | |
pen | |
pencil | |
person | |
physical | |
picture | |
pig | |
pin | |
pipe | |
place | |
plane | |
plant | |
plate | |
play | |
please | |
pleasure | |
plough | |
point | |
poison | |
polish | |
political | |
poor | |
porter | |
position | |
possible | |
pot | |
potato | |
powder | |
power | |
present | |
price | |
prison | |
private | |
probable | |
process | |
produce | |
profit | |
property | |
prose | |
protest | |
public | |
pull | |
pump | |
punishment | |
purpose | |
push | |
put | |
quality | |
question | |
quick | |
quiet | |
quite | |
rail | |
rain | |
range | |
rat | |
rate | |
ray | |
reaction | |
reading | |
ready | |
reason | |
receipt | |
record | |
red | |
regret | |
regular | |
relation | |
religion | |
representative | |
request | |
respect | |
responsible | |
rest | |
reward | |
rhythm | |
rice | |
right | |
ring | |
river | |
road | |
rod | |
roll | |
roof | |
room | |
root | |
rough | |
round | |
rub | |
rule | |
run | |
sad | |
safe | |
sail | |
salt | |
same | |
sand | |
say | |
scale | |
school | |
science | |
scissors | |
screw | |
sea | |
seat | |
second | |
secret | |
secretary | |
see | |
seed | |
seem | |
selection | |
self | |
send | |
sense | |
separate | |
serious | |
servant | |
sex | |
shade | |
shake | |
shame | |
sharp | |
sheep | |
shelf | |
ship | |
shirt | |
shock | |
shoe | |
short | |
shut | |
side | |
sign | |
silk | |
silver | |
simple | |
sister | |
size | |
skin | |
skirt | |
sky | |
sleep | |
slip | |
slope | |
slow | |
small | |
smash | |
smell | |
smile | |
smoke | |
smooth | |
snake | |
sneeze | |
snow | |
so | |
soap | |
society | |
sock | |
soft | |
solid | |
some | |
son | |
song | |
sort | |
sound | |
soup | |
south | |
space | |
spade | |
special | |
sponge | |
spoon | |
spring | |
square | |
stage | |
stamp | |
star | |
start | |
statement | |
station | |
steam | |
steel | |
stem | |
step | |
stick | |
sticky | |
stiff | |
still | |
stitch | |
stocking | |
stomach | |
stone | |
stop | |
store | |
story | |
straight | |
strange | |
street | |
stretch | |
strong | |
structure | |
substance | |
such | |
sudden | |
sugar | |
suggestion | |
summer | |
sun | |
support | |
surprise | |
sweet | |
swim | |
system | |
table | |
tail | |
take | |
talk | |
tall | |
taste | |
tax | |
teaching | |
tendency | |
test | |
than | |
that | |
the | |
then | |
theory | |
there | |
thick | |
thin | |
thing | |
this | |
thought | |
thread | |
throat | |
through | |
through | |
thumb | |
thunder | |
ticket | |
tight | |
till | |
time | |
tin | |
tired | |
to | |
toe | |
together | |
tomorrow | |
tongue | |
tooth | |
top | |
touch | |
town | |
trade | |
train | |
transport | |
tray | |
tree | |
trick | |
trouble | |
trousers | |
true | |
turn | |
twist | |
umbrella | |
under | |
unit | |
up | |
use | |
value | |
verse | |
very | |
vessel | |
view | |
violent | |
voice | |
waiting | |
walk | |
wall | |
war | |
warm | |
wash | |
waste | |
watch | |
water | |
wave | |
wax | |
way | |
weather | |
week | |
weight | |
well | |
west | |
wet | |
wheel | |
when | |
where | |
while | |
whip | |
whistle | |
white | |
who | |
why | |
wide | |
will | |
wind | |
window | |
wine | |
wing | |
winter | |
wire | |
wise | |
with | |
woman | |
wood | |
wool | |
word | |
work | |
worm | |
wound | |
writing | |
wrong | |
year | |
yellow | |
yes | |
yesterday | |
you | |
young | |
Bernhard | |
Breytenbach | |
Android |
This file contains 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
########################################## | |
# prints board state | |
########################################## | |
def hangmanInterface(index): | |
if index==0: | |
clear() | |
print(' _____ ') | |
print(' | | ') | |
print(' O | ') | |
print(' /|\ | ') | |
print(' / \ | ') | |
print(' | ') | |
print(' ________|_') | |
return | |
if index==1: | |
clear() | |
print(' _____ ') | |
print(' | | ') | |
print(' O | ') | |
print(' /|\ | ') | |
print(' / | ') | |
print(' | ') | |
print(' ________|_') | |
return | |
if index==2: | |
clear() | |
print(' _____ ') | |
print(' | | ') | |
print(' O | ') | |
print(' /|\ | ') | |
print(' | ') | |
print(' | ') | |
print(' ________|_') | |
return | |
if index==3: | |
clear() | |
print(' _____ ') | |
print(' | | ') | |
print(' O | ') | |
print(' /| | ') | |
print(' | ') | |
print(' | ') | |
print(' ________|_') | |
return | |
if index==4: | |
clear() | |
print(' _____ ') | |
print(' | | ') | |
print(' O | ') | |
print(' | | ') | |
print(' | ') | |
print(' | ') | |
print(' ________|_') | |
return | |
if index==5: | |
clear() | |
print(' _____ ') | |
print(' | | ') | |
print(' O | ') | |
print(' | ') | |
print(' | ') | |
print(' | ') | |
print(' ________|_') | |
return | |
if index==6: | |
clear() | |
print(' _____ ') | |
print(' | | ') | |
print(' | ') | |
print(' | ') | |
print(' | ') | |
print(' | ') | |
print(' ________|_') | |
return | |
if index==7: | |
clear() | |
print(' _____ ') | |
print(' | ') | |
print(' | ') | |
print(' | ') | |
print(' | ') | |
print(' | ') | |
print(' ________|_') | |
return | |
if index==8: | |
clear() | |
print(' ') | |
print(' | ') | |
print(' | ') | |
print(' | ') | |
print(' | ') | |
print(' | ') | |
print(' ________|_') | |
return | |
if index==9: | |
clear() | |
print(' ') | |
print(' ') | |
print(' ') | |
print(' ') | |
print(' ') | |
print(' ') | |
print(' ________|_') | |
return | |
########################################## | |
########################################## | |
# Aesthetic Functions | |
########################################## | |
def clear(): | |
for i in range(25): | |
print ('\n') | |
######################### | |
def printLines(x): | |
for i in range(x): | |
print("\n") | |
######################### | |
def spacing_fix(tmp): | |
if tmp == 0: | |
tmp = 1 | |
return tmp | |
if tmp == 2: | |
print() | |
tmp = 3 | |
return tmp | |
########################################## |
This file contains 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
import random | |
from hang_aesthetics import * | |
def main(): | |
while True: | |
hangman_word = generate_random() | |
play_game(hangman_word) | |
if play_again() == 2: | |
break | |
############################################ | |
# The game! | |
############################################ | |
def play_game(random_word): | |
clear() | |
guesses = "" | |
tries = 9 | |
while True: | |
winning_number = 0 | |
hangmanInterface(tries) | |
print("WORD:", end="") | |
for char in random_word: | |
if char in guesses: | |
print(" {} ".format(char), end="") | |
else: | |
print(" _ ", end="") | |
winning_number += 1 | |
if win_check(winning_number, tries) == True: | |
break | |
printLines(1) | |
print(" Tried:", end="") | |
for j in range(len(guesses)): | |
print("[{}]".format(guesses[j]), end="") | |
spacing_fix(2) | |
guess = get_guess() | |
guesses += guess | |
printLines(2) | |
if guess not in random_word: | |
tries -= 1 | |
return | |
########################################## | |
########################################## | |
# generates a random word | |
########################################## | |
def generate_random(): | |
#opens the dictionary and initializes a random word | |
with open("dict.txt") as fp: | |
dictwords = [] | |
for line in fp: | |
dictwords.append(line.rstrip("\n")) | |
#makes sure the word is in lower case | |
rand = random.choice(dictwords) | |
randlower = rand.lower() | |
return randlower | |
########################################## | |
########################################## | |
# Checks if the game should restart | |
########################################## | |
def play_again(): | |
print("Play again?") | |
print("1. yes!") | |
print("2. no :(") | |
ans = get_ans() | |
return ans | |
################## | |
def get_ans(): | |
ans1 = input() | |
ans = int(ans1) | |
if ans == 1 or ans == 2: | |
return ans | |
else: | |
print("Please type 1 or 2") | |
get_ans() | |
########################################## | |
########################################## | |
# checks for the win | |
########################################## | |
def win_check(a, b): | |
if a == 0: | |
printLines(2) | |
print("######################") | |
print("# #") | |
print("# W I N N E R #") | |
print("# #") | |
print("######################") | |
return True | |
elif b == 0: | |
printLines(2) | |
print("######################") | |
print("# #") | |
print("# L O S E R #") | |
print("# #") | |
print("######################") | |
return True | |
########################################## | |
########################################## | |
# gets users guess while ensuring only | |
# one alpha, lowercase char is entered | |
########################################## | |
def get_guess(): | |
get = input(" Guess: ") | |
a = get.lower() | |
if len(a) > 1: | |
print("One letter only") | |
get_guess() | |
elif not a.isalpha(): | |
print("One letter only") | |
get_guess() | |
return a | |
########################################## | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment