Python海龟绘图-斗地主

#导入库
import random as r
import turtle as t
#数据
pk=['红心A','红心2','红心3','红心4','红心5','红心6','红心7','红心8', '红心9','红心10','红心J','红心Q','红心K',
    '黑桃A','黑桃2','黑桃3','黑桃4','黑桃5','黑桃6','黑桃7','黑桃8', '黑桃9','黑桃10','黑桃J', '黑桃Q','黑桃K',
    '方块A','方块2','方块3','方块4','方块5','方块6','方块7','方块8', '方块9','方块10','方块J','方块Q','方块K',
    '梅花A','梅花2','梅花3','梅花4','梅花5','梅花6','梅花7','梅花8', '梅花9','梅花10','梅花J','梅花Q','梅花K','小王','大王']
Farmer1 = []
Farmer2 = []
Dz = []
#函数的定义
def custom_sort_key(item):
    order = ['红心3','黑桃3','方块3','梅花3',
             '红心4','黑桃4','方块4','梅花4',
             '红心5','黑桃5','方块5','梅花5',
             '红心6','黑桃6','方块6','梅花6',
             '红心7','黑桃7','方块7','梅花7',
             '红心8','黑桃8','方块8','梅花8',
             '红心9','黑桃9','方块9','梅花9',
             '红心10','黑桃10','方块10','梅花10',
             '红心J','黑桃J','方块J','梅花J',
             '红心Q','黑桃Q','方块Q','梅花Q',
             '红心K','黑桃K','方块K','梅花K',
             '红心A','黑桃A','方块A','梅花A',
             '红心2','黑桃2','方块2','梅花2',
             '小王','大王']
    return order.index(item) if item in order else len(order)
def move (x,y):
    t.penup()
    t.goto(x,y)
    t.pendown()
def Give (identity):
    for i in range(17):
        Num = r.randint(0, len(pk) - 1)
        identity.append(pk[Num])
        del pk[Num]
def Write (identity,x,y):
    for j in range(0, len(identity)):
        move(x+j*40,y)
        # 方框
        t.penup()
        t.pensize(1)
        t.goto(x + j * 40, y + 30)
        t.pendown()
        t.color("Gray", "white")
        t.begin_fill()
        t.setheading(0)
        t.forward(100)
        t.circle(-5, 90)
        t.setheading(270)
        t.forward(150)
        t.circle(-5, 90)
        t.setheading(180)
        t.forward(100)
        t.circle(-5, 90)
        t.setheading(90)
        t.forward(150)
        t.circle(-5, 90)
        t.end_fill()
        move(x+j*40,y-20)
        if identity[j][0:2] == "红心":
            t.color("Red")
            t.write("\u2665", font=("Arial", 20, "normal"))
            move(x+j*40,y)
            t.write(identity[j][2:], font=("Arial", 20, "normal"))
        elif identity[j][0:2] == "黑桃":
            t.color("Black")
            t.write("\u2660", font=("Arial", 20, "normal"))
            move(x+j*40,y)
            t.write(identity[j][2:], font=("Arial", 20, "normal"))
        elif identity[j][0:2] == "方块":
            t.color("Red")
            t.write("\u2666", font=("Arial", 20, "normal"))
            move(x+j*40,y)
            t.write(identity[j][2:], font=("Arial", 20, "normal"))
        elif identity[j][0:2] == "梅花":
            t.color("Black")
            t.write("\u2663", font=("Arial", 20, "normal"))
            move(x+j*40,y)
            t.write(identity[j][2:], font=("Arial", 20, "normal"))
        elif identity[j][0:2] == "大王":
            t.color("Red")
            move(x+j*40,y)
            t.write("J",font=("Arial", 20, "normal"))
            move(x+j*40,y-25)
            t.write("O",font=("Arial", 20, "normal"))
            move(x+j*40,y-50)
            t.write("K",font=("Arial", 20, "normal"))
            move(x+j*40,y-75)
            t.write("E",font=("Arial", 20, "normal"))
            move(x+j*40,y-100)
            t.write("R",font=("Arial", 20, "normal"))
        elif identity[j][0:2] == "小王":
            t.color("Black")
            move(x + j * 40, y)
            t.write("J", font=("Arial", 20, "normal"))
            move(x + j * 40, y - 25)
            t.write("O", font=("Arial", 20, "normal"))
            move(x + j * 40, y - 50)
            t.write("K", font=("Arial", 20, "normal"))
            move(x + j * 40, y - 75)
            t.write("E", font=("Arial", 20, "normal"))
            move(x + j * 40, y - 100)
            t.write("R", font=("Arial", 20, "normal"))

#程序主体
t.hideturtle()
t.speed(0)
t.tracer(0)
#农民1
Give(Farmer1)
sorted_strings = sorted(Farmer1, key=custom_sort_key)
t.penup()
t.goto(-800,280)
t.color("black")
t.write("农民1的牌为:",font=("Arial", 20, "normal"))
Write(sorted_strings,-600,300)
#农民2的牌
Give(Farmer2)
sorted_strings1 = sorted(Farmer2, key=custom_sort_key)
move(-800,-20)
t.color("black")
t.write("农民2的牌为:",font=("微软雅黑", 20, "normal"))
Write(sorted_strings1,-600,0)
#地主的牌
Give(Dz)
for i in range (0,len(pk)):
    Dz.append(pk[i])
sorted_strings2 = sorted(Dz, key=custom_sort_key)
move(-800,-320)
t.color("black")
t.write("地主的牌为:",font=("微软雅黑", 20, "normal"))
Write(sorted_strings2,-600,-300)
#程序结尾
t.update()
t.done()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值