猫史档案馆


【Python作品分享】awa【作品秀】

用户:柏林防空塔柏林防空塔查看:0 回复:0 评论:0 创建时间:2024-01-19T10:56:43


【作品展示】

center_image

 

【作品介绍】

a

 

【作品源代码】

'''你能闯到第几层?'''

# 1.导入库
import turtle as t
import random
import time

# 2.基础设置
t.hideturtle()
p = t.Pen()
p.speed(0)

# 3.背景场景
t.addshape('xhz.gif')
p.shape('xhz.gif')
p.stamp()
# 4.画笔外观
p.shape('turtle')
p.right(0)  
p.shapesize(3)
p.penup()

# 5.变量设置
level = 0
j = 0.1
lst = [
    (-90,  90),  (-30,  90),  ( 30,  90),  ( 90,  90),
    (-90,  30),  (-30,  30),  ( 30,  30),  ( 90,  30),
    (-90, -30),  (-30, -30),  ( 30, -30),  ( 90, -30),
    (-90, -90),  (-30, -90),  ( 30, -90),  ( 90, -90),
]

# 6.进入下一层
def next_level(x, y):
    '''进入下一层'''
    global level, j, lst
    red = random.randint(1, 8) / 10
    write = random.randint(1, 8) / 10
    orange = random.randint(1, 8) / 10
    p.color(red, write, orange)
    for x, y in lst:
        p.goto(x, y)
        p.stamp()
    x, y = random.choice(lst)
    p.goto(x, y)
    p.color(red+j, write+j, orange+j)
    level = level + 1
    j = j - 0.005

# 7.开始游戏
start = time.time()
while time.time() - start <= 10:
    p.onclick(next_level)

# 8.结果显示
p.goto(-150, -150)
p.hideturtle()
p.write('真厉害! 达到了第'+str(level)+'层', move=True, align='left', font=('瘦金体', 20, 'italic', 'bold'))
t.done()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页