Advertisement
c0d3dsk1lls

Zeros-n-ones/Tic-Tac-Toe/ CodedSkills.net

Aug 5th, 2022 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 16.43 KB | None | 0 0
  1.  
  2. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  3. ##=======================================================================================================================================================================================##
  4. ##----------------------CODEDSKILLS.NET--------------------------------------------------------------------------------------------------------------------------------------------------##
  5. #---ONES AND ZEROS---#------#---------------------#-----#--------------#====================================================================================================
  6. #---------------#----#------#---------------------#-----#--------------#
  7. from tkinter import *#------#---------------------#-----#--------------#
  8. import random   #----#------#---------------------#-----#--------------#
  9. #---------------#----#------#---------------------#-----#--------------#
  10. #+++++++++++++++#----#------#---------------------#-----#--------------#
  11. #---------------#----#------#---------------------#-----#--------------#
  12. def next_turn(row, column): #---------------------#-----#--------------#
  13.     global player    #------#---------------------#-----#--------------#
  14. #---------------------------#---------------------#-----#--------------#
  15. #+++++++++++++++++++++++++++#---------------------#-----#--------------#
  16. #-------------------------------------------------#-----#--------------#
  17.     if buttons[row][column]["text"] == "" and check_winner() is False: #
  18.         if player == players[0]: #----------#-----#-----#--------------#    
  19. #--------------------------------#----------#-----#-----#
  20. #++++++++++++++++++++++++++++++++#----------#-----#-----#
  21. #--------------------------------#----------#-----#-----#                            
  22.             buttons[row][column]["text"] = player #-----#
  23.             if check_winner() is False:     #-----#-----#
  24.                 player = players[1]         #-----#-----#
  25.                 label.config(text=(players[1]+" turn")) #
  26.             elif check_winner() is True:    #-----#-----#
  27.                 label.config(text=(players[0]+" wins")) #
  28.             elif check_winner()  == "Tie":  #-----#-----#
  29.                 label.config(text=("Tie!")) #-----#-----#
  30.         else:#------------------------------#-----#-----#
  31.             buttons[row][column]["text"] = player #-----#
  32.             if check_winner() is False:     #-----#-----#
  33.                 player = players[0]         #-----#-----#
  34.                 label.config(text=(players[0]+" turn")) #
  35.             elif check_winner() is True:    #-----#-----#
  36.                 label.config(text=(players[1]+" wins")) #
  37.             elif check_winner()  == "Tie":  #-----#-----#
  38.                 label.config(text=("Tie!")) #-----#-----#
  39. #-------------------------------------------#-----#-----#
  40. #++++++++++++++++++++++++++++#--------------#-----#-----#
  41. #----------------------------#--------------#-----#-----#---#----#----------------------------------------------#
  42. def check_winner():#---------#--------------#-----#-----#---#----#----------------------------------------------#                                                                                                                                                            
  43.     for row in range    (3): #--------------#-----#-----#---#----#----------------------------------------------#                                                  
  44.         if  buttons    [row]        [0]["text"] == buttons[row][1]["text"] == buttons[row][2]["text"] != "":    #
  45.             buttons    [row]        [0].config(bg="green")  #----#----------------------------------------------#  
  46.             buttons    [row]        [1].config(bg="green")  #----#
  47.             buttons    [row]        [2].config(bg="green")  #----#
  48.             return            True          #-----#-----#---#----#
  49. #-------------------------------------------#-----#---------#----#
  50. #+++++++++++++++++++++++++++++++++++++++++++#-----#---------#----#
  51. #-------------------------------------------#-----#---------#----#--------------------------------------------------------#
  52.     for column in range (3):#---------------#-----#---------#----#--------------------------------------------------------#
  53.         if  buttons     [0]         [column]["text"] == buttons[1][column]["text"] == buttons[2][column]["text"] != "":   #
  54.             buttons     [0]         [column].config(bg="green")  #--------------------------------------------------------#  
  55.             buttons     [1]         [column].config(bg="green")  #  
  56.             buttons     [2]         [column].config(bg="green")  #  
  57.             return            True          #-----#---------#----#
  58. #-------------------------------------------#-----#---------#----#      
  59. #+++++++++++++++++++++++++++++++++++++++++++#-----#---------#----#
  60. #-------------------------------------------#-----#---------#----#----------------------------------------#                                                                          
  61.     if  buttons         [0]         [0]["text"] == buttons[1][1]["text"] == buttons[2][2]["text"] != "":  #
  62.         buttons         [0]         [0].config(bg="green")  #----#----------------------------------------#                              
  63.         buttons         [1]         [1].config(bg="green")  #----#  
  64.         buttons         [2]         [2].config(bg="green")  #----#
  65.         return                True          #-----#---------#----#
  66. #-------------------------------------------#-----#---------#----#  
  67. #+++++++++++++++++++++++++++++++++++++++++++#-----#---------#----#
  68. #-------------------------------------------#-----#---------#----#----------------------------------------#                                                                              
  69.     elif buttons        [0]         [2]["text"] == buttons[1][1]["text"] == buttons[2][0]["text"] != "":  #
  70.         buttons         [0]         [2].config(bg="green")  #---------------------------------------------#  
  71.         buttons         [1]         [1].config(bg="green")  #
  72.         buttons         [2]         [0].config(bg="green")  #
  73.         return                True                          #
  74. #-------------------------------------------#-----#---------#
  75. #+++++++++++++++++++++++++++++++++++++++++++#-----#---------#
  76. #---------------------------#--------#------------#------#--#
  77.     elif empty_spaces() is False: #--#------------#------#--#
  78.         for row in range(3):#-----#--#------------#------#--#
  79.             for column in range(3):  #------------#------#--#
  80.                 buttons[row][column].config(bg="red") #--#--#
  81.         return "Tie" #----------------------------#------#--#
  82.     else: #-----------------#---------------------#------#--#
  83.         return False #------#---------------------#------#--#
  84. #---------------------------#---------------------#------#--#
  85. #+++++++++++++++++++++++++++#---------------------#------#--#
  86. #------------------- #------#---------------------#------#--#
  87. def empty_spaces():  #------#---------------------#------#--#
  88.     spaces = 9       #------#---------------------#------#--#                                    
  89.     for row        in range(3):#------------------#------#--#
  90.         for column in range(3): #-----------------#------#--#                    
  91.             if buttons    [row][column]["text"] != "":   #--#
  92.                 spaces  -=1 #---------------------#------#--#
  93.     if spaces == 0:  #------#---------------------#------#--#
  94.         return False #------#---------------------#------#--#
  95.     else:            #------#---------------------#------#--#
  96.         return True  #------#---------------------#------#--#
  97. #--------------------#------#---------------------#------#--#  
  98. #++++++++++++++++++++#------#---------------------#------#--#
  99. #--------------------#-------------------#--------#------#--#
  100. def new_game():      #-------------------#--------#------#--#
  101.     global player    #-------------------#--------#------#--#
  102.     player = random.choice (players)     #--------#------#--#
  103.     label.config           (text=player+" turn")  #------#--#
  104.     for row in range       (3):                   #------#--#
  105.         for column in range(3):                   #------#--#
  106.             buttons       [row]  [column].config(text="",#--#
  107.                                                  bg="#000000")#
  108. #-----------------------------------#-------------#-----------#
  109. #+++++++++++++++++++++++++++++++++++#-------------#-----------#
  110. #-----------------------------------#-------------#-----------#
  111. window = Tk()                       #-------------#-----------#
  112. window.title("CodedSkills: Tic-Tac-Toe")          #-----------#
  113. players = ["-1-","-0-"]             #-------------#-----------#
  114. player = random.choice(players)     #-------------#-----------#
  115. buttons = [[0,0,0], #---------------#-------------#-----------#                
  116.            [0,0,0], #---------------#-------------#-----------#                
  117.            [0,0,0]] #---------------#-------------#-----------#                
  118. #-------------------#---------------#-------------#-----------#
  119. #+++++++++++++++++++++++++++++++++++#-------------#-----------#
  120. #-----------------------------------#-------------#-----------#
  121. label = Label(text= player + " turn", font=("consolas",40))   #
  122. label.pack(side="top") #------------#-------------#-----------#
  123. #-----------------------------------#-------------#-----------#
  124. #+++++++++++++++++++++++++++++++++++#-------------#-----------#
  125. #-----------------------------------#-------------#-----------#---------------#
  126. reset_button = Button(text="restart", font=("consolas",20), command=new_game) #
  127. reset_button.pack(side="top") #-----#-------------#-----------#---------------#
  128. #-----------------------------------#-------------#-----------#---------------#
  129. #+++++++++++++++++++++++++++++++++++#-------------#-----------#---------------#
  130. #-----------------------------#-------------------#-----------#---------------#
  131. frame = Frame(window) #-------#-------------------#-----------#---------------#
  132. frame.pack()  #-------#-------#-------------------#-----------#---------------#
  133. #-------------#---------------#-------------------#-----------#---------------#
  134. #+++++++++++++++++++++++++++++#-------------------#-----------#---------------#
  135. #-----------------------------#-------------------#-----------#---------------#----+
  136. for row                             in range(3):  #-----------#---------------#--------+
  137.     for column                      in range(3):  #-----------#---------------#------------+
  138.         buttons[row][column] =      Button(frame, #-----------#---------------#----------------+
  139.                                     text="", #----#-----------#---------------#--------------------+
  140.                                     font=("consolas", 40),    #---------------#----------------+
  141.                                     width=5, #----#-----------#---------------#------------+
  142.                                     height=2,#----#-----------#---------------#--------+
  143.                                     command= lambda row=row,  #---------------#------------+
  144.                                     column=column: next_turn(row,column)) #---#----------------+
  145.         buttons[row][column].grid  (row=row,column=column)    #---------------#--------------------+
  146. window.mainloop() #-------------------------------#-----------#---------------#----------------+
  147. #-----------------#-------------------------------#-----------#---------------#------------+
  148. #-----------------#-------------------------------#-----------#---------------#------------------------------+
  149. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  150. ##=================================================================================================================================================##
  151. ##-------------------------------------------------------------------------------------------------------------------------------------------------##
  152. ##                                                                                                                                                 ##
  153. ##                                                                                        ##   //                                                  ##
  154. ##----+-#########\   ########  -+#######\\-- +##########   #######\\        /#######\\    ##  //     ######---+-##      ##       /#######\\        ##
  155. ##      ##-          ##|--|##    ##-     ##   ##           ##-     ##      ||-----        ## //        ##       ##----+-##      ||-----         +--##
  156. ##      ##           ##|  |##  -+##    +--##  #######      ##       ##  -- \\#######\\    ## \\        ##       ##      ##------\\#######\\-------+##
  157. ##      ##-        +-##|--|##    ##-     ##   ##           ##-     ##         ------||    ##  \\       ##       ##      ##         ------||--------##
  158. ##      #########/   ########  -#######//-  -+##########   #######//       \\######//     ##   \\    ######---+-#####   #####   \\######//------+--##
  159. ##                                                                                                                                                 ##
  160. ##                                                          https://CodedSkills.net                                                                ##
  161. ##-------------------------------------------------------------------------------------------------------------------------------------------------##
  162. ##=================================================================================================================================================##
  163. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  164.  
  165.  
  166. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  167. ##=======================================================================================================================================================================================##
  168. ##---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------##
  169. ##                                                                                                                                                                                       ##
  170. ##           ###       #######\    #######\       #######       ########     ##  ##     ########     ########       #######     ########       ####        ##         /#######\\         ##
  171. ##          #-##            //          //        \   //    =      ##        ##  ##        ##        ##|--|##       ##  //         ##         //  \\       ##        ||-                 ##
  172. ##            ##          ##\\        ##\\           //            ##        ##  ##        ##        ##|  |##       ###\\          ##        //====\\      ##        \\#######\\         ##
  173. ##            ##            //          //          //             ##        ##  ##        ##        ##|--|##       ##  \\         ##       //      \\     ##                 ||         ##
  174. ##       ##########   ########--  ########--       //       =      ##         ####         ##        ########       ##   \\     ########   //        \\    #######   \\######//          ##
  175. ##                                                                                                                                                                                       ##
  176. ##                                                                         https://1337tutorials.net                                                                                     ##
  177. ##---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------##
  178. ##=======================================================================================================================================================================================##
  179. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  180.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement