代码是在开源中国上看到的,源代码网址: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()

Python五子棋的小程序的更多相关文章

  1. 【Python精华】100个Python练手小程序

    100个Python练手小程序,学习python的很好的资料,覆盖了python中的每一部分,可以边学习边练习,更容易掌握python. [程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同 ...

  2. 整理了适合新手的20个Python练手小程序

    100个Python练手小程序,学习python的很好的资料,覆盖了python中的每一部分,可以边学习边练习,更容易掌握python. 本文附带基础视频教程:私信回复[基础]就可以获取的 [程序1] ...

  3. 利用python实现微信小程序游戏跳一跳详细教程

    利用python实现微信小程序游戏跳一跳详细教程 1 先安装python 然后再安装pip <a href="http://newmiracle.cn/wp-content/uploa ...

  4. 微信小程序开发:python+sanic 实现小程序登录注册

    开发微信小程序时,接入小程序的授权登录可以快速实现用户注册登录的步骤,是快速建立用户体系的重要一步.这篇文章将介绍 python + sanic + 微信小程序实现用户快速注册登录全栈方案. 微信小程 ...

  5. Python实现微信小程序支付功能

    由于最近自己在做小程序的支付,就在这里简单介绍一下讲一下用python做小程序支付这个流程.当然在进行开发之前还是建议读一下具体的流程,清楚支付的过程. 1.支付交互流程 当然具体的参数配置可以参考官 ...

  6. Python - 文件分发小程序

    一.概述 该小程序实现从源端到目标端的文件一键拷贝,源端和目标段都在一台电脑上面,只是目录不同而已 二.参数文件说明 1. settings.txt的说明 a. 通过配置settings.txt,填源 ...

  7. Python 发送微信小程序的模板消息

    在小程序的开发过程中,会存在模板消息的发送,具体文档见 这里,模板消息的发送是和语言无关的,这里将简要写一下怎么用 Python 给用户发送模板消息.     通过文档可以知道,发送的时候,需要使用小 ...

  8. Python编写购物小程序

    购物车要求: 用户名和密码存放于文件中 启动程序后,先登录,登录成功则让用户输入工资,然后打印商品列表,失败则重新登录,超过三次则退出程序 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够 ...

  9. Python 实现微信小程序的用户登录

    小程序可以通过官方提供的登录能力来获取用户身份的标示,具体文档可以参考 这里,通过流程时序可以看到,对于需要和前端配合的服务端开发,主要实现的就是通过小程序提供的 code 换取用户的 openid ...

随机推荐

  1. linux 小技巧

      http://blog.csdn.net/xianjie0318/article/details/75712990 1.按内存从大到小排列进程:  ps -eo "%C : %p : % ...

  2. jq的each理解

    1种 通过each遍历li 可以获得所有li的内容 <!-- 1种 --> <ul class="one"> <li>11a</li> ...

  3. python升级引发的问题总结

    http://www.cnblogs.com/ajianbeyourself/p/4214398.html http://www.cnblogs.com/hanggegege/p/6993003.ht ...

  4. jq 正则

    if(_each_this_type_name == 'post_num'){ var patrn = /^[a-zA-Z0-9]{3,12}$/; if(!patrn.test(_each_this ...

  5. Web Api Action的筛选

    web Api设置默认路由设置: 这种目标Action方法的选择有以下几轮: 1.针对 HTTP方法 进行筛选 2.针对参数类型,可以做参数约束 3.针对参数数量 另一种路由“api/{control ...

  6. MongoDB入门(3)- MongoDB备份与恢复

    1. 备份 MongoDB提供了备份工具,mongodump.exe,在bin目录下,其用法如下: mongodump.exe -h localhost -d database_name -o d:\ ...

  7. [洛谷P2610] [ZJOI2012]旅游

    洛谷题目链接:[ZJOI2012]旅游 题目描述 到了难得的暑假,为了庆祝小白在数学考试中取得的优异成绩,小蓝决定带小白出去旅游~~ 经过一番抉择,两人决定将T国作为他们的目的地.T国的国土可以用一个 ...

  8. MySQL按天,按周,按月,按时间段统计

    MYSQL函数:DATE_FORMAT 例子: select DATE_FORMAT(create_time,'%Y%m%d') days,count(caseid) count from tc_ca ...

  9. Berland National Library

    题目链接:http://codeforces.com/problemset/problem/567/B 题目描述: Berland National Library has recently been ...

  10. Android中自定义属性attr.xml的格式详解

    1. reference:参考某一资源ID.     (1)属性定义:             <declare-styleable name = "名称">      ...