Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement simple tic-tac-toe chess Mini Game with python

Shulou Source: shulou.com Published: 2022-05-31 19:10:01 09月21日 Update

This article mainly explains "python how to achieve simple tic-tac-toe Mini Game". The content in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve simple tic-tac-toe-chess Mini Game with python".

Window

Omnipotent windows, implementation windows can be simply modified to use:

From tkinter import * root = Tk () # window name root.title ("Han Gang") f1=Frame (root) f1.pack () w1 = Canvas (F1, width=580,height=580,background='lightcyan') # create a canvas, set the size and background color w1.pack () root.mainloop ()

Draw a chessboard

# draw the chessboard for i in range (0,4): w1.create_line (I * 180 + 20,560) w1.create_line (20,180 + 20560, I * 180 + 20)

Draw horizontal and vertical lines, four horizontal lines and four vertical lines to generate nine grids. Can also draw two horizontal and two vertical, closer to the shape of the well character. Just draw fewer lines, for example:

For i in range (1,3): w1.create_line (I * 180 + 20,20,560) w1.create_line (20,180 + 20,560, I * 180 + 20)

Num = 0 # record the number of clicks, which is used to determine which figure to draw after clicking A = np.full ((3,3), 0) # graphic algorithm for recording each location

After each click, we have to draw pictures and determine whether we meet the conditions for winning.

Setting function

Def dawn (event): global W1 global num, A for i in range (0,3): for j in range (0,3): if 20 + j * 180 < event.y and event.y

Tags: Messages hints zigzag location graphics Mini Game circles situation box condition chessboard learning Han Han Sanzi code content name italics vertical bar analysis Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple MySQL macOS Shulou Technology