返回顶部

收藏

五子棋

更多
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

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2017-12-05 12:31:27配置文件备份 by wubai
  2. 2017-12-05 09:35:25python 学习,使用类模拟购物车代码 by 阿明娃儿
  3. 2017-12-04 16:38:15Python有道字典 by jack.chen
  4. 2017-12-03 15:08:33九九乘法表 by 蟋蟀MM
  5. 2017-12-02 15:13:05python验证文件是否可读可写 by 张宋付
  6. 2017-12-02 10:00:23python ftplib模块制作ftp客户端 by wubai
  7. 2017-12-01 17:02:31Python使用剪切板代码 by wubai
  8. 2017-12-01 09:28:31python使用sqlite3的简单代码 by 西国の海妖
  9. 2017-12-01 09:16:27python邮件发送 by jack.chen
  10. 2017-11-30 15:41:33# 根据比例求角度 by wubai
  11. 2017-12-06 09:23:38五子棋 by jack.chen
相关聚客文章
  1. 小码哥 发表 2017-11-07 08:00:25 Python中的时间处理大总结
  2. 小码哥 发表 2017-11-07 08:19:22 如何快速爬取B站全站视频信息
  3. Gavin 发表 2017-11-06 10:01:37 Python批量给云主机配置安全组
  4. Gavin 发表 2017-11-06 10:06:40 如何使用pdb工具来调试python脚本?
  5. 博主 发表 2017-11-05 04:08:13 C语言实现的Python扩展模块
  6. 博主 发表 2017-11-04 14:40:16 Python 3 极简教程 之 基本数据类型
  7. zhu329599788@126 发表 2017-10-18 09:48:23 打印杨辉三角(python版)
  8. 小码哥 发表 2017-11-04 05:45:55 如何通过Python/Shell对HTTP服务状态的监控?
  9. techug 发表 2017-11-02 03:36:46 用Python复制文件的九种方法
  10. techug 发表 2017-11-03 03:46:27 python奇技淫巧
  11. gonwan 发表 2016-01-11 12:52:41 Coroutines in Python
  12. Charles 发表 2016-12-24 12:25:13 在 CentOS 6.8 上安装 Python 2.7

发表评论