INHOUDSOPGAWE:
- Stap 1: Invoer
- Stap 2: Wortel
- Stap 3: Funksie nadat dit in die redakteur geplaas is. Dit wys waarborge. Klik op die Warrnigs en gee Assambel alles
- Stap 4: Finale kode Dit gee 'n finale kyk?
Video: Python Tic Tac Toe -spel: 4 stappe
2024 Outeur: John Day | [email protected]. Laas verander: 2024-01-30 07:23
spel met python tic tac toe
hierdie speletjie is gemaak in python wat 'n rekenaartaal is
Ek het 'n python -redakteur genaamd: pycharm gebruik, u kan ook 'n normale python -kode -redakteur gebruik
Stap 1: Invoer
vanaf tkinter invoer *
Stap 2: Wortel
root = Tk ()
root.title ("3T TIC TAC TOE") # Titel
text = Entry (root, font = ("ds-digital", 15)) text.pack (fill = X, padx = 5, pady = 5, ipadx = 5, ipady = 5) # Teks
bord = ["-", "-", "-", "-", "-", "-", "-", "-", "-"] # Bord
Stap 3: Funksie nadat dit in die redakteur geplaas is. Dit wys waarborge. Klik op die Warrnigs en gee Assambel alles
# Funksies
speler = "X" -knoppie = stop_spel = Valse stop_game_tie = Onwaar
def Turn (): # Printing Turn text.delete (0, END) text.insert (0, "{} 'S TURN".format (speler))
def Exit (): root.destroy () exit ()
def Game_Over (): # Chech as die spel verby is Check_Winner ()
if stop_game == True: Hplayer () text.delete (0, END) text.insert (0, "'{}' WINNER".format (speler))
anders: Check_Tie ()
if stop_game_tie == Waar: text.delete (0, END) text.insert (0, "TIE MATCH")
def Check_Winner (): # Kyk of daar 'n wêreldwye stopspel is
row_1 = board [0] == board [1] == board [2]! = "-" row_2 = board [3] == board [4] == board [5]! = "-" row_3 = board [6] == bord [7] == bord [8]! = "-" as ry_1 of ry_2 of ry_3: stop_spel = Waar
column_1 = board [0] == board [3] == board [6]! = "-" column_2 = board [1] == board [4] == board [7]! = "-" column_3 = board [2] == board [5] == board [8]! = "-" as column_1 of column_2 of column_3: stop_game = True
diagonal_1 = board [0] == board [4] == board [8]! = "-" diagonal_2 = board [2] == board [4] == board [6]! = "-" if diagonal_1 or diagonal_2: stop_game = Waar
def Check_Tie (): # Kyk of dit 'n gelykop wedstryd is, globale stop_game_tie
as "-" nie aan boord is nie: stop_game_tie = Waar
def Hplayer (): # Bestuur Turn global player
as speler == "X": speler = "O"
anders: speler = "X"
def Add_Text (pos, play): # Voeg globale teksknoppie by
as pos nie in knoppie is nie en stop_game == Onwaar en stop_spel_tie == Onwaar en pos! = 9: Draai ()
def_buttons [pos].configure (text = play) board [pos] = speler
button.append (pos) Hplayer () Turn () Game_Over ()
Stap 4: Finale kode Dit gee 'n finale kyk?
# GRID
def New_Match (): # New Match Button Function globale bord globale speler globale knoppie 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 (teks = "") button_7.configure (text = "") button_8.configure (text = "") button_9.configure (text = "") bord = ["-", "-", "-", "-", "-", "-", "-", "-", "-"] speler = "X" -knoppie = stop_spel = Valse stop_game_tie = Valse draai ()
# Knoppies
Draai ()
raam = raam (wortel) raam. pak (kant = bo, anker = NW)
raam1 = raam (raam) raam1.pak ()
button_1 = Knoppie (raam1, teks = "", breedte = 8, hoogte = 3, opdrag = lambda: Add_Text (0, speler), bg = 'pienk') knoppie_1.pak (kant = LINKS)
button_2 = Knoppie (raam1, teks = "", breedte = 8, hoogte = 3, opdrag = lambda: Add_Text (1, speler), bg = 'pienk') knoppie_2.pak (sy = LINKS)
button_3 = Knoppie (raam1, teks = "", breedte = 8, hoogte = 3, opdrag = lambda: Add_Text (2, speler), bg = 'pienk') button_3.pack (sy = LEFT)
raam2 = raam (raam) raam2.pak ()
button_4 = Knoppie (frame2, text = "", breedte = 8, hoogte = 3, command = lambda: Add_Text (3, speler), bg = 'blou') button_4.pack (sy = LEFT)
button_5 = Knoppie (frame2, text = "", breedte = 8, hoogte = 3, command = lambda: Add_Text (4, speler), bg = 'blou') button_5.pack (sy = LEFT)
button_6 = Knoppie (frame2, text = "", breedte = 8, hoogte = 3, command = lambda: Add_Text (5, speler), bg = 'blou') button_6.pack (sy = LEFT)
raam3 = raam (raam) raam3.pak ()
button_7 = Button (frame3, text = "", width = 8, height = 3, command = lambda: Add_Text (6, player), bg = 'orange') button_7.pack (side = LEFT)
button_8 = Knoppie (frame3, text = "", breedte = 8, hoogte = 3, command = lambda: Add_Text (7, speler), bg = 'oranje') button_8.pack (sy = LEFT)
button_9 = Button (frame3, text = "", width = 8, height = 3, command = lambda: Add_Text (8, player), bg = 'orange') button_9.pack (side = LEFT)
raam4 = raam (raam) raam4.pak ()
button_clear = Knoppie (frame4, text = "NEW MATCH", breedte = 13, hoogte = 3, command = lambda: New_Match (), bg = 'violet', voorgrond = 'rooi') button_clear.pack (sy = LINKS)
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]
root.mainloop ()
Aanbeveel:
Elektroniese Tic-Tac-Toe-speletjie in 'n houtkas: 5 stappe
Elektroniese Tic-Tac-Toe-spel in 'n houtkas: Hallo, ek stel die snaakse Tic-Tac-Toe-speletjie in 'n nuwe uitgawe voor. Ek het op die internet gesoek na soortgelyke projekte, maar die idee hier is uniek
Tic Tac Toe: 12 stappe
Tic Tac Toe: Vandag maak ons 'n Tic Tac Toe -speletjie op TinkerCad met behulp van die Arduino. Ons gaan baie eenvoudige komponente gebruik en die kode gebruik om dit almal saam te bind. Die belangrikste deel van hierdie kring wat dit alles bymekaar bring, is die kode. Hierdie prog
RG LED Tic Tac Toe: 9 stappe
RG LED Tic Tac Toe: RG Tic Tac Toe is 'n klassieke spel wat in verskillende weergawes gemaak kan word. Maar ek het besluit om dit te bou met gewone katode RG LED's van 5 mm as monitor van die resultate, sodat sodra die betrokke skakelaar gemanipuleer is, die LED die resultaat in kleur rooi of groen in
GPIO Tic Tac Toe: 5 stappe
GPIO Tic Tac Toe: Probablemente, para el hablar latinoamericano el pronunciar el nombre de este sencillo pero muy popular yego puede resultar bastante confuso, esto debido a la gran cantidad de nombres que se le atribuyen a este, entre los cuales cabe: " Gato
Tic Tac Toe (3 in 'n ry): 10 stappe (met foto's)
Tic Tac Toe (3 in 'n ry): Hierdie projek is 'n elektroniese weergawe van die klassieke Tic-Tac-Toe potlood & papier 2 speler spel. Die hart van die stroombaan is die mikrobeheerder PIC 16F627A van Microchip. Ek het die aflaai -skakel vir 'n rekenaarbord -PDF en die HEX -kode vir