资源简介
中国象棋对战
使用python语言实现
能够实现双人对战(单机)
代码片段和文件信息
import pygame
import pygame.font
import sys
import traceback
import copy
from math import sqrt
from pygame.locals import *
pygame.font.init()
pygame.init()
i = 50 #一格的距离
r = 25 #棋子半径
#绘制棋盘
def Draw_qipan(screen):
#棋盘背景色
screen.fill((200200200))
#画外框
color1 = (100100100)
pygame.draw.rect(screencolor1[4040420470]5)
#画行和列
color2 = (000)
for i in range(111):
pygame.draw.line(screencolor2(5050*i)(45050*i))
for i in(19):
pygame.draw.line(screencolor2(50*i50)(50*i500))
for i in range(29):
pygame.draw.line(screencolor2(50*i50)(50*i250))
pygame.draw.line(screencolor2(50*i300)(50*i500))
#画‘士’路线
color3 = (000)
pygame.draw.line(screen color3 (20050)(300150))
pygame.draw.line(screen color3 (200150)(30050))
pygame.draw.line(screen color3 (200500)(300400))
pygame.draw.line(screen color3 (200400)(300500))
#画‘悔棋’,‘重新开始’,‘退出’,‘楚河汉界’
color4 = (100100100)
pygame.draw.rect(screencolor4[50020012040]3)
pygame.draw.rect(screencolor4[50030012040]3)
pygame.draw.rect(screencolor4[50040012040]3)
font1 = pygame.font.Font(‘C:\Windows\Fonts\STXINGKA.TTF‘20)
font2 = pygame.font.Font(‘C:\Windows\Fonts\STXINGKA.TTF‘30)
text1 = font1.render(“悔 棋“Truecolor4)
text2 = font1.render(“重新开始“Truecolor4)
text3 = font1.render(“退出游戏“Truecolor4)
text4 = font2.render(“楚 河 汉 界“Truecolor4)
screen.blit(text1(520210))
screen.blit(text2(520310))
screen.blit(text3(520410))
screen.blit(text4(150260))
#绘制棋子
def Draw_qizi(screencolorqizixy):
red_color = (25500)
black_color = (000)
pygame.draw.circle(screen(128640)(xy)25)
pygame.draw.circle(screen(255255128)(xy)20)
font1 = pygame.font.Font(‘C:\Windows\Fonts\STHUPO.TTF‘32)
if color == ‘red‘:
q_color = red_color
elif color == ‘black‘:
q_color = black_color
screen.blit(font1.render(qizi[0]Trueq_color)(x-16y-16))
#绘制带有棋盘的棋子
def Draw_qipan_with_qizi(screen):
Draw_qipan(screen)
for qizi in hongqi.keys():
Draw_qizi(screenhongqi[qizi][‘color‘]qizihongqi[qizi][‘weizhi‘][0]hongqi[qizi][‘weizhi‘][1])
for qizi in heiqi.keys():
Draw_qizi(screenheiqi[qizi][‘color‘]qiziheiqi[qizi][‘weizhi‘][0]heiqi[qizi][‘weizhi‘][1])
#通过位置寻找棋子
def find(xy):
for qizi in hongqi.keys():
if sqrt((hongqi[qizi][‘weizhi‘][0] - x)**2+(hongqi[qizi][‘weizhi‘][1]-y)**2) < r:
return [Trueqizi‘red‘]
for qizi in heiqi.keys():
if sqrt((heiqi[qizi][‘weizhi‘][0] - x)**2+(heiqi[qizi][‘weizhi‘][1]-y)**2) < r:
return [Trueqizi‘black‘]
return[False]
#判断该位置有无棋子
def weizhi_panduan(xy):
for qizi in hongqi.keys():
if [xy] == hongqi[qizi][‘
- 上一篇:openmv 识别3个颜色 工程训练大赛
- 下一篇:python文件词频统计
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论