猫史档案馆


One2three4

One2three4

Lv.1

好好学习,天天向上!

获赞:43收藏:13浏览:134作品收藏:6

签名:努力创作出更好的作品

回复帖子评论
上一页1 页 / 共 1下一页

【Python作品分享】我的文件【作品秀】 中回复

这是我的帖子。请大家多多指导!谢谢大家🙏!

2023-08-09T19:35:22 点赞:0

【Python作品分享】我的文件【作品秀】 中回复

import turtle
import random
import time

# "px"=头像
px = turtle.Pen()
px.speed(0)
turtle.bgpic("场景1.gif")

px.penup()
turtle.addshape("Users(系统内部文件).gif")
px.shape("Users(系统内部文件).gif")
px.goto((-20), 200)
px.speed(1)
px.goto((-20), 0)
print('进入秘境,沿着主路探索:')
print('------------------------')
score = 0
# 遇到野怪
# p0~4=野怪
p0 = turtle.Pen()
p1 = turtle.Pen()
p2 = turtle.Pen()
p3 = turtle.Pen()
p4 = turtle.Pen()
p0.speed(0)
p1.speed(0)
p2.speed(0)
p3.speed(0)
p4.speed(0)
p0.penup()
p1.penup()
p2.penup()
p3.penup()
p4.penup()
turtle.addshape("野怪图片.gif")
p0.shape("野怪图片.gif")
p1.shape("野怪图片.gif")
p2.shape("野怪图片.gif")
p3.shape("野怪图片.gif")
p4.shape("野怪图片.gif")
x = random.randint((-200), 200)
y = random.randint((-100), 100)
p0.goto(x, y)
x = random.randint((-200), 200)
y = random.randint((-100), 100)
p1.goto(x, y)
x = random.randint((-200), 200)
y = random.randint((-100), 100)
p2.goto(x, y)
x = random.randint((-200), 200)
y = random.randint((-100), 100)
p3.goto(x, y)
x = random.randint((-200), 200)
y = random.randint((-100), 100)
p4.goto(x, y)

print('遇到野怪:')
for i in range(5):
    print('消灭野怪,获得10个积分')
    score += 10
time.sleep(0.333)
p0.hideturtle()
time.sleep(0.1)
p1.hideturtle()
time.sleep(0.1)
p2.hideturtle()
time.sleep(0.1)
p3.hideturtle()
time.sleep(0.1)
p4.hideturtle()
px.goto((-20), (-400))
print('你的积分:', score)
print('------------------------')

px.speed(0)
px.goto((-10), 200)
# 遇到宝藏
yet = ''

turtle.bgpic("场景2.gif")
px.speed(1)
px.goto((-10), 0)
print('遇到宝藏:')
print('单词密码为: h o p y t n')
key = turtle.textinput('textinput', 'Please enter the ture password:')
if (key == 'python'):
    print('获得宝藏10个积分')
    score += 10
    yet = 1
elif (key == 'Python'):
    print('获得宝藏10个积分')
    score += 10
    yet = 1
elif (key == 'PYTHON'):
    print('获得宝藏10个积分')
    score += 10
    yet = 1
else:
    yet = 0
    px.goto((-20), (-400))
    pass
if (yet == 1):
    turtle.bgpic("场景2 - 副本.gif")
    px.forward(200)
    time.sleep(1)
    px.backward(200)
    px.goto((-20), (-400))
else:
    px.goto((-20), (-400))
print('你的积分:', score)
print('------------------------')

# 遇到英雄或敌人
turtle.bgpic("场景3.gif")
px.speed(0)
px.goto(0, 200)
px.speed(1)
px.goto(0, 30)

print('遇到英雄或敌人:')
way = turtle.textinput("textinput",'Choose two routes A or B:')
if (way == 'A'):
    px.backward(1000)
    print('给你10个积分')
    print('遇到英雄获得10积分')
    score += 10
else:
    px.forward(1000)
    print("遇到敌人损失10积分")
    print("哈哈哈!哈哈哈!不许动!不交10个积分你别想走!!!")
    score -= 10
    print('------------------------')

#"情景4.png"
turtle.bgpic("情景4.png")
px.speed(0)
px.goto(-25,500)
px.speed(1)
px.goto(-25,-500)
print('到达秘境出口,即将离开秘境')
print('你的积分:', score)
if (score > 50):
    print('闯关成功')
else:
    print('闯关失败')



turtle.done()

代码可以借鉴的哈

2023-08-09T19:37:58 点赞:0