Python Gobang Applet

Source: Internet
Author: User
Tags gety

Code is seen in open source China, source code URL: http://www.oschina.net/code/snippet_2365439_48010

The graphics module needs to be installed: The version number saved to the C:\Python27\Lib\site-packages path is changed to your http://mcsp.wartburg.edu/zelle/python/graphics.py.
 fromGraphicsImport* fromMathImport*defGobangwin (): Win=graphwin ("This is a Gobang game", 400,400)#Öæx÷21x21µäæååìWin.setbackground ("Yellow") I1=0 whilei1<401: L=line (Point (i1,0), point (i1,400) ) L.draw (win) I1=i1+20I2=0 whilei2<401: L=line (Point (0,I2), point (400, I2)) L.draw (Win) I2=i2+20returnwindefMain (): Win=Gobangwin () List1=[] List2=[] List3=[] change=0 g=0 M=0 N=0 whileG = =0:ifchange%2 = = 1: P1=Win.getmouse ()if  not((Round ((P1.getx () +10)/20), Round ((P1.gety () +10)/20))inchlist3): 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)#´´½¨æåxóPiece.setfill (' White') Piece.draw (Win) forMinchRange (21):#åð¶ïêäó®                  forNinchRange (21):                                               ifN<17 and(M,n)inchList1 and(m,n+1)inchList1 and(m,n+2)inchList1 and(m,n+3)inchList1 and(m,n+4)inchList1:message= Text (Point (100,100),"White win.") Message.draw (Win) G= 1#Åð¶ï°xæåêúðð                         elifM<17 and(M,n)inchList1 and(M+1,n)inchList1 and(M+2,n)inchList1 and(M+3,n)inchList1 and(M+4,n)inchList1:message= Text (Point (100,100),"White win.") Message.draw (Win) G= 1#Åð¶ï°xæåºáðð                         elifM<17 andN<17 and(M,n)inchList1 and(m+1,n+1)inchList1 and(m+2,n+2)inchList1 and(m+3,n+3)inchList1 and(m+4,n+4)inchList1:message= Text (Point (100,100),"White win.") Message.draw (Win) G= 1#Åð¶ï°xæåð±ðð                         elifM<17 andN>3 and(M,n)inchList1 and(m+1,n-1)inchList1 and(m+2,n-2)inchList1 and(m+3,n-3)inchList1 and(m+4,n-4)inchList1:message= Text (Point (100,100),"White win.") Message.draw (Win) G= 1#Åð¶ï°xæåð±ðð                         Else: Change = change+1#»»ºúæåxß                    Else: P2=Win.getmouse ()if  not((Round ((P2.getx () +10)/20), Round ((P2.gety () +10)/20))inchlist3): 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) forMinchRange (21):                  forNinchRange (21):                                               ifN<17 and(M,n)inchList2 and(m,n+1)inchList2 and(m,n+2)inchList2 and(m,n+3)inchList2 and(m,n+4)inchList2:message= Text (Point (100,100),"Black win.") Message.draw (Win) G= 1#Åð¶ïºúæåêúðð                         elifM<17 and(M,n)inchList2 and(M+1,n)inchList2 and(M+2,n)inchList2 and(M+3,n)inchList2 and(M+4,n)inchList2:message= Text (Point (100,100),"Black win.") Message.draw (Win) G= 1#Åð¶ïºúæåºáðð                         elifM<17 andN<17 and(M,n)inchList2 and(m+1,n+1)inchList2 and(m+2,n+2)inchList2 and(m+3,n+3)inchList2 and(m+4,n+4)inchList2:message= Text (Point (100,100),"Black win.") Message.draw (Win) G= 1#Åð¶ïºúæåð±ðð                         elifM<17 andN>3 and(M,n)inchList2 and(m+1,n-1)inchList2 and(m+2,n-2)inchList2 and(m+3,n-3)inchList2 and(m+4,n-4)inchList2:message= Text (Point (100,100),"Black win.") Message.draw (Win) G= 1#Åð¶ïºúæåð±ðð                         Else: Change = change+1#»»°xæåxßmessage= Text (Point (100,120),"Click anywhere to quit.") Message.draw (Win) Win.getmouse () Win.close () main ()

Python Gobang Applet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.