Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@TQuinlivan
Created October 29, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TQuinlivan/9179b22ac029e866ff06 to your computer and use it in GitHub Desktop.
Save TQuinlivan/9179b22ac029e866ff06 to your computer and use it in GitHub Desktop.
# Fallout Hacking Game by Torin Quinlivan
import random
word_dict = []
password = ''
guesses = 4
def match(str1, str2):
letters_match = 0
for i in range(len(str1)):
if str1[i] == str2[i]:
letters_match += 1
return letters_match
with open('enable1.txt') as f:
word_list = f.read().splitlines()
for word in word_list:
if len(word) >= 4 and len(word) <= 15:
word_dict.append(word)
print('Welcome to the Fallout Hacking game by Torin Quinlivan.')
while True:
difficulty = int(input("Difficulty (1-5)? "))
if difficulty == 1:
word_length = random.randint(4, 5)
number_of_words = random.randint(5, 7)
break
elif difficulty == 2:
word_length = random.randint(5, 8)
number_of_words = random.randint(7, 9)
break
elif difficulty == 3:
word_length = random.randint(7, 10)
number_of_words = random.randint(9, 11)
break
elif difficulty == 4:
word_length = random.randint(10, 13)
number_of_words = random.randint(11, 13)
break
else:
word_length = random.randint(13, 15)
number_of_words = random.randint(13, 15)
break
random.shuffle(word_dict)
i = 0
while password == '':
if len(word_dict[i]) == word_length:
password = word_dict[i]
i += 1
print_list = [password]
while len(print_list) < number_of_words:
if len(word_dict[i]) == word_length:
print_list.append(word_dict[i])
i += 1
random.shuffle(print_list)
new_list = map(lambda x:x.upper(), print_list)
print("\n".join(new_list))
while guesses > 0:
guess_word = input("Guess ({} left)? ".format(guesses))
if guess_word in print_list:
matches = match(guess_word, password)
print('{}/{} correct'.format(matches, len(password)))
if matches < len(password):
guesses -= 1
else:
print('You win!')
break
else:
print("Not Valid.")
else:
print('You lose.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment