Как скрыть/показать буквы в игре на Python?Python

Программы на Python
Ответить
Anonymous
 Как скрыть/показать буквы в игре на Python?

Сообщение Anonymous »

Я новичок в программировании и в настоящее время пытаюсь создать упрощенную игру «Висельник», используя Python 3. По большей части я знаю, за исключением самой важной части, как скрыть буквы случайного слова, а затем как показать их, если они угаданы. В основном мне просто нужен быстрый ответ. Любая помощь будет принята с благодарностью. Вот мой код (извините, если он длинный, как я уже сказал, я относительно новичок в этом деле, и еще раз спасибо!):

import random

#list of words for game
hangmanWords = ("Halloween","Hockey","Minnesota","Vikings","Twins","Timberwolves","Wild","Playstation","Achievement","Minecraft","Metallica","Portal","Xbox","Guitar")

#randomizes the word chosen for game
index = random.randint(0,len(hangmanWords)-1)

#assigns radomized word to variable
randomWord = hangmanWords[index]

'''
menu function, provides user with choices for game, user chooses via imput
'''
def menu():
print("""
Welcome to Hangman!

Select a difficulty:
1. Easy (9 Misses)
2. Medium (7 Misses)
3. Advanced (5 Misses)

4. Exit Game
""")
selection = int(input("What difficulty do you pick (1-4)?: "))
return selection

'''
the function for easy mode, prints the word chosen by randomizer
asks the player to enter a letter that they guess is in the word
player gets 9 guesses to figure out word, correct guesses don't
count, returns player to main menu when they lose
'''
def easyMode():
wrongGuesses = 0
listOfGuesses = []
print(randomWord)
while(wrongGuesses != 9):
x = input("Enter a letter: ")
if x.lower() in randomWord.lower():
print(x,"is in the word!")
listOfGuesses.append(x)
print("Letters guessed so far: ",listOfGuesses)
print()
else:
print(x,"is not in the word.")
wrongGuesses += 1
print(wrongGuesses, "wrong guesses.")
listOfGuesses.append(x)
print("Letters guessed so far: ",listOfGuesses)
print()

print("You lost the game!")
return x

'''
the function for medium mode, prints the word chosen by randomizer
asks the player to enter a letter that they guess is in the word
player gets 7 guesses to figure out word, correct guesses don't
count, returns player to main menu when they lose
'''
def medium():
wrongGuesses = 0
listOfGuesses = []
print(randomWord)
while(wrongGuesses != 7):
x = input("Enter a letter: ")
if x.lower() in randomWord.lower():
print(x,"is in the word!")
listOfGuesses.append(x)
print("Letters guessed so far: ",listOfGuesses)
print()
else:
print(x,"is not in the word.")
wrongGuesses += 1
print(wrongGuesses, "wrong guesses.")
listOfGuesses.append(x)
print("Letters guessed so far: ",listOfGuesses)
print()

print("You lost the game!")
return x

'''
the function for advanced mode, prints the word chosen by randomizer
asks the player to enter a letter that they guess is in the word
player gets 5 guesses to figure out word, correct guesses don't
count, returns player to main menu when they lose
'''
def advanced():
wrongGuesses = 0
listOfGuesses = []
print(randomWord)
while(wrongGuesses != 5):
x = input("Enter a letter: ")
if x.lower() in randomWord.lower():
print(x,"is in the word!")
listOfGuesses.append(x)
print("Letters guessed so far: ",listOfGuesses)
print()
else:
print(x,"is not in the word.")
wrongGuesses += 1
print(wrongGuesses, "wrong guesses.")
listOfGuesses.append(x)
print("Letters guessed so far: ",listOfGuesses)
print()

print("You lost the game!")
return x

'''
main function, deals with what happens depending on
what the player selected on the menu
'''
def main():
select = menu()
while(select != 4):
if(select == 1):
easyMode()
elif(select == 2):
medium()
elif(select == 3):
advanced()

select = menu()

print("You don't want to play today? :'(")

main()


Подробнее здесь: https://stackoverflow.com/questions/197 ... ython-game
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»