资源简介
用pygame简单实现的一个中国象棋代码
代码片段和文件信息
#-*- coding:utf-8 -*-
import pygame
import pygame._view
from pygame.locals import *
from sys import exit
#from Chessman import *
class chess(object):
pygame.init()
font = pygame.font.Font(“simsun.ttc“32)
def __init__(selfSCREEN_SIZE=(560630)):
#pygame.init()
self.SCREEN_SIZE=SCREEN_SIZE
x=SCREEN_SIZE[0]+60
y=SCREEN_SIZE[1]+60
self.screen = pygame.display.set_mode((xy)032)
pygame.display.set_caption(‘Chess‘)
#self.background = pygame.image.load(‘sushiplate.jpg‘).convert()
self.grid_dict = {}
for x in range(9):
for y in range(10):
self.grid_dict[(xy)] = self.grid(xy)
self.red_list = maninit(red)
self.green_list = maninit(green)
#self.man_list = self.red_list + self.green_list
self.select_point = (-1-1)
self.select_man = None
self.current_color = red
self.background = pygame.image.load(‘back2.jpg‘).convert()
self.update()
#print ‘end‘
def over(selfcolor):
text = ‘‘
if color == red:
text = u‘红方‘
if color == green:
text = u‘蓝方‘
text_surface = chess.font.render(text+u‘输‘Truecolor)
self.screen.blit(text_surface(305345))
def update(self):
self.screen.blit(self.background(00))
self.drawbackground(self.screen)
self.drawcross(self.screen)
self.drawmans()
self.select(self.select_point[0]self.select_point[1])
def get_mans(self):
return self.red_list + self.green_list
def grid(selfxy):
gridX=self.SCREEN_SIZE[0] * x / 8.0 + 30
gridY=self.SCREEN_SIZE[1] * y / 9.0 + 30
return (gridXgridY)
def find_grid(selfMouse_xMouse_y):
longth = 10000
points_list = self.grid_dict.values()
tmp_point = (00)
for point in points_list:
tmp = (Mouse_x-point[0])**2+(Mouse_y-point[1])**2
if longth>= tmp:
longth = tmp
tmp_point = point
if longth >= 35**2:
return None
i = points_list.index(tmp_point)
return self.grid_dict.keys()[i]
def select(selfgridXgridY):
#self.drawcross(self.screen(gridXgridY))
if (gridXgridY)==(-1-1):
return
xy = self.grid(gridXgridY)
color = red
pygame.draw.lines(self.screencolorFalse[(x-35y-35)(x-10y-35)]3)
pygame.draw.lines(self.screencolorFalse[(x+35y-35)(x+10y-35)]3)
pygame.draw.lines(self.screencolorFalse[(x-35y+35)(x-10y+35)]3)
pygame.draw.lines(self.screencolorFalse[(x+35y+35)(x+10y+35)]3)
pygame.draw.lines(self.screencolorFalse[(x-35y-35)(x-35y-10)]3)
pygame.draw.lines(self.screencolorFalse[(x+35y-35)(x+35y-10)]3)
pygame.draw
- 上一篇:Python爬虫--抓取百度百科的前1000个页面
- 下一篇:多线程爬虫
相关资源
- 多线程爬虫
- Python爬虫--抓取百度百科的前1000个页
- nlp肯定句与否定句判断
- 绘制社交网络图的幂律分布python代码
- Python 飞机大战 游戏设计需求 与 实现
- PARZEN窗和K近邻算法的python实现
- windows下fcntl.py
- Python项目案例开发从入门到实战源代
- Python项目案例开发从入门到实战源代
- python写的专家系统玩具分类
- 基于决策树的天气大数据回归例程
- python实现图像的混沌加密解密
- think python 中文版.pdf
- kNN分类器和两个-Python
- TensorFlow实现股票预测的Python代码
- 解压微信小程序源码python文件
- python数据结构与算法
- 支持向量机几个的代码
- Python:网络爬虫抓取豆瓣3万本书-详细
- Python GUI项目:文件夹管理系统代码
- python2.7_批量读取netCDF4文件并输出为
- Python 3网络爬虫开发实战pdf 崔庆才著
- python串口读写
- 基于Python的Vibe目标检测代码
- python首次连接STK
- PSO_TSP_Python
- PythonOCC的安装
-
pyQt5_wavepla
yer python计算声音分贝 语 - The Python Language Reference Manual 无水印
- iris.csv数据集和python代码
评论
共有 条评论