用户:
坚强的超能鸭nGCy查看:0 回复:1 评论:0 创建时间:2021-01-24T17:19:34
【作品展示】

【作品介绍】
一个与电脑游戏的数字喵小游戏,全靠运气哟。你只要在弹窗输入弹窗提示的多少到多少中的一个数字就行了。你们赢的机会高吗。我这个背景很好看哟。
【作品源代码】
import turtle
import random
screen=turtle.Screen()
screen.setup(1000,783)
mypen = turtle.Pen()
screen.bgpic("梦幻海.PNG")
mypen.hideturtle()
boom = random.randint(1, 100)
min_num = 1
max_num = 100
bout=1
mypen.penup()
def game(name):
global min_num, max_num,playing
if name == "玩家":
choose = int(screen.numinput(f"第{bout}回合", f"请从{min_num}到{max_num}中选取一个数字", maxval=max_num, minval=min_num))
mypen.clear()
y = 0
else:
choose = random.randint(min_num,max_num)
y = -100
mypen.goto(0, y)
mypen.write(f"{name}选择的数是{choose}", font=("思源宋体", 40, "normal"), align="center")
if choose == boom:
if name == "玩家":
winner="电脑"
else:
winner="玩家"
mypen.goto(0,100)
mypen.pencolor("tomato")
mypen.write(f'游戏结束,数字喵是{boom},{winner}赢了', font=(
"思源宋体", 40, "normal"), align="center")
playing = False
elif choose < boom:
min_num=choose+1
else:
max_num = choose-1
playing = True
while playing:
game("玩家")
if playing:
game("电脑")
bout+=1
turtle.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn