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 ...
随机推荐
- 简述JavaScript的类与对象
JavaScript语言是动态类型的语言,基于对象并由事件驱动.用面向对象的思想来看,它也有类的概念.JavaScript 没有class关键字,就是用function来实现. 1. 实现方式及变量/ ...
- POSIX.2 正则表达式
By francis_hao Oct 1,2017 这里的正则表达式主要是指扩展正则,也就是egrep(grep -e)用到的正则表达式. 字符 含义 类别说明 | 分割分支,正则表达式会去 ...
- ACE中UDP通信
转载于:http://www.cnblogs.com/TianFang/archive/2006/12/07/585205.html udp是一种无连接的协议,提供无连接不可靠的服务. 在ace中,通 ...
- Mybatis批量更新详解
转:http://www.cnblogs.com/winkey4986/p/3915151.html Mybatis批量更新 批量操作就不进行赘述了.减少服务器与数据库之间的交互.网上有很多关于批量插 ...
- kubernetes--应用程序健康检查
版权声明:本文属于原创,欢迎转载,转载请保留出处:http://blog.csdn.net/liyingke112 http://blog.csdn.net/liyingke112/article/d ...
- spring boot 在IDEA控制台中打印彩色日志
只需要在application.properties中加入 spring.output.ansi.enabled=ALWAYS 即可
- Apache 文件服务器
1.安装apache服务器yum install httpd 2.启动httpd服务service httpd start 3.查看httpd服务器的版本httpd -v 4.修改访问端口和文件路径, ...
- log4net 按照日期备份日志
配置: <logger name="Log.All"> <level value="INFO" /> <appender- ...
- Different Integers(牛客多校第一场+莫队做法)
题目链接:https://www.nowcoder.com/acm/contest/139/J 题目: 题意:给你n个数,q次查询,对于每次查询得l,r,求1~l和r~n元素得种类. 莫队思路:1.将 ...
- HTML JS文字闪烁实现(项目top.htm分析)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- saved from ur ...