Basit bir Adam Asmaca Oyunu

CruellHacker

Yeni üye
19 May 2018
36
0
Gotham
Merhaba arkadaşlar python ile yaptığım basit bir adam asmaca oyunu kelimeler ve açıklamalar ingilizce fakat kelimeleri türkçeleri ile uygun harfli kelimelerle değiştirip kullanabilirsiniz.






import random


# Introduction section printed by hang_man function

def hang_man():
print("*"*24)
print("** Welcome to Hangman **")
print("*"*24)

# get_word function have words list and this function select random vocab from words short but useful for using in the other functions.

def get_word():
words=["apple","banana","cherry","succesful","smart","telephone","rıdıculous","trousers","tshırt","bottle","fantastıc","python","glass","mouse","laptop","pıllow","function","developer","applıcatıon","headphones","serıes","calculus","physıc","healthy","notebook"]
return random.choice(words)

#play_game function is main part of game all of the condition and rules in this function also we use here get_word funtion to define the variable(word).
def play_game():
word = get_word()
available_letters = ["a","b","c","d","e","f","g","h","ı","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
letters_guessed= []
tries = len(word)+5
guessed = False

# When guessed equal false and tries greater than zero ,loop will not break.

print("I am looking for some word and the word contains ",len(word)," letters long.")
print("_ "*len(word))
print("You have " + str(tries)+ " tries left")
print(available_letters)

while guessed == False and tries > 0 :

# We got a input from player and lower function turned to lowercase even if, the the input is uppercase.
guess = input("Please enter your guess : ").lower()


# When lenght of guess equal the 1 , enter the loop
if len(guess) == 1 :

if guess not in available_letters :
tries -=1
print("Please enter the valid letter.")
print("You have "+str(tries)+" tries left,")
print(available_letters)
letters_guessed.append(guess)

elif guess in available_letters :

if guess not in letters_guessed :

if guess not in word :
tries -= 1
print("Upps, The word not contains that letter. :( ")
print("You have "+str(tries)+" tries left.")
available_letters.remove(guess)
print(available_letters)
letters_guessed.append(guess)

elif guess in word :
tries -=1
print("Good guess, you know true letter.")
print("You have "+str(tries)+" tries left.")
available_letters.remove(guess)
letters_guessed.append(guess)
print(available_letters)
else :
print("Unexpected ERROR")

elif guess in letters_guessed :
tries -=1
print("You have already guessed that letter.")
print(available_letters)

# This part of else block is not necessary but ı wrote it for not be empty :)
else:
print("Unexpected ERROR.")
else:
print("Unexpected ERROR.")

elif len(guess) == len(word):
if guess == word :
print("Congratulations, You guessed the world")
guessed = True
elif guess != word :
tries -=1
print("Upss,That guess is not true")
print("You have "+str(tries)+" tries left.")

else :
tries -=1
print("Upps,the lenght of the guess is not same as the lenght of the word :( ")
print("You have "+str(tries)+" tries left.")

# Status part main lobby of the game beacuse we define the status and we print the scheme of game like (_ _ _)
status = " "
if guessed == False:
for letter in word:
if letter in letters_guessed:
status += letter
else:
status += "_ "
print(status)

if status == word:
print("Congratulations, You found the Word !! ")
guessed = True
elif tries == 0:
print("You have run out all the tries you could not find the word :(( ")
guessed = True

# Finally, we operate 2 functions here and game is ready . :)

hang_man()
play_game()
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.