猫史档案馆


【Python作品分享】level2火星地形【作品秀】

用户:@所以图@所以图查看:0 回复:0 评论:0 创建时间:2024-05-26T20:15:14


【作品展示】

center_image

 

【作品介绍】

简单

 

【作品源代码】

import turtle as t
import time
import random
t.tracer(0)
t.penup()
t.ht()
t.setup(width=800, height=600)
t.title("2100资源危机")
t.bgpic('背景.gif')
t.color("white")
t.goto(-380,200)
t.write('2100年地球资源枯竭\n人类需要去近似地球的其他星球探索殖民\n火星则成为了最优选择',
        align="left", font=('楷体', 20, ''))
t.goto(-380, 170)
t.write('宇航员需要勘测火星地形选择符合要求的地方进行殖民',
        align="left", font=('楷体', 20, ''))
t.goto(0,0)
t.textinput("勘测火星地形", "按回车键开始进行勘测")
t.ht()
t.penup()
t.title("勘测火星地形")
t.bgpic('火星.gif')
t.clear()
t.goto(-380, 250)
t.write('点击火星表面红标位置观看火星地貌并测量适合度',
        align="left", font=('楷体', 20, ''))
t.goto(-380, 220)
t.write('若测量出的适合度小于60,则此地暂时不适合殖民',
        align="left", font=('楷体', 20, ''))
wn = t.Screen()

p = t.Pen()
p.penup()
p.ht()

'''绘制不同地点'''
dict = {"水手峡谷":(100,50),"奥林匹斯山":(-175,-85)}
for key,val in dict.items():  
    p.goto(val[0],val[1])
    p.dot(25,'red')
    p.write(key)

'''预置地貌图片'''
img = t.Pen()
img.penup()
img.ht()
for i in dict.keys():    
    t.addshape(i+".gif")

'''定义点击事件'''
def fn(x,y):
    threshold = 100 
    for key,val in dict.items():
        if (x - val[0])**2 + (y - val[1])**2 <= threshold:
            img.ht()
            img.shape(key + ".gif")
            loc = dict.get(key)
            img.goto(loc[0],loc[1])
            img.st() 
            t.update()
            f = random.randint(40, 100)
            s=t.textinput("适合度:"+str(f)+"是否要去"+key, "去输入去,不去输入额外字符")
            if s== "去" and f >= 60:
                wn.clear()
                img.ht()
                t.title("火星家园")
                t.bgpic('火星表面.gif')
                import level1火星家园
            elif s == "去" and f < 60:
                t.textinput("按回车键结束对话", "适合度过低,总部不批准去")



wn.onclick(fn)
t.done()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页