gpt4 book ai didi

python - 打开图像? Python

转载 作者:太空狗 更新时间:2023-10-29 21:12:33 25 4
gpt4 key购买 nike

我正在创建一个基于文本的迷宫游戏,但我认为它需要一些图片来说明发生了什么。出于某种原因,当我尝试转到 a2(图片应该弹出的位置)时它就死了。我是初学者所以不要对我的代码评价太多^^

import Image
a1 = ("a1 Go to the start of the Labyrinth", "You're at the start of the labyrinth") #Start
a2 = ("a2 Go Left", "You've chosen to go left, unfortunatly it leads to nothing.") #Fail route
a3 = ("a3 Go Right", "You've chosen to go right.") #Right route
a4 = ("a4 Go Left", "You've chosen to go left") #Fail route
a5 = ("a5 Go Right", "You've chosen to go right") #Right route
a6 = ("a6 Go Right", "You've chosen to go right") #Fail route; end
a7 = ("a7 Go Left", "You've chosen to go left") #Fail route
a8 = ("a8 Go Left", "You've chosen to go left") #Fail route; end
a9 = ("a9 Go Right", "You've chosen to go right") #Fail route; end
a10 = ("a10 Go Forwards", "You've chosen to go forwards") #Right route
a11 = ("a11 Go left", "You've chosen to go left; Congratulations, you won! You may restart") #Right route; end; victory
fail = ("fail End game", "You lost!") #End game
b1 = ("b1 Go Left", "You've chosen to go left")
b2 = ("b2 Go Right", "You've chosen to go right")
b3 = ("b3 Go Left", "You've chosen to go left")

transitions = {
a1: (a2, a3),
a2: (fail, a1),
a3: (b1,),
b1: (a4, a5,),
a4: (b2,),
b2: (a7, a6,),
a5: (b3,),
b3: (a9, a10,),
a6: (fail, a1),
a7: (a8,),
a8: (fail, a1),
a9: (fail, a1),
a10: (a11,),
a11: (a1,)
}

location = a1

while True:
print location[1]
print ("Here you can: ")

for (i, t) in enumerate(transitions[location]):
print i + 1, t[0]

choice = int(raw_input("Choose one "))
location = transitions[location][choice - 1]

if location == a2:
Image.open(picture.jpg)
Img.show

最佳答案

代替

Image.open(picture.jpg)
Img.show

你应该有

from PIL import Image

#...

img = Image.open('picture.jpg')
img.show()

您可能还应该考虑使用其他系统来显示您的消息,因为这样会需要大量的手动工作。查看字符串替换(使用 %s.format())。

关于python - 打开图像? Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16387069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com