Python Python ile Adam Asmaca oyunu

Python ile Adam Asmaca oyunu



import random

pics = ["""
   +---+
   |   |
       |
       |
       |
       |
=========""","""
   +---+
   |   |
   O   |
       |
       |
       |
=========""","""
   +---+
   |   |
   O   |
   |   |
       |
       |
=========""","""
   +---+
   |   |
   O   |
  /|   |
       |
       |
=========""","""
   +---+
   |   |
   O   |
  /|\  |
       |
       |
=========""","""
   +---+
   |   |
   O   |
  /|\  |
  /    |
       |
=========""","""
   +---+
   |   |
   O   |
  /|\  |
  / \  |
       |
========="""]

def is_correct_guess(guess, word):
    return guess in word

while True:
    print(("-" * 30) + "\nHangman Game\n" + ("-" * 30))
   
    word = random.choice(["windows", "python", "usb", "klavye", "notebook", "server", "anakart"])
    step = 0
    correct_letters = []
    wrong_letters = []
   
    while True:
        print(pics[step])
       
        for char in word:
            if char in correct_letters:
                print(char, end=" ")
            else:
                print("_", end=" ")
       
        soru = input("\nsoru: ")
       
        if soru == word:
            print("Kazandin!\n\n")
            break
        elif len(soru) == 1:
            if is_correct_guess(soru, word):
                correct_letters.append(soru)
                if set(correct_letters) == set(word):
                    print("Kazandin!\n\n")
                    break
            else:
                wrong_letters.append(soru)
                step += 1
       
        if step >= len(pics):
            print("Kaybettin!\n\n")
            break
       
    if input("Tekrar oyna (e/h): ").lower() != "e":
        break

Leave a Reply

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir