Δημοσιεύτηκε: 22 Οκτ 2009, 22:13
Μια έκδοση της Κρεμάλας (Hangman) που έφτιαξα
κανονικά
http://en.wikipedia.org/wiki/Hangman_(game)
μόλις ο παίκτης μαντέψει ένα γράμμα του εμφανίζονται και όλα τα ίδια γράμματα της λέξης ( αν υπάρχουν )
σε αυτή την εκδοχή όμως ... τα πράγματα είναι πιο δύσκολα
Enjoy
κανονικά
μόλις ο παίκτης μαντέψει ένα γράμμα του εμφανίζονται και όλα τα ίδια γράμματα της λέξης ( αν υπάρχουν )
σε αυτή την εκδοχή όμως ... τα πράγματα είναι πιο δύσκολα
Enjoy
- Κώδικας: Επιλογή όλων
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Copyright : 2009 Giannis fysakis <giannisfs at gmail dot com >
#This is free software. You may redistribute copies of it under the terms of
#the GNU General Public License <http://www.gnu.org/licenses/GPL.html>
#There is NO WARRANTY, to the extent permitted by law.
#Notes : Typically in a hangman game as soun as the player founds at least one letter the game
# exposes all similar letters ... Well this version ... makes it harder to guess :P
from sys import exit
from random import choice
def dots(a="*"): print a*50
def Hang(status):
if status ==0:
print """
_____
|
|
|
|
"""
if status == 1:
print """
_____
| 0
| |\\
|
|
"""
if status == 2:
print """
_____
| 0
| /||\\
|
|
"""
if status == 3:
print """
_____
| 0
| /||\\
| /
|
"""
if status == 4:
print """
_____
| 0
| /||\\
| /\\
|
"""
if status == 5:
print """
_____
| 0 /
| /||\\ /
| /\\ y
| \\/\///\\
"""
if status == 6:
print """
_____
| 0
| /||\\w
| /\\WW
|wWwwW
WwWwWW
"""
def mask (original,masked):
msk = []
try:
for i,v in enumerate( masked):
if v in original:
msk.append("_")
elif v not in original:
msk.append(original[i])
except IndexError:
pass
return msk
def main ():
dots()
word = choice(["kitchen","mountain","system", "amplify","tomato"])
word = word.lower()
bkp = word
MaxTries=len(word) * 5
Completed= False
lost =0
found =0
Try=0
wrongs=0
dots()
print "\n\tWelcome to The HAngmAn Game \t\t\n"
dots()
Hang(wrongs)
dots()
print "You Have %d attempts\n" % MaxTries
while not Completed :
guess = raw_input("Give a letter\n")
Try +=1
print "You have done %d attempts till now !!! \n " % Try
if guess == word :
dots()
dots()
print " TILT TILT WELL DONE YOU FIND IT BRAVO BRAVO ! !!"
dots()
dots()
Completed = True
break
if word.count(guess) > 1 and guess != '':
dots()
print "\t \n HINT>> %s is %d times in the word <<HINT " % (guess , word.count(guess))
dots()
while guess in """`~!@#$%^&*()_+|-=\{}[]:";'<>?,.// \n """ or guess =="":
guess = raw_input("\nPlease Give Just a letter -->: ")
Try +=1
dots(a="_")
print "Attempts Still Count !!! you have Tried: %d Times till now" % Try
if Try == MaxTries -1 :
Completed = True
break
guess = " "
if guess not in word:
print "Unfortunately %s is not in the Word :( \n " % guess
lost +=1
wrongs += 1
dots()
Hang(wrongs)
dots()
if guess in bkp and bkp.count(guess)<len(word)/2:
found+=1
pos = bkp.find(guess)
bkp =bkp.replace(guess,'$',1)
hidden = mask(word,bkp)
print "You have lost %d and Found %d " % (lost, found)
print "You have done %d attempts till now !!! \n " % Try
print hidden ,"\n"
if "_" not in hidden:
Completed =True
dots("$")
print "\n Gongratulation you Won!! \n at the %d attempt " % Try
print " Bye bye\n"
dots("$")
break
exit
if wrongs >5 or Try == MaxTries -1:
Completed =True
dots()
print "\t\tBye bye\n"
dots()
print """\nThe Score is
%d Attempts %d lost %d Found
""" % ( Try , lost ,found)
dots()
exit
else:
print ";)"
if __name__ == '__main__':
main()