代码是在开源中国上看到的,源代码网址: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. CSS设计一个三列布局的页面

    探讨这种布局是因为最近对话框组件以及信息系统B/S界面布局的需要.无论是什么,我们在写CSS之前首先引入reset.css,我使用的是淘宝的reset. 01 /* 02 KISSY CSS Rese ...

  2. JavaScript关键字return的用法

    return 语句从当前函数退出,并从那个函数返回一个值. 语法: 1 return[()[expression][]]; 可选项 expression 参数是要从函数返回的值.如果省略,则该函数不返 ...

  3. Spring面试,IoC和AOP的理解(转)

    spring 的优点?1.降低了组件之间的耦合性 ,实现了软件各层之间的解耦 2.可以使用容易提供的众多服务,如事务管理,消息服务等 3.容器提供单例模式支持 4.容器提供了AOP技术,利用它很容易实 ...

  4. 牛客328B Rabbit的工作(1)

    传送门:https://ac.nowcoder.com/acm/contest/328/B 题意:给你n和k,和一个长度为n的字符串,字符串中的0表示休息,1表示工作,连续工作会损耗连续的体力值,从1 ...

  5. [python]爬站点

    #!/usr/bin/python 2 import urllib 3 import urllib2 4 import re 5 import os 6 7 dirs = ['js','img','p ...

  6. idea出现:error:java: Target level '1.7' is incompatible with source level '1.8'.解决办法

    当我们开始使用idea的时候,编译jsp程序我们有可能出现编译错误,然而我们的代码又没有什么问题. 解决方法一:我们开始的时候可以通过修改java compiler来解决这样的问题,点击file菜单- ...

  7. HDFS fs 基本命令

    https://hadoop.apache.org/docs/r2.7.1/hadoop-project-dist/hadoop-common/FileSystemShell.html#Overvie ...

  8. 【BZOJ1272】Gate Of Babylon [Lucas][组合数][逆元]

    Gate Of Babylon Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description Input ...

  9. 【Atcoder】CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning

    [题意]给定只含小写字母的字符串,要求分割成若干段使段内字母重组顺序后能得到回文串,求最少分割段数.n<=2*10^5 [算法]DP [题解]关键在于快速判断一个字符子串是否合法,容易发现合法仅 ...

  10. Creating a new dynamic form project, business modeling.

    The domain logic is like there are a bunch of objects, as well as a lot of configurations, according ...