分类: Python/Ruby
2022-11-30 17:40:44
from graphics import *
from time import sleep
class goChess:
def __init__(self, x, y, color=1):
self.color = "black" if color==0 else "white"
self.x,self.y = x,y
self.circle = Circle(Point(0,0),0)
def draw(self):
self.circle = Circle(Point(self.x,self.y),0.4)
self.circle.setFill(self.color)
self.circle.draw(win)
def undraw(self):
self.circle.undraw()
def showBoard():
for i in range(18):
for j in range(18):
k = 外汇跟单gendan5.comRectangle(Point(i+1,j+1),Point(i+2,j+2))
k.draw(win)
k = Rectangle(Point(0.92,0.88),Point(19.1,19.08))
k.draw(win)
k.setWidth(2)
for i in range(3):
for j in range(3):
p = Circle(Point(i*6+4,j*6+4),0.1)
p.draw(win)
p.setFill("black")
def runGame():
global chess
chess = []
coord = [(4,4),(16,16),(4,16),(16,4),(14,17),(6,3),(3,3),(4,2),(3,6),(9,3),
(4,9),(15,17),(14,16),(16,14),(10,16),(14,4),(17,9),(17,11),(17,6),
(3,14),(3,12),(3,17),(4,17),(3,16),(3,18),(2,18),(4,18),(3,13),
(4,12),(17,4),(8,16),(6,5)]
for i,go in enumerate(coord):
t = goChess(go[0],go[1],i%2)
t.draw()
sleep(1)
chess.append(t)
def delAll():
global chess
for go in chess:
go.undraw()
def main():
global win,chess
win = GraphWin("围棋",640,480)
win.setCoords(0,0,640/24,480/24)
showBoard()
win.getMouse()
runGame()
win.getMouse()
delAll()
win.getMouse()
win.close()
if __name__ == "__main__":
main()