代码是在开源中国上看到的,源代码网址:http://www.oschina.net/code/snippet_2365439_48010

需要安装graphics模块,下载地址:http://mcsp.wartburg.edu/zelle/python/graphics.py 保存到C:\Python27\Lib\site-packages 路径中的版本号改成你用的
from graphics import *
from math import *
def gobangwin():
win=GraphWin("this is a gobang game",400,400) #ÖÆ×÷21x21µÄÆåÅÌ
win.setBackground("yellow")
i1=0 while i1<401:
l=Line(Point(i1,0),Point(i1,400))
l.draw(win)
i1=i1+20
i2=0 while i2<401:
l=Line(Point(0,i2),Point(400,i2))
l.draw(win)
i2=i2+20
return win def main():
win = gobangwin() list1 = []
list2 = []
list3 = [] change = 0
g = 0
m=0
n=0 while g == 0: if change%2 == 1:
p1 = win.getMouse()
if not ((round((p1.getX()+10)/20),round((p1.getY()+10)/20)) in list3): a1 = round((p1.getX()+10)/20)
b1 = round((p1.getY()+10)/20)
list1.append((a1,b1))
list3.append((a1,b1)) piece = Circle(Point(20*a1,20*b1),8) #´´½¨Æå×Ó
piece.setFill('white')
piece.draw(win)
for m in range(21): #ÅжÏÊäÓ®
for n in range(21): if n<17 and (m,n) in list1 and (m,n+1) in list1 and (m,n+2) in list1 and (m,n+3) in list1 and (m,n+4) in list1 :
message = Text(Point(100,100),"white win.")
message.draw(win)
g = 1 #Åжϰ×ÆåÊúÐÐ
elif m<17 and (m,n) in list1 and (m+1,n) in list1 and (m+2,n) in list1 and (m+3,n) in list1 and (m+4,n) in list1 :
message = Text(Point(100,100),"white win.")
message.draw(win)
g = 1 #Åжϰ×ÆåºáÐÐ
elif m<17 and n<17 and (m,n) in list1 and (m+1,n+1) in list1 and (m+2,n+2) in list1 and (m+3,n+3) in list1 and (m+4,n+4) in list1 :
message = Text(Point(100,100),"white win.")
message.draw(win)
g = 1 #Åжϰ×ÆåбÐÐ
elif m<17 and n>3 and (m,n) in list1 and (m+1,n-1) in list1 and (m+2,n-2) in list1 and (m+3,n-3) in list1 and (m+4,n-4) in list1 :
message = Text(Point(100,100),"white win.")
message.draw(win)
g = 1 #Åжϰ×ÆåбÐÐ
else: change = change+1 #»»ºÚÆå×ß else:
p2 = win.getMouse()
if not ((round((p2.getX()+10)/20),round((p2.getY()+10)/20)) in list3): a2 = round((p2.getX()+10)/20)
b2 = round((p2.getY()+10)/20)
list2.append((a2,b2))
list3.append((a2,b2)) piece = Circle(Point(20*a2,20*b2),8)
piece.setFill('black')
piece.draw(win)
for m in range(21):
for n in range(21): if n<17 and (m,n) in list2 and (m,n+1) in list2 and (m,n+2) in list2 and (m,n+3) in list2 and (m,n+4) in list2 :
message = Text(Point(100,100),"black win.")
message.draw(win)
g = 1 #ÅжϺÚÆåÊúÐÐ
elif m<17 and (m,n) in list2 and (m+1,n) in list2 and (m+2,n) in list2 and (m+3,n) in list2 and (m+4,n) in list2 :
message = Text(Point(100,100),"black win.")
message.draw(win)
g = 1 #ÅжϺÚÆåºáÐÐ
elif m<17 and n<17 and (m,n) in list2 and (m+1,n+1) in list2 and (m+2,n+2) in list2 and (m+3,n+3) in list2 and (m+4,n+4) in list2 :
message = Text(Point(100,100),"black win.")
message.draw(win)
g = 1 #ÅжϺÚÆåбÐÐ
elif m<17 and n>3 and (m,n) in list2 and (m+1,n-1) in list2 and (m+2,n-2) in list2 and (m+3,n-3) in list2 and (m+4,n-4) in list2 :
message = Text(Point(100,100),"black win.")
message.draw(win)
g = 1 #ÅжϺÚÆåбÐÐ
else: change = change+1 #»»°×Æå×ß message = Text(Point(100,120),"Click anywhere to quit.")
message.draw(win)
win.getMouse()
win.close() main()

最新文章

  1. Mosquitto pub/sub服务实现代码浅析-主体框架
  2. 如何执行字符串的PHP代码
  3. VS2015 Apache Cordova第一个Android和IOS应用
  4. HTML5 javascript CSS3 jQuery Mobile一些好用的网站
  5. iOS:BitCode的介绍
  6. 【HDOJ】3732 Ahui Writes Word
  7. Webstorm10.0.3破解程序及汉化包下载、Webstorm配置入门指南
  8. CEF中文教程(google chrome浏览器控件) -- Windows下编译Chromium
  9. DL动态载入框架技术文档
  10. html表单 2017-03-10PM
  11. springboot~集成测试里的redis
  12. RabbitMQ学习笔记(二) 工作队列
  13. synchronized 是可重入锁吗?为什么?
  14. NetworkStream介绍说明
  15. Codeforces1073E Segment Sum 【数位DP】
  16. Python数据分析Numpy库方法简介(一)
  17. 改善Python程序的条条建议
  18. js把文本字符串转换为文件并下载
  19. WordPress数据库及各表结构分析
  20. redis集群redis-cloud搭建

热门文章

  1. 【HASH】【UVA 10125】 Sumset
  2. 图片上传(方法一:jquery.upload.js)
  3. 【Android开发】范例1-绘制Android的机器人
  4. ImageNet: what is top-1 and top-5 error rate?
  5. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A
  6. [转载][mysql]mysql字符集干货
  7. sql service (case when then else end ..... group by)
  8. Spring Boot 配置定时任务
  9. 多种方法过Codeforces Round #270的A题(奇偶法、打表法和Miller_Rabin(这个方法才是重点))
  10. js中三种定义变量 const, var, let 的区别