Python五子棋的小程序
代码是在开源中国上看到的,源代码网址: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五子棋的小程序的更多相关文章
- 【Python精华】100个Python练手小程序
		100个Python练手小程序,学习python的很好的资料,覆盖了python中的每一部分,可以边学习边练习,更容易掌握python. [程序1] 题目:有1.2.3.4个数字,能组成多少个互不相同 ... 
- 整理了适合新手的20个Python练手小程序
		100个Python练手小程序,学习python的很好的资料,覆盖了python中的每一部分,可以边学习边练习,更容易掌握python. 本文附带基础视频教程:私信回复[基础]就可以获取的 [程序1] ... 
- 利用python实现微信小程序游戏跳一跳详细教程
		利用python实现微信小程序游戏跳一跳详细教程 1 先安装python 然后再安装pip <a href="http://newmiracle.cn/wp-content/uploa ... 
- 微信小程序开发:python+sanic 实现小程序登录注册
		开发微信小程序时,接入小程序的授权登录可以快速实现用户注册登录的步骤,是快速建立用户体系的重要一步.这篇文章将介绍 python + sanic + 微信小程序实现用户快速注册登录全栈方案. 微信小程 ... 
- Python实现微信小程序支付功能
		由于最近自己在做小程序的支付,就在这里简单介绍一下讲一下用python做小程序支付这个流程.当然在进行开发之前还是建议读一下具体的流程,清楚支付的过程. 1.支付交互流程 当然具体的参数配置可以参考官 ... 
- Python - 文件分发小程序
		一.概述 该小程序实现从源端到目标端的文件一键拷贝,源端和目标段都在一台电脑上面,只是目录不同而已 二.参数文件说明 1. settings.txt的说明 a. 通过配置settings.txt,填源 ... 
- Python 发送微信小程序的模板消息
		在小程序的开发过程中,会存在模板消息的发送,具体文档见 这里,模板消息的发送是和语言无关的,这里将简要写一下怎么用 Python 给用户发送模板消息. 通过文档可以知道,发送的时候,需要使用小 ... 
- Python编写购物小程序
		购物车要求: 用户名和密码存放于文件中 启动程序后,先登录,登录成功则让用户输入工资,然后打印商品列表,失败则重新登录,超过三次则退出程序 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够 ... 
- Python 实现微信小程序的用户登录
		小程序可以通过官方提供的登录能力来获取用户身份的标示,具体文档可以参考 这里,通过流程时序可以看到,对于需要和前端配合的服务端开发,主要实现的就是通过小程序提供的 code 换取用户的 openid ... 
随机推荐
- 配置好solr搜索引擎服务器后java后台如何将商品信息导入索引库
			首先,在配置文件目录中添加solr 服务器的bean 配置文件 solr服务器的url可以写在配置文件中: url地址其实就是我们网页可以访问的solr地址: 然后我们写 service packag ... 
- 搭建JavaWeb应用开发环境
			下载和安装Tomcat服务器 下载Tomcat安装程序包:http://tomcat.apache.org/,下载一个zip版本,解压到本地即完成了Tomcat的安装. 测试是否安装成功:进入Tomc ... 
- bzoj 1179 [Apio2009]Atm 缩点+最短路
			[Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 4290 Solved: 1893[Submit][Status][Dis ... 
- Leetcode:52. N-QueensII
			Description Follow up for N-Queens problem. Now, instead outputting board configurations, return the ... 
- Java面试知识总结三
			1.SpringMVC在项目中的应用? 1)service层,项目的业务逻辑层,一般先定义一个接口,在写一个实现类,实现所有的接口方法.service的实现类中要加注解@Service(用于标注业务层 ... 
- 用reduce实现简单的pipe
			function pipe(src, ...fns){ return fns.reduce(function(fn1, fn2){ return fn2(fn1) }, src); } undefin ... 
- 【TYVJ】P1039 忠诚2
			[算法]线段树 [注意]修改或查询区间时,若区间能包含某棵子树就立即返回,否则线段树就失去了意义. #include<cstdio> #include<algorithm> u ... 
- Spring总结以及在面试中的一些问题(山东数漫江湖)
			1.谈谈你对spring IOC和DI的理解,它们有什么区别? IoC Inverse of Control 反转控制的概念,就是将原本在程序中手动创建UserService对象的控制权,交由Spri ... 
- Winform Socket通信
			Socket相关概念[端口] 在Internet上有很多这样的主机,这些主机一般运行了多个服务软件,同时提供几种服务.每种服务都打开一个Socket,并绑定到一个端口上,不同的端口对应于不同的服务(应 ... 
- js 的function为什么可以添加属性
			(1) function person(){ this.name = 'Tom'; } (2) function person(){} person.name = 'Tom'; (3) functio ... 
