资源简介
Python项目案例开发从入门到实战源代码第14章 网络通讯案例——基于UDP的网络五子棋.rar

代码片段和文件信息
from tkinter import *
from tkinter.messagebox import *
import socket
import threading
import string
root = Tk()
root.title(“ 五子棋--夏敏捷2016-2-11仨个小时 网络版 UDP 客户端“)
imgs= [PhotoImage(file=‘D:\\python\\bmp\\BlackStone.gif‘) PhotoImage(file=‘D:\\python\\bmp\\WhiteStone.gif‘)]
turn=0
def callback(event):#走棋
global turn
#print (“clicked at“ event.x event.yturn)
x=(event.x)//40 #换算棋盘坐标
y=(event.y)//40
print (“clicked at“ x yturn)
if map[x][y]!=“ “:
showinfo(title=“提示“message=“已有棋子“)
else:
img1= imgs[turn]
cv.create_image((x*40+20y*40+20)image=img1)
cv.pack()
map[x][y]=str(turn)
k=win_lose( )
#print_map( ) #输出map地图
if win_lose( )==True:
if turn==0 :
showinfo(title=“提示“message=“黑方你赢了“)
else:
showinfo(title=“提示“message=“白方你赢了“)
#换下一方走棋
if turn==0 :
turn=1
else:
turn=0
pos=str(x)+““+str(y)
sendMessage(pos)
def drawQiPan( ):#画棋盘
for i in range(015):
cv.create_line(2020+40*i58020+40*iwidth=2)
for i in range(015):
cv.create_line(20+40*i2020+40*i580width=2)
cv.pack()
def win_lose( ):#输赢判断
#扫描整个棋盘,判断是否连成五颗
a = str(turn)
print (“a=“a)
for i in range(011):#0--10
# 判断X= Y轴上是否形成五子连珠
for j in range(011):#0--10
if map[i][j] == a and map[i + 1][j + 1] == a and map[i + 2][j + 2] == a and map[i + 3][j + 3] == a and map[i + 4][j + 4] == a :
print(“X= Y轴上形成五子连珠“)
return True
for i in range(415):# 4 To 14
# 判断X= -Y轴上是否形成五子连珠
for j in range(011):#0--10
if map[i][j] == a and map[i - 1][j + 1] == a and map[i - 2][j + 2] == a and map[i - 3][j + 3] == a and map[i - 4][j + 4] == a :
print(“X= -Y轴上形成五子连珠“)
return True
for i in range(015):#0--14
# 判断Y轴上是否形成五子连珠
for j in range(415):# 4 To 14
if map[i][j] == a and map[i][j - 1] == a and map[i][j - 2] == a and map[i][j - 3] == a and map[i][j - 4] == a :
print(“Y轴上形成五子连珠“)
return True
for i in range(011):#0--10
# 判断X轴上是否形成五子连珠
for j in range(015):#0--14
if map[i][j] == a and map[i + 1][j] == a and map[i + 2][j] == a and map[i + 3][j] == a and map[i + 4][j] == a :
print(“X轴上形成五子连珠“)
return True
return False
#End Function
def print_map( ):#输出map地图
for j in range(015):#0--14
for i in range(015):#0--14
print (map[i][j]end=‘ ‘)
print (‘w‘)
def drawOtherChess(xy):#画对方棋子
global turn
img1= imgs[turn]
cv.create_image((x*40+2
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5433 2016-07-27 09:06 第14章 网络通讯案例——基于UDP的网络五子棋\五子棋游戏 - 单机版\人机井字棋.py
文件 3841 2016-02-11 19:15 第14章 网络通讯案例——基于UDP的网络五子棋\五子棋游戏 - 单机版\鼠标事件-3 五子棋游戏 - 单机版 V1.0.py
文件 5716 2016-08-31 10:23 第14章 网络通讯案例——基于UDP的网络五子棋\五子棋游戏 - 单机版\鼠标事件-3 五子棋游戏 - 单机版 V2.0(悔棋版).py
文件 4827 2016-02-28 12:05 第14章 网络通讯案例——基于UDP的网络五子棋\五子棋游戏 - 单机版\鼠标事件-3 五子棋游戏 - 单机版 V2.0.py
文件 70 2016-02-16 09:55 第14章 网络通讯案例——基于UDP的网络五子棋\版本.txt
文件 5886 2016-02-13 20:41 第14章 网络通讯案例——基于UDP的网络五子棋\鼠标事件-3 五子棋游戏 - 网络版 UDP 客户端1.0.py
文件 7226 2016-08-01 16:01 第14章 网络通讯案例——基于UDP的网络五子棋\鼠标事件-3 五子棋游戏 - 网络版 UDP 客户端V2.0.py
文件 7659 2016-08-31 10:49 第14章 网络通讯案例——基于UDP的网络五子棋\鼠标事件-3 五子棋游戏 - 网络版 UDP 客户端V2.1.py
文件 6071 2016-02-13 20:46 第14章 网络通讯案例——基于UDP的网络五子棋\鼠标事件-3 五子棋游戏 - 网络版 UDP 服务器端1.0.py
文件 7165 2016-08-31 10:49 第14章 网络通讯案例——基于UDP的网络五子棋\鼠标事件-3 五子棋游戏 - 网络版 UDP 服务器端V2.1.py
目录 0 2018-11-07 19:54 第14章 网络通讯案例——基于UDP的网络五子棋\五子棋游戏 - 单机版
目录 0 2018-11-07 19:54 第14章 网络通讯案例——基于UDP的网络五子棋
----------- --------- ---------- ----- ----
53894 12
相关资源
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
评论
共有 条评论