Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3648156
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: 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()

阅读(668) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~