打开图片?蟒蛇 [英] Open images? Python

查看:107
本文介绍了打开图片?蟒蛇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基于文本的labryinth游戏,但我认为它需要一些图片来说明最新情况。出于某种原因,当我试图去a2时(图片应该弹出),它就会死掉。我是初学者,所以不要太多地判断我的代码^^

Im creating a text based labryinth game, but I figured it needed some pictures to illustrate whats going on. For some reason it just dies when I try to go to a2(Where the picture should pop up). I am a beginner so dont judge my code so much ^^

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())。

You should probably also think about an other system to show your messages, because this way it will be a lot of manual work. Look into string substitution (using %s or .format()).

这篇关于打开图片?蟒蛇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆