예제 #1
0
def talk(thing):
    if thing == "to" or thing == None:
        a.say("You talk a bit to yourself")
        return
    # check if the thing is in the inventory or in the current room
    # inventory and room.items are SET's. to merge them, I use pythons join command
    for i in inventory.union(current_room.items):
        if thing in i.aliases:
            exist = True
            break
    else:
        # else in a for loop means the whole loop was interrated trough, without any break
        a.say(
            "there is no {} to talk to, neither in your inventory nor in this room/location"
            .format(thing))
        return
    # the thing exist. thing is a string, i is the object
    a.say("you talk to {}...".format(thing))
    # check if object i (the item) has the .answers attribute
    if "answers" in i.__dict__.keys():
        a.say("and the {} says: '{}'".format(thing, random.choice(i.answers)))
    else:
        a.say(
            "but you get no reply. None at all. It seems that the {} is unable to talk"
            .format(thing))
예제 #2
0
def drop(thing):
    obj = inventory.take(thing)
    if not obj:
        a.say('You do not have a %s.' % thing)
    else:
        a.say('You drop the %s.' % obj)
        current_room.items.add(obj)
예제 #3
0
def go(direction):
    global current_room
    room = current_room.exit(direction)
    if room:
        current_room = room
        a.say('You go %s.' % direction)
        look()
        if room == magic_forest:
            a.set_context('magic_aura')
        else:
            a.set_context('default')
예제 #4
0
def take(item):
    if item == "wizard":
        a.say("The wizard does not want to be picked up by you")
        return
    obj = current_room.items.take(item)
    if obj:
        a.say('You pick up the %s.' % obj)
        inventory.add(obj)
    else:
        a.say('There is no %s here.' % item)
예제 #5
0
def cast(magic):
    if magic == None:
        a.say("Which magic you would like to spell?")
    elif magic == "fireball":
        a.say("you cast a flaming Fireball! Woooosh....")
예제 #6
0
def show_inventory():
    a.say('You have:')
    for thing in inventory:
        a.say(thing)
예제 #7
0
def look():
    a.say(current_room)
    #a.say("image: {}".format(current_room.image))
    if current_room.items:
        for i in current_room.items:
            a.say('A %s is here.' % i)
예제 #8
0
               ]])
    ],
    [sg.Button("Start"),
     sg.Button("Cancel"),
     sg.Button("test")],
]

window = sg.Window(title="Adventuregame", layout=layout)

while True:
    event, values = window.read()
    if event in [None, "Cancel"]:
        break
    if event == "Start":
        window["header"].update("Game is running")
        a.say("starting a new adventure")
        #a.start()
        look()
        #window["output"].update(size=(70,15))
        window["gui"].update(visible=True)
        #window["command"].update(visible=True)
        #window["execute"].update(visible=True)
        window["inputline"].update(visible=True)
        window["Start"].update(visible=False)
    if event == "execute":
        a.say(">>> " + values["command"].strip())
        a._handle_command(values["command"].strip())
    if event == "test":
        ugly = a._available_commands()
        print(ugly)
        #for t in ugly: