用户:
优雅的小黄鸡OdzY查看:42 回复:0 评论:0 创建时间:2021-05-23T12:52:26
【作品展示】

【作品介绍】
更新第四章,添加一个小游戏(请把文件保存到一个文件夹里,在文件夹里面放一个弹球的图像即可)
【作品源代码】
import random
import pygame
print("第一章 获得灵兽")
print("欢迎来到明日大陆")
print("在这个世界里,每个人都有一个叫“灵兽”的东西")
qw0=0
lqs=0
while qw0 != 1:
qw = input('''你成年了,需要猎取灵兽。
1.去灵兽森林
2.购买灵兽(初始财产50)''')
cc = 50
if qw == "1":
print("您进入了森林。")
print("森林里似乎有危险")
qw1 = input('''要离开吗?
1.离开。
2.继续走''')
if qw1 == "2":
print("一只强大的灵兽扑了上来。")
print("您捕捉了他。")
print("您获得了灵兽")
lqs = str(random.randint(1,100))
qw0=1
elif qw1 == "1":
print("您离开了森林。")
else:
print("请输入数字。")
qw0=0
elif qw == "2":
print("1.一级:25 2.二级:40 3.三级:50。")
if cc < 25:
print("财产不足")
if cc > 25:
qw2 = input("您要买哪种?")
if qw2 == "1":
cc-25
print("购买成功")
print("您获得了灵兽")
lqs = str(random.randint(10,19))
qw0 = 1
if qw2 == "2":
cc-40
print("购买成功")
print("您获得了灵兽")
lqs = str(random.randint(20,29))
qw0 = 1
if qw2 == "3":
cc-50
print("购买成功")
print("您获得了灵兽")
lqs = str(random.randint(30,39))
qw0 = 1
else:
print("恭喜发现彩蛋,作为奖励,作者送你一个灵兽,灵力自定义。")
qw0 = 1
lqs=input("灵力:")
else:
print("请输入数字。")
qw0=0
print("第一章完")
print("第二章 测试。")
print("您需要测试灵力。")
qe2=0
while qe2!=1:
qe=input('''您要去实验室吗?
1.yes.
2.no''')
if qe=="1":
print("您来到了实验室")
print("您的灵力是"+lqs+"级")
qe2=1
elif qe == "2":
print("作者语:嘿嘿,不想去也不行")
print("您来到了实验室")
print("您的灵力是"+lqs+"级")
qe2=1
else:
print("请输入数字。")
qw2=0
print("第二章完")
print("第三章,地下国度。")
print("你需要进入地下城提升实力。")
qr0=0
while qr0!=1:
print('你面前有三条路,那么,你要走哪条?')
qr=input("""1.左边
2.右边
3.中间""")
if qr=="1":
print("前方有一个不明生物,要离开吗?")
qr1=input('''1.yes
2.no''')
if qr1=="2":
print("你击杀了它并吸收了它的灵力。")
qr0=1
lqs="150"
elif qr1=="1":
qr0=0
else:
print("请输入数字。")
qr0=0
elif qr=="2":
print("前方有一个盒子,要打开它吗?")
qr2=input("""1.yes
2.no""")
if qr2=="1":
print("你获得了灵核。")
qr0=1
lqs="150"
elif qr2=="2":
print("你被传送回了起点。")
qr0=0
else:
print("请输入数字。")
qr0 = 0
elif qr=="3":
print("前方有一个闪着蓝光的物体,往前走吗?")
qr3=input("""1.yes
2.no""")
if qr3=="1":
print("那是一个升灵装置,你的灵力提升了。")
qr0=1
lqs="150"
elif qr3=="2":
qr0=0
else :
print("请输入数字。")
qr0 = 0
else:
print("请输入数字。")
qr0=0
print("灵力:"+lqs)
print("第三章完")
print("第四章 聚灵阵")
print("既然你已经完成了凝气一重")
print("你需要完成一个聚灵阵")
print("但完成聚灵阵需要灵石")
qa0=0
while qa0 !=1:
qa = input("""1.去购物中心
2.去乱石滩
3.去天堂......""")
if qa=="1":
print("你来到了购物中心")
print("")
print("购物中心里有很多店铺,要去哪一个?")
qa1=input("""1.奶茶店
2.石头工艺馆""")
if qa1=="1":
print("你来到了奶茶店。")
print("服务员:“您好,请问您想要那种饮品?”")
qa2=input("""1.椰果奶茶
2.珍珠奶茶
3.布丁奶茶""")
if qa2=="1":
print("你在奶茶里喝出了一块石头,你刚想找服务员理论,却发现这块石头中有一丝灵气。原来,这是一块灵石。")
qa0=1
elif qa2=="2":
print("你在奶茶里喝出了一块石头,你刚想找服务员理论,却发现这块石头中有一丝灵气。原来,这是一块灵石。")
qa0 = 1
elif qa2 == "3":
print("你在奶茶里喝出了一块石头,你刚想找服务员理论,却发现这块石头中有一丝灵气。原来,这是一块灵石。")
qa0 = 1
else:
print("请输入数字。")
qa0 = 0
elif qa1 == "2":
print("你来到了石头工艺馆。")
print("你看中了一个泛着光的石头,果不其然,这是一块灵石。")
qa0 = 1
else:
print("请输入数字。")
qa0 = 0
elif qa == "2":
print("你来到了乱石滩")
print("在乱石滩上,你找来找去,发现了一块很大的灵石。")
qa0 = 1
elif qa == "3":
print("还真有人想去天堂......")
qa0 = 0
else:
print("请输入数字。")
qa0 = 0
print("你抱着灵石回了家,你用灵石搭设了一个聚灵阵,你感觉天地之间的灵喵源不断地聚集过来")
print("第四章完")
qa3=input("ps:第四章结束,作者准备了一个游戏,想玩请输入game")
pygame.init()
screen = pygame.display.set_mode([800, 600])
white = (255, 255, 255)
black = (0, 0, 0)
ball = pygame.image.load("ball.png")
ballx = 0
bally = 0
speedx = 5
speedy = 5
qew = 200
qeh = 15
qex = 300
qey = 570
font = pygame.font.SysFont("SimHei", 24)
timer = pygame.time.Clock()
points = 0
lives = 3
runniing = True
while runniing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
runniing = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_F1:
lives = 3
points = 0
if lives == 0:
text = font.render("游戏结束", True, white)
screen.blit(text, (350, 270))
pygame.display.update()
ballx += speedx
bally += speedy
if ballx <= 0 or ballx + ball.get_width() >= 800:
speedx = -speedx
if bally+ball.get_height() >= 600:
lives -= 1
speedy = -speedy
if bally <= 0:
speedy = -speedy
screen.fill(black)
screen.blit(ball, (ballx, bally))
qex = pygame.mouse.get_pos()[0]
pygame.draw.rect(screen, white, (qex, qey, qew, qeh))
if bally + ball.get_height() >= qey and speedy > 0:
if ballx + ball.get_width() / 2 >= qey and ballx + ball.get_width() / 2 <= qex + qew:
points += 1
speedy = -speedy
draw_string = "生命数:" + str(lives) + "得分:" + str(points)
text = font.render(draw_string, True, white)
text_rect = text.get_rect()
text_rect.centerx = screen.get_rect().centerx
text_rect.y = 10
screen.blit(text, text_rect)
pygame.display.update()
timer.tick(60)
pygame.quit()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn