hab als allererstes kleines Projekt mal ein Hangman in der Konsole angefangen, weiß allerdings grade nicht weiter.Hier mein Code wie er bis jetzt aussieht:
Code: Alles auswählen
import random
class hangman:
def play(self):
counter = 0
fieldnumber= len(wordlist[random.randint(0,2)])
field = []
word = wordlist[random.randint(0,2)]
while counter <= 9:
while fieldnumber > 0:
field.append("_ ")
fieldnumber -= 1
if counter == 1:
print "/-\_"
elif counter == 2:
print " | "
print " | "
print " | "
print "_/-\_"
elif counter == 3:
print " |/ "
print " | "
print " | "
print "_/-\_"
elif counter == 4:
print " ____"
print " |/ "
print " | "
print " | "
print "_/-\_"
elif counter == 5:
print " ____"
print " |/ |"
print " | "
print " | "
print "_/-\_"
elif counter == 6:
print " ____"
print " |/ |"
print " | o "
print " | "
print "_/-\_"
elif counter == 7:
print " ____"
print " |/ |"
print " | o"
print " | 0"
print "_/-\_ "
elif counter == 8:
print " ____"
print " |/ |"
print " | o "
print " | /0\\"
print "_/-\_"
elif counter == 9:
print " ____"
print " |/ |"
print " | o"
print " | /0\\"
print "_/-\/\\"
print field
inp = raw_input("Raten sie einen Buchstaben: ")
if len(inp) != 1:
print "Ungueltige Eingabe!"
else:
if inp in word:
a = word.find(inp)
print a
else:
counter += 1
print "Der Buchstabe ist nicht in dem gesuchten Wort."
wordlist = ["nadelwald", "gitarre", "tastatur"]
game = hangman()
game.play()
Ich weiß nicht wie ich es anstellen soll, dass die richtig geratenen Buchstaben die Unterstriche in der Liste ersetzen. Ich müsste dafür ja rausfinden wie oft und wo der geratene Buchstabe im Wort vorkommt, wie ich das mache konntich aber nirgendwo herausfinden.
Ne andere Frage,die aber nicht so wichtig ist:
Wie kann ich es machen, das die Ausgabe(also das leere Feld und der Galgen),nicht jedes mal neu augegeben wird, sondern die alte ersetzt bzw. erweitert?
Für Kritik am Code bin ich natürlich auch offen.