İçindekiler:

Python Tic Tac Toe Oyunu: 4 Adım
Python Tic Tac Toe Oyunu: 4 Adım

Video: Python Tic Tac Toe Oyunu: 4 Adım

Video: Python Tic Tac Toe Oyunu: 4 Adım
Video: How to build TIC TAC TOE game? - Python PyQT5 2024, Temmuz
Anonim
Python Tic Tac Toe Oyunu
Python Tic Tac Toe Oyunu

piton tic tac toe oyunu

bu oyun bir bilgisayar dili olan python'da yapılmıştır

pycharm adında bir python düzenleyici kullandım, ayrıca normal python kod düzenleyicisini de kullanabilirsiniz

1. Adım: İçe aktarın

İçe aktarmak
İçe aktarmak

tkinter import'dan *

2. Adım: Kök

Kök
Kök

kök = Tk()

root.title(" 3T TIC TAC TOE") # Başlık

text = Entry(root, font=("ds-digital", 15)) text.pack(fill=X, padx=5, pady=5, ipadx=5, ipady=5) # Metin

tahta = ["-", "-", "-", "-", "-", "-", "-", "-", "-"] # Pano

Adım 3: Editöre Yerleştirdikten Sonra İşlev Uyarıları Gösteriyor Uyarıları Tıklayın ve Tümünü Assambel'e Verin

# Fonksiyonlar

oyuncu = "X" düğmesi = stop_game = Yanlış stop_game_tie = Yanlış

def Turn(): # Yazdırma Turn text.delete(0, END) text.insert(0, "{}'S TURN".format(player))

def Exit(): root.destroy() çıkış()

def Game_Over(): # Oyunun bitip bitmediğini kontrol edin Check_Winner()

if stop_game == True: Hplayer() text.delete(0, END) text.insert(0, "'{}' KAZANAN".format(player))

başka: Check_Tie()

if stop_game_tie == Doğru: text.delete(0, END) text.insert(0, "TIE MATCH")

def Check_Winner(): # Bir kazanan olup olmadığını kontrol edin stop_game

row_1 = tahta[0] == tahta[1] == tahta[2] != "-" satır_2 = tahta[3] == tahta[4] == tahta[5] != "-" satır_3 = tahta[6] == tahta[7] == tahta[8] != "-" eğer satır_1 veya satır_2 veya satır_3: stop_game = True

sütun_1 = pano[0] == pano[3] == pano[6] != "-" sütun_2 = pano[1] == pano[4] == pano[7] != "-" column_3 = pano[2] == tahta[5] == tahta[8] != "-" sütun_1 veya sütun_2 veya sütun_3 ise: stop_game = Doğru

diyagonal_1 = tahta[0] == tahta[4] == tahta[8] != "-" diyagonal_2 = tahta[2] == tahta[4] == tahta[6] != diyagonal_1 veya diyagonal_2 ise "-": stop_game = Doğru

def Check_Tie(): # Bir kravat eşleşmesi olup olmadığını kontrol edin stop_game_tie

"-" panoda değilse: stop_game_tie = Doğru

def Hplayer(): # Turn küresel oyuncuyu yönetme

oyuncu == "X" ise: oyuncu = "O"

başka: oyuncu = "X"

def Add_Text(kon, oynat): # Metin Ekle global düğmesi

pos butonun içinde değilse ve stop_game == False ve stop_game_tie == False ve pos != 9: Turn()

def_buttons[pos].configure(text=play) board[pos] = oyuncu

button.append(konum) Hplayer() Turn() Game_Over()

Adım 4: Son Kod Son Bir Bakış Verecek mi?

Son Kod Son Bir Bakış Verecek mi?
Son Kod Son Bir Bakış Verecek mi?
Son Kod Son Bir Bakış Verecek mi?
Son Kod Son Bir Bakış Verecek mi?

# KAFES

def New_Match(): # New Match Button Function global board global player global button global stop_game global stop_game_tie

button_1.configure(text="") button_2.configure(text="") button_3.configure(text="") button_4.configure(text="") button_5.configure(text="") button_6.configure(metin ="") button_7.configure(text="") button_8.configure(text="") button_9.configure(text="") pano = ["-", "-", "-", "-", "-", "-", "-", "-", "-"] oyuncu = "X" düğmesi = stop_game = Yanlış stop_game_tie = Yanlış Dönüş()

# Düğmeler

Dönüş()

çerçeve = Çerçeve(kök) çerçeve.pack(yan=ÜST, çapa=NW)

çerçeve1 = Çerçeve(çerçeve) çerçeve1.pack()

button_1 = Düğme(çerçeve1, metin="", genişlik=8, yükseklik=3, komut=lambda: Add_Text(0, oyuncu), bg = 'pembe') button_1.pack(yan=SOL)

button_2 = Düğme(çerçeve1, metin="", genişlik=8, yükseklik=3, komut=lambda: Add_Text(1, oyuncu), bg = 'pembe') button_2.pack(yan=SOL)

button_3 = Button(frame1, text="", command=lambda: Add_Text(2, player), bg = 'pembe') button_3.pack(yan=SOL)

çerçeve2 = Çerçeve(çerçeve) çerçeve2.pack()

button_4 = Button(frame2, text="", genişlik=8, yükseklik=3, komut=lambda: Add_Text(3, oyuncu), bg = 'mavi') button_4.pack(yan=SOL)

button_5 = Button(frame2, text="", genişlik=8, yükseklik=3, komut=lambda: Add_Text(4, oyuncu), bg = 'mavi') button_5.pack(yan=SOL)

button_6 = Düğme(çerçeve2, metin="", genişlik=8, yükseklik=3, komut=lambda: Add_Text(5, oyuncu), bg = 'mavi') button_6.pack(yan=SOL)

çerçeve3 = Çerçeve(çerçeve) çerçeve3.pack()

button_7 = Button(frame3, text="", genişlik=8, yükseklik=3, komut=lambda: Add_Text(6, oyuncu), bg = 'turuncu') button_7.pack(yan=SOL)

button_8 = Button(frame3, text="", genişlik=8, yükseklik=3, komut=lambda: Add_Text(7, oyuncu), bg = 'turuncu') button_8.pack(yan=SOL)

button_9 = Button(frame3, text="", genişlik=8, yükseklik=3, komut=lambda: Add_Text(8, oyuncu), bg = 'turuncu') button_9.pack(yan=SOL)

çerçeve4 = Çerçeve(çerçeve) çerçeve4.pack()

button_clear = Button(frame4, metin="YENİ MAÇ", genişlik=13, yükseklik=3, komut=lambda: New_Match(), bg = 'mor', ön plan = 'kırmızı') button_clear.pack(yan=SOL)

exit_button = Düğme(frame4, metin="ÇIKIŞ", genişlik=12, yükseklik=3, komut=lambda: Çıkış(), bg = 'yeşil', ön plan = 'turuncu') exit_button.pack(yan=SOL)

def_buttons = [button_1, button_2, button_3, button_4, button_5, button_6, button_7, button_8, button_9]

root.mainloop()

Önerilen: