# width、height已经给出
# 长/宽的三分之一,为一个格子的长宽
single = width/3
# 表示九个格子
rect = [0]*9
rect[0] = pygame.draw.rect(screen,(255,228,181),((0,0),(single,single)),width=1)
rect[1] = pygame.draw.rect(screen,(255,228,181),((single,0),(single,single)),width=1)
rect[2] = pygame.draw.rect(screen,(255,228,181),((single*2,0),(single,single)),width=1)
rect[3] = pygame.draw.rect(screen,(255,228,181),((0,single),(single,single)),width=1)
rect[4] = pygame.draw.rect(screen,(255,228,181),((single,single),(single,single)),width=1)
rect[5] = pygame.draw.rect(screen,(255,228,181),((single*2,single),(single,single)),width=1)
rect[6] = pygame.draw.rect(screen,(255,228,181),((0,single*2),(single,00)),width=1)
rect[7] = pygame.draw.rect(screen,(255,228,181),((single,single*2),(single,single)),width=1)
rect[8] = pygame.draw.rect(screen,(255,228,181),((single*2,800),(single,single)),width=1)
当格子被占用,我们需要显示一个X或者O,初步想法是在rect上渲染一个图像(如果懒得找就直接文字处理成矩形了),所以这样就涉及到了两个矩形的嵌套,我另外写了一个类。
到此这篇关于pygame实现井字棋之第一步绘制九宫格的文章就介绍到这了,更多相关pygame绘制九宫格内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!