用python怎样写个简单的象棋游戏
Admin 2022-09-08 群英技术资讯 966 次浏览
这篇文章主要介绍“用python怎样写个简单的象棋游戏”,有一些人在用python怎样写个简单的象棋游戏的问题上存在疑惑,接下来小编就给大家来介绍一下相关的内容,希望对大家解答有帮助,有这个方面学习需要的朋友就继续往下看吧。本文实例为大家分享了python实现象棋游戏的具体代码,供大家参考,具体内容如下
import math
from turtle import *
speed(0) #调整画的速度 1-10,数字越大,速度越快
width=50
hideturtle() #隐藏画笔的形状a
#绘制棋盘
for i in range(5):
forward(8*width)
penup()
goto(0,(i+1)*width)
pendown()
left(90)
for i in range(9):
penup()
goto(i*width,0)
pendown()
forward(4*width)
for i in range(9):
penup()
goto(i*width,-width)
pendown()
forward(-4*width)
left(270)
for i in range(5):
penup()
goto(0,-width*(i+1))
pendown()
forward(8*width)
penup()
goto(-10,4*width+10)
pendown()
right(90)
for i in range(2):
forward(9*width+20)
left(90)
forward(8*width+20)
left(90)
#田线
penup()
goto(3*width,4*width)
pendown()
left(45)
fd(2*math.sqrt(5000))
penup()
goto(3*width,2*width)
pendown()
left(90)
fd(2*math.sqrt(5000))
penup()
goto(3*width,-5*width)
pendown()
fd(2*math.sqrt(5000))
penup()
goto(3*width,-3*width)
pendown()
right(90)
fd(2*math.sqrt(5000))
#绘制炮兵标记
def fun(x,y):
penup()
home()
goto(x*width,y*width+3)
fd(-6)
pendown()
for i in range(4):
fd(3)
left(90)
fd(3)
penup()
right(90)
fd(6)
pendown()
right(90)
for i in range(5):
fun(i*2,1)
for i in range(5):
fun(i*2,-2)
fun(1,2)
fun(7,2)
fun(1,-3)
fun(7,-3)
def write_chees(str,color1): #棋字
color(color1)
write(str,font=('隶书',width//2,'normal'))
def drawcircle(radius): #画圆
pensize(3)
begin_fill()
fillcolor('white')
circle(radius)
end_fill()
def chees(x,y,str,color): #绘制棋子
penup()
home()
goto(x*width,y*width)
right(90)
fd(1/3*width)
left(90)
pendown()
pencolor(color)
drawcircle(1/3*width)
penup()
fd(-1/3*width)
pendown()
write_chees(str,color)
red='red'
black='black'
#红棋子
for i in range(5):
chees(i*2,1,'兵','red')
chees(1,2,'炮',red)
chees(7,2,'炮',red)
chees(0,4,'車',red)
chees(1,4,'馬',red)
chees(2,4,'相',red)
chees(3,4,'仕',red)
chees(4,4,'帅',red)
chees(5,4,'仕',red)
chees(6,4,'相',red)
chees(7,4,'馬',red)
chees(8,4,'車',red)
#黑棋子
for i in range(5):
chees(i*2,-2,'卒','black')
chees(1,-3,'炮',black)
chees(7,-3,'炮',black)
chees(0,-5,'車',black)
chees(1,-5,'馬',black)
chees(2,-5,'象',black)
chees(3,-5,'士',black)
chees(4,-5,'将',black)
chees(5,-5,'士',black)
chees(6,-5,'象',black)
chees(7,-5,'馬',black)
chees(8,-5,'車',black)
done()

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要介绍了Python如何保留float类型小数点后3位,具有很好的参考价值,希望对的大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
怎么用Python做中文词云?一些朋友比较好奇中文词云的实现,因此这篇文章就主要给大家介绍Python实现中文词云的方法,下文的示例代码对大家了解Python实现词云的方法有一定的帮助,感兴趣的朋友接下来一起跟随小编来学习一下吧。
@property装饰器能把一个方法变成属性一样来调用,下面我们就一起来看看Python黑魔法@property装饰器的使用技巧解析@property有什么用呢?表
如果想要充分利用,在python中大部分情况需要使用多进程,那么这个包就叫做multiprocessing。借助它,可以轻松完成从单进程到并发执行的转换。multiprocessing支持子进程、通信和共享数据、执行不同形式的同步,提供了Process、Queue、Pipe、Lock等组件。那么本节要介绍的内容有:ProcessLockSemaphoreQueuePipePoo
本文主要介绍了Python中str.format()方法的具体使用,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008