Mundarija:
- 1 -qadam: Import
- 2 -qadam: Ildiz
- 3 -qadam: Tahrirlovchiga qo'ygandan so'ng vazifasi ogohlantirishlarni ko'rsatadi Warrnigs -ni bosing va Assambel -ga hamma narsani bering
- 4 -qadam: Yakuniy kod oxirgi ko'rinishga ega bo'ladimi?
Video: Python Tic Tac Toe o'yini: 4 qadam
2024 Muallif: John Day | [email protected]. Oxirgi o'zgartirilgan: 2024-01-30 13:22
python tic tac toe o'yini
Bu o'yin kompyuter tili bo'lgan pythonda qilingan
Men pytharm deb nomlangan python muharriridan foydalandim, siz oddiy python kod muharriridan ham foydalanishingiz mumkin
1 -qadam: Import
tkinter importidan *
2 -qadam: Ildiz
ildiz = Tk ()
root.title ("3T TIC TAC TOE") # Sarlavha
text = Kirish (ildiz, shrift = ("ds-raqamli", 15)) text.pack (to'ldirish = X, padx = 5, pady = 5, ipadx = 5, ipady = 5) # Matn
taxta = ["-", "-", "-", "-", "-", "-", "-", "-", "-"] # taxta
3 -qadam: Tahrirlovchiga qo'ygandan so'ng vazifasi ogohlantirishlarni ko'rsatadi Warrnigs -ni bosing va Assambel -ga hamma narsani bering
# Funktsiyalar
player = "X" tugmasi = stop_game = Noto'g'ri stop_game_tie = Yolg'on
def Turn (): # Chop etish Text.delete (0, END) text.insert (0, "{} 'S TURN". format (pleer))
def Exit (): root.destroy () exit ()
def Game_Over (): # Chex, agar o'yin tugasa Check_Winner ()
if stop_game == True: Hplayer () text.delete (0, END) text.insert (0, "'{}' WINNER". format (o'yinchi))
boshqa: Check_Tie ()
if stop_game_tie == To'g'ri: text.delete (0, END) text.insert (0, "TIE MATCH")
def Check_Winner (): # Global stop_game g'olibi borligini tekshiring
qator_1 = taxta [0] == taxta [1] == taxta [2]! = "-" qator_2 = taxta [3] == taxta [4] == taxta [5]! = »-" qator_3 = taxta [6] == taxta [7] == taxta [8]! = "-" agar qator_1 yoki qator_2 yoki qator_3 bo'lsa: stop_ o'yin = To'g'ri
ustun_1 = taxta [0] == taxta [3] == taxta [6]! = "-" ustun_2 = taxta [1] == taxta [4] == taxta [7]! = »-" ustun_3 = taxta [2] == taxta [5] == taxta [8]! = "-" agar ustun_1 yoki ustun_2 yoki ustun_3: stop_ o'yini = To'g'ri
diagonal_1 = taxta [0] == taxta [4] == taxta [8]! = "-" diagonal_2 = taxta [2] == taxta [4] == taxta [6]! = "-" bo'lsa diagonal_1 yoki diagonal_2: stop_game = To'g'ri
def Check_Tie (): # Uning global stop_game_tie tengligini tekshiring
agar bortda "-" bo'lmasa: stop_game_tie = To'g'ri
def Hplayer (): # Boshqarish Turn global o'yinchi
agar o'yinchi == "X": o'yinchi = "O"
boshqa: o'yinchi = "X"
def Add_Text (pos, play): # Matn qo'shish global tugmasi
Agar pos tugmachasida bo'lmasa va stop_game == False va stop_game_tie == False va pos! = 9: Turn ()
def_buttons [pos].configure (text = play) doska [pos] = pleer
button.append (pos) Hplayer () Turn () Game_Over ()
4 -qadam: Yakuniy kod oxirgi ko'rinishga ega bo'ladimi?
# GRID
def New_Match (): # Yangi Match tugmachasi global boshqaruv paneli global o'yinchi global tugmasi global stop_ o'yin global stop_ o'yin_tie
button_1.configure (text = "") button_2.configure (text = "") button_3.configure (text = "") button_4.configure (text = "") button_5.configure (text = "") button_6.configure (matn = "") button_7.configure (text = "") button_8.configure (text = "") button_9.configure (text = "") board = ["-", "-", "-", "-", "-", "-", "-", "-", "-"] o'yinchi = "X" tugmasi = stop_game = Yolg'on stop_game_tie = Noto'g'ri burilish ()
# Tugmalar
Burilish ()
ramka = Frame (root) frame.pack (yon = TOP, langar = NW)
frame1 = Frame (ramka) frame1.pack ()
button_1 = Tugma (ramka1, matn = "", kenglik = 8, balandlik = 3, buyruq = lambda: Add_Text (0, o'yinchi), bg = 'pushti') button_1.pack (yon = LEFT)
button_2 = Tugma (ramka1, matn = "", kenglik = 8, balandlik = 3, buyruq = lambda: Add_Text (1, o'yinchi), bg = 'pushti') button_2.pack (yon = LEFT)
button_3 = Tugma (ramka1, matn = "", kenglik = 8, balandlik = 3, buyruq = lambda: Add_Text (2, o'yinchi), bg = 'pushti') button_3.pack (yon = LEFT)
frame2 = Frame (ramka) frame2.pack ()
button_4 = Button (frame2, text = "", width = 8, height = 3, command = lambda: Add_Text (3, player), bg = 'blue') button_4.pack (side = LEFT)
button_5 = Tugma (frame2, text = "", width = 8, height = 3, command = lambda: Add_Text (4, player), bg = 'blue') button_5.pack (side = LEFT)
button_6 = Button (frame2, text = "", width = 8, height = 3, command = lambda: Add_Text (5, player), bg = 'blue') button_6.pack (side = LEFT)
frame3 = Frame (ramka) frame3.pack ()
button_7 = Button (frame3, text = "", width = 8, height = 3, command = lambda: Add_Text (6, player), bg = 'orange') button_7.pack (side = LEFT)
button_8 = Button (frame3, text = "", width = 8, height = 3, command = lambda: Add_Text (7, player), bg = 'orange') button_8.pack (side = LEFT)
button_9 = Button (frame3, text = "", width = 8, height = 3, command = lambda: Add_Text (8, player), bg = 'orange') button_9.pack (side = LEFT)
frame4 = Frame (ramka) frame4.pack ()
button_clear = Tugma (frame4, text = "NEW MATCH", width = 13, height = 3, command = lambda: New_Match (), bg = 'violet', foreground = 'red') button_clear.pack (yon = SOL)
exit_button = Tugma (frame4, text = "EXIT", width = 12, height = 3, command = lambda: Exit (), bg = 'green', foreground = 'orange') exit_button.pack (side = LEFT)
def_buttons = [tugma_1, tugma_2, tugma_3, tugma_4, tugma_5, tugma_6, tugma_7, tugma_8, tugma_9]
root.mainloop ()
Tavsiya:
Arduino Touch Tic Tac Toe o'yini: 6 qadam (rasmlar bilan)
Arduino Touch Tic Tac Toe o'yini: Aziz do'stlar, Arduino -ning boshqa darsligiga xush kelibsiz! Ushbu batafsil qo'llanmada biz Arduino Tic Tac Toe o'yinini qurmoqchimiz. Ko'rib turganingizdek, biz sensorli ekranni ishlatamiz va biz kompyuterga qarshi o'ynaymiz. Tic Tac Toe kabi oddiy o'yin - bu
DIY Arduino Tic Toc Toe o'yini: 6 qadam (rasmlar bilan)
DIY Arduino Tic Toc Toe o'yini: Tic Tac Toe o'yini - bu ikki kishilik klassik o'yin. Agar siz bolalar, oila va do'stlar bilan o'ynasangiz, bu qiziqarli bo'ladi. Bu erda men qanday qilib Arduino Uno, Push tugmalari va pikselli LEDlar yordamida Tic Tac Toe o'yinini yasashni ko'rsatdim. Bu Arduino 4 dan 4 gacha bo'lgan Tic Tac Toe -ga asoslangan
Tic Tac Toe: 12 qadam
Tic Tac Toe: Bugun biz TinkerCad -da Arduino yordamida Tic Tac Toe o'yinini o'tkazamiz. Biz juda ko'p oddiy komponentlardan foydalanamiz va ularning barchasini bog'lash uchun koddan foydalanamiz. Bularning barchasini birlashtiradigan ushbu sxemaning asosiy qismi - bu kod. Bu dastur
Microbit Tic Tac Toe o'yini: 4 qadam (rasmlar bilan)
Microbit Tic Tac Toe O'yini: Ushbu loyiha uchun mening hamkasbim - @descartez va men mikrobitlarning radio funksiyasidan foydalangan holda ajoyib tac toe o'yini yaratdik. Agar siz ilgari mikrobitlar haqida eshitmagan bo'lsangiz, ular bolalarga dasturlashni o'rgatish uchun mo'ljallangan ajoyib mikrokontroller. Ular
Arduino bilan boshqariladigan interaktiv Tic-Tac Toe o'yini: 6 qadam
Arduino bilan boshqariladigan interaktiv Tic-Tac-Toe o'yini: Jismoniy Tic-Tac-Toe loyihasining maqsadi-taniqli o'yinni jismoniy sohaga ko'chirish. Dastlab, o'yinni ikkita o'yinchi qog'ozga - "X" va "O" belgilarini navbat bilan qo'yish orqali o'ynaydi. Bizning fikrimiz futbolchilarning xatti -harakatlarini tekshirish edi