Orodha ya maudhui:

Mchezo wa Toe wa Tic Tic Tac: Hatua 4
Mchezo wa Toe wa Tic Tic Tac: Hatua 4

Video: Mchezo wa Toe wa Tic Tic Tac: Hatua 4

Video: Mchezo wa Toe wa Tic Tic Tac: Hatua 4
Video: ЛЕДИБАГ ПРОТИВ СТРАШНОЙ УЧИЛКИ 3D! У Хлои и Адриана СВИДАНИЕ?! 2024, Novemba
Anonim
Python Tic Tac Toe Mchezo
Python Tic Tac Toe Mchezo

chatu tic tac toe mchezo

mchezo huu umetengenezwa kwa chatu hiyo ni lugha ya kompyuta

nimetumia mhariri wa chatu kuitwa: pycharm unaweza pia kutumia mhariri wa msimbo wa chatu wa kawaida pia

Hatua ya 1: Ingiza

Ingiza
Ingiza

kutoka kwa kuingiza tkinter *

Hatua ya 2: Mizizi

Mzizi
Mzizi

mzizi = Tk ()

kichwa cha kichwa ("3T TIC TAC TOE") # Kichwa

maandishi = Kuingia (mzizi, fonti = ("ds-digital", 15)) maandishi.pack (kujaza = X, padx = 5, pady = 5, ipadx = 5, ipady = 5) # Nakala

bodi = ["-", "-", "-", "-", "-", "-", "-", "-", "-"] # Bodi

Hatua ya 3: Kazi Baada ya Kuweka Katika Mhariri Inaonyesha Maonyo Bonyeza Warrnigs na Uipe Assambel Yote

# Kazi

mchezaji = "X" button = stop_game = Uongo stop_game_tie = Uongo

def Turn (): # Uchapishaji Zima maandishi delete (0, END) text.insert (0, "{} 'S TURN".format (player))

def Exit (): root.destroy () exit ()

def Game_Over (): # Chech ikiwa mchezo umeisha Check_Winner ()

ikiwa stop_game == Kweli: Hplayer () text.delete (0, END) text.insert (0, "'{}' WINNER".format (player))

kingine: Check_Tie ()

ikiwa stop_game_tie == Kweli: text.delete (0, END) text.insert (0, "TIE MATCH")

def Check_Winner (): # Angalia ikiwa kuna mshindi wa kimataifa stop_game

row_1 = bodi [0] == bodi [1] == bodi [2]! = "-" row_2 = bodi [3] == bodi [4] == bodi [5]! = "-" row_3 = bodi [6] == bodi [7] == bodi [8]! = "-" ikiwa row_1 au row_2 au row_3: stop_game = True

column_1 = bodi [0] == bodi [3] == bodi [6]! = "-" column_2 = bodi [1] == bodi [4] == bodi [7]! = "-" column_3 = bodi [2] == bodi [5] == bodi [8]! = "-" ikiwa safu_1 au safu_2 au safu_3: stop_game = Kweli

diagonal_1 = bodi [0] == bodi [4] == bodi [8]! = "-" diagonal_2 = bodi [2] == bodi [4] == bodi [6]! = "-" ikiwa diagonal_1 au diagonal_2: stop_game = Kweli

def Check_Tie (): # Angalia ikiwa ni mechi inayolingana ya kimataifa stop_game_tie

ikiwa "-" sio kwenye bodi: stop_game_tie = Kweli

def Hplayer (): # Kusimamia Badilisha mchezaji wa ulimwengu

ikiwa mchezaji == "X": mchezaji = "O"

mwingine: mchezaji = "X"

def Add_Text (pos, play): # Ongeza Nakala kifungo cha ulimwengu

ikiwa pos sio kwenye kifungo na stop_game == Uongo na stop_game_tie == Uongo na pos! = 9: Geuza ()

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

kifungo. tumia (pos) Hplayer () Turn () Game_Over ()

Hatua ya 4: Nambari ya Mwisho Itatoa Mwonekano wa Mwisho?

Nambari ya Mwisho Itatoa Mwonekano wa Mwisho?
Nambari ya Mwisho Itatoa Mwonekano wa Mwisho?
Nambari ya Mwisho Itatoa Mwonekano wa Mwisho?
Nambari ya Mwisho Itatoa Mwonekano wa Mwisho?

# GRID

def New_Match (): # Kitufe kipya cha Mechi Kazi ya bodi ya kimataifa mchezaji wa kimataifa kifungo cha kimataifa stop_game kimataifa stop_game_tie

kifungo_1.configure (text = "") button_2.configure (text = "") button_3.configure (text = "") button_4.configure (text = "") button_5.configure (text = "") button_6.configure (text = "") button_7.configure (text = "") button_8.configure (text = "") button_9.configure (text = "") board = ["-", "-", "-", "-", "-", "-", "-", "-", "-"] player = "X" button = stop_game = Uongo stop_game_tie = Uongo wa Uongo ()

# Vifungo

Pinduka ()

fremu = fremu (mzizi) fremu. pakiti (upande = TOP, nanga = NW)

fremu1 = fremu (fremu) fremu1 pakiti ()

kifungo_1 = Kifungo (fremu1, maandishi = "", upana = 8, urefu = 3, amri = lambda: Add_Text (0, mchezaji), bg = 'pink') button_1.pack (side = LEFT)

kifungo_2 = Kifungo (fremu1, maandishi = "", upana = 8, urefu = 3, amri = lambda: Ongeza_Text (1, kichezaji), bg = 'pink') kifungo_2.pack (side = LEFT)

kifungo_3 = Kifungo (fremu1, maandishi = "", upana = 8, urefu = 3, amri = lambda: Ongeza_Text (2, kichezaji), bg = 'pink') button_3.pack (side = LEFT)

fremu2 = fremu (fremu) fremu2.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 = Button (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)

fremu3 = fremu (fremu) fremu3.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 = 'machungwa') button_9.pack (side = LEFT)

fremu4 = fremu (fremu) fremu4.pack ()

button_clear = Button (frame4, text = "MECHI MPYA", width = 13, height = 3, command = lambda: New_Match (), bg = 'violet', foreground = 'red') button_clear.pack (side = LEFT)

exit_button = Button (frame4, text = "EXIT", width = 12, height = 3, command = lambda: Exit (), bg = 'green', foreground = 'orange') exit_button.pack (side = LEFT)

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

mzizi. kitanzi ()

Ilipendekeza: