1.要安装的库
按住win+r输入cmd 回车确定
再输入 pip install pygame 下载pygame
2.源码
import pygame
import sys
import random
# 设置窗口
pygame.init()
time_clock = pygame.time.Clock()
screen = pygame.display.set_mode((900, 900))
pygame.display.set_caption('双人对战井字棋')
# 颜色
black = [0, 0, 0]
white = [255, 255, 255]
red = [255, 0, 0]
blue = [0, 0, 255]
# 下棋坐标
chess_pos = []
chess_pos1 = []
# 场上每个格子是否有棋
lattice = [0, 0, 0,
0, 0, 0,
0, 0, 0]
# 轮哪一方下棋
play_chess = 0
first = 0
# 赢的项
win_term = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
# 循环
while True:
# 按键判断
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# 画