猫史档案馆


【Python作品分享】第五课 - 接手开发

用户:曹50UI曹50UI查看:0 回复:0 评论:0 创建时间:2024-07-22T15:19:15


【作品展示】

center_image

 

【作品介绍】

这是我的作品

 

【作品源代码】

'''你能闯到第几层?'''
# 1.导入库
import turtle as t
import random
import time

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

# 3.背景场景
t.addshape('pic.gif')#增加背景
p.shape('pic.gif')#增加背景
p.stamp# 印章
# 4.画笔外观
p.shape("circle")
p.right(77)
p.shapesize(2)
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
    green = random.randint(1, 8) / 10
    blue = random.randint(1, 8) / 10
    p.color(red, green, blue)
    for x, y in lst:
        p.goto(x, y)
        p.stamp()
    x, y = random.choice(lst)
    p.goto(x, y)
    p.color(red+j, green+j, blue+j)
    level = level + 1
    j = j - 0.005

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

# 8.结果显示
p.goto(0, 0)
p.hideturtle()
p.write('真厉害! 达到了第'+str(level)+'层')

t.done()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页