Ejemplo n.º 1
0
    def interact(self):

        if self.is_open:
            self.location.remove_item(self.contains)
            if self.contains is not None:
                if item_contained.location == -1:
                    self.contains = None
                else:
                    self.contains.location = None

                self.location.remove_items(self.contains)

            interaction = "You closed the \[b]{}\[o]".format(self.name)
            lib.pretty_print(interaction)

        else:
            interaction = "You opened the \[b]{}\[o] and you see it contains \[b]{}\[o]".format(
                self.name, self.contains.name)
            lib.pretty_print(interaction)

            if self.contains is not None:
                self.location.add_item(self.contains)
                self.contains.location = self.location

        self.is_open = not self.is_open

        return 0
Ejemplo n.º 2
0
 def get_item(self, player=None):
     if player is None:
         if self.is_open:
             lib.pretty_print(
                 "You pick up the {} and start to read it.\n{}".format(
                     self.contains.name, self.contains.desc))
     else:
         lib.pretty_print("The mailbox is firmly attached to it's post.")
Ejemplo n.º 3
0
    def look(self):
        string_to_print = self.desc
        if self.is_open:
            string_to_print = string_to_print.replace('closed', 'opened')
            if self.contains is not None:
                string_to_print += ' You can also see that it contains \[b]' + item_name + '\[o].'

        lib.pretty_print(string_to_print)
Ejemplo n.º 4
0
    def show(self):
        tmp_str = 'Your inventory contains:'
        for item in self.items:
            tmp_str += f'a \[b]{item}\[o] '

        tmp_str += "\nSo far the treasures you've collected are:"
        for treasure in self.treasures:
            tmp_str += f'\[b]{treasure}\[o] '

        lib.pretty_print(tmp_str)
Ejemplo n.º 5
0
    def look(self, player):
        if player.alight:
            if self.hidden_mobs is not None and self.mobs is None:
                super().add_mobs(self.hidden_mobs)
            if self.hidden_items is not None:
                super().add_items(self.hidden_items)
            super().print_mobs()
        else:
            lib.pretty_print(self.dark)
            self.print_mobs()

        super().print_exits()
        self.print_items()
Ejemplo n.º 6
0
    def use(self):
        if self.location == -1:
            player.alight = not player.alight

        if self.light:
            lib.pretty_print(
                f"You turned on the {self.name} and a light began to emit from it."
            )
        else:
            lib.pretty_print(
                f"You turned off the {self.name} and the light slowly faded from it."
            )

        self.light = not self.light
Ejemplo n.º 7
0
def main():
    # add other generation functions to this list
    generate.register_generation({
        "basic" : easy1.generate,
        "who" : who.generate,
        "whose" : who.generate_plural,
        "which" : which.generate#,
        })

    fname = sys.argv[1]
    nquestions = int(sys.argv[2])

    paras = []

    f = open(fname)
    line = f.readline()
    # take only real paragraphs, not titles or tables
    while line != "":
        if len(line) > 70:
            paras += [line]
        line = f.readline()
    f.close()

    all_qs = []
    qs = []

    while (len(qs) < nquestions) and (len(paras) > 0):
        i = random.randint(0, len(paras) - 1)
        p = paras.pop(i)
        parsed = parse.parse(p)
        all_qs += filter(lambda x: (type(x) == tuple) and 
                                   (x[0] != None) and 
                                   (lib.wc(x[0]) > 5),
                         generate.generate(parsed))
        flips = [random.randint(0, 2) for i in xrange(len(all_qs))]
        new_qs = []
        for i in xrange(len(flips)):
            if flips[i] == 0:
                qs += [all_qs[i][0]]
            else:
                new_qs += [all_qs[i]]
        all_qs = new_qs

    lib.pretty_print(qs)
    lib.pretty_print(all_qs)
    questions = map (lib.format, qs)
    for q in questions:
        print q
Ejemplo n.º 8
0
    def move(self, movement):
        exits = self.location.exits
        selected_move = False
        #		print(movement)
        if movement is None:
            lib.pretty_print("No movement given.")
        elif movement in exits:
            selected_move = exits.get(movement, None)
        elif movement[0:1] in exits:
            selected_move = exits.get(movement[0:1], None)

        if selected_move:
            self.turns = 0
            selected_move.look(self)
            self.location = selected_move
        else:
            lib.pretty_print("The move you entered is invalid")
            return None
Ejemplo n.º 9
0
 def look_obj(self, obj):
     if self.mobs is None and self.items is None:
         lib.pretty_print("There is \[b]nothing\[o] here to see.")
     elif self.mobs is not None and obj in self.mobs:
         lib.pretty_print(self.mobs[obj].desc)
     elif self.items is not None and obj in self.items:
         lib.pretty_print(self.items[obj].desc)
     else:
         lib.pretty_print(
             f"The \[b]{obj}\[o] doesn't exist or you mistyped it. Check your spelling."
         )
Ejemplo n.º 10
0
 def interact(self, player):
     #if the room is lit up we can see everything. By default the grue is always there.
     #if you have the flashlight and interact with it. It'll tell lyou some information
     #and then it'll let you shine it in it's eyes causing it run away and break through the wall
     #thus leading to the victory room.
     #if you interact with it without a flaslight you'll be eaten.
     if player.alight:
         lib.pretty_print(
             "The \[b]Grue\[o] stared at the \[b]flashglight\[o]'s glowing beam intently. It then stared at you. You could see the primal fear in its eyes as it ran away into the darkness.... Then a bright light appeared before you with a new exit from this area. It beckons you to come."
         )
         player.location.remove_mob(self)
         player.location.remove_hidden_mob(self)
         player.location.add_moves(player.location.hidden_exits)
     else:
         lib.pretty_print(
             "The \[b]Grue\[o] opened it mouth and the last thing you remember is the warmth leaving your body."
         )
         player.dead = True
         player.game_over = True
Ejemplo n.º 11
0
    def get_item(self, player):

        #we call the move location method and tell it to put it into the player's inventory so that it's
        #no longer in the game world.
        if self.location != -1 and self.removeable == True:
            self.move_location(-1)
            player.inventory.add(self)
            lib.pretty_print(
                "You have grabbed \[b]{}\[o] and put it into your \[b]inventory.\[o]"
                .format(self.name))
            player.location.remove_item(self)
        elif self.location is None:
            lib.pretty_print("This item doesn't exist")
        elif self.location == -1:
            lib.pretty_print("The item is in your inventory already.")
        elif self.removeable == False:
            lib.pretty_print(
                f"\[b]{self.name}\[o] is firmly attached and wont' budge.")
        else:
            lib.pretty_print("There is no item.")
Ejemplo n.º 12
0
    def print_exits(self):
        if self.exits == {}:
            lib.pretty_print(
                "There are no \[b]exits\[o]. It seems as though you're trapped in here. There must be some other way out."
            )
        else:
            exits = ' '.join(self.exits.keys())
            exits = exits.replace('n', 'north')
            exits = exits.replace('s', 'south')
            exits = exits.replace('e', 'east')
            exits = exits.replace('w', 'west')

            string = ""
            if len(exits) == 4:
                string = "There is a single exit to the \[b]{}\[o].".format(
                    exits)
            else:
                string = "There are exits to the \[b]{}\[o].".format(exits)

            lib.pretty_print(string)
Ejemplo n.º 13
0
def room_print_objs(objs: list, total_objs: str, prefix="You can see"):
    """
	
	Args:
		objs(list):The list of things we're going to be printing to the string. Mobs or Items by default. 
		total_objs (int): The total number of items we're going to be workign with.
		prefix(str): What to prefix the printing with.

	Returns:None

	"""
    string = ""
    if total_objs == 1:
        string = prefix + " a single \[b]{}\[o] before you."
        lib.pretty_print(string.format(objs[0]))
    elif total_objs >= 2:
        objs = ["\[b]{}\[o]".format(obj) for obj in objs]
        objs_fmt = "{}, and {}".format(','.join(objs[:-1]),
                                       objs[total_objs - 1])
        string = prefix + " {} before you."
        lib.pretty_print(string.format(objs_fmt))
Ejemplo n.º 14
0
    def interact(self):
        string_to_print = self.interaction
        if self.contains is not None:
            item_name = self.contains.name
            item_contained = self.contains
            string_to_print = string_to_print[:
                                              -1] + ' and it contains \[b]' + item_name + '\[o].'

            if self.is_open:
                self.location.remove_item(self.contains)
                if item_contained.location == -1:
                    self.contains = None
                else:
                    item_contained.location = None
                lib.pretty_print(string_to_print.replace('open', 'close')[:21],
                                 end=".\n")

            else:
                lib.pretty_print(string_to_print)
                if self.contains is not None:
                    self.location.add_items(self.contains)
                    item_contained.location = self.location

        self.is_open = not self.is_open
Ejemplo n.º 15
0
    def get_item(self, player):
        #we call the move location method and tell it to put it into the player's inventory so that it's
        #no longer in the game world.
        if self.location != -1:
            self.move_location(-1)
            player.inventory.add(self)
            player.score += self.score
            lib.pretty_print(
                f"You have grabbed \[b]{self.name}\[o] and put it into your \[b]inventory's treasure pouch\[o]"
            )
            player.location.remove_item(self)

        elif self.location is None:
            lib.pretty_print("This item doesn't exist")
        elif self.location == -1:
            lib.pretty_print("The item is in your inventory already.")
        else:
            lib.pretty_print("There is no item.")
Ejemplo n.º 16
0
def main_loop():
    gameover: bool = False
    while not gameover:
        usr_input = input(prefix).lower()
        lib.check_input(usr_input, player)
        #		dead=True
        gameover = player.game_over
    lib.pretty_print(f"You have scored {player.score} during your adventure.")
    if player.dead:
        lib.pretty_print(
            "You have died. Please try to stay alive longer next time.")
    else:
        lib.pretty_print(
            "You have escaped from this twisted world. Though you can feel it's beckoning call to explore it's \[b]world\[o] again. Stay tuned for \[b;o]Adventure 2: The Adventuring\[o]"
        )
Ejemplo n.º 17
0
except NameError:
    import lib

import sys
from data import *

verbs = ['look', 'grab', 'move', 'interact', 'help']

prefix = '> '

directions = ['north', 'south', 'west', 'east']
print('Enter your name brave traveller.')
name = input(prefix)
#name='a';
lib.pretty_print(
    "Welcome to the world of \[b;i]Adventure\[o].\nBut before we begin first a brief tutorial on how this world works. In this world you will be tasked discovering it's secrets. The parser is your interface to this game world. It will accept commands in the following input.\n \[b]{VERB} {OBJECT}\[o]. An example is given below. To move north you'd type into the prompt denoted by \[b]>\[o] \n> move north\nIt also supports shorthand for movements so move n also works. Your verbs are given at the start. Anything you can interact with via a verb will be \[b]bolded\[o].\nYou also have an inventory you can utilize. It is accessed via \[b]look inventory\[o].\n"
)

lib.pretty_print(f'\[b]{name}\[o] finds themself in the middle of a field.')
lib.pretty_print('Your action verbs are \[b]{}\[o]'.format(' '.join(verbs)))
lib.pretty_print('Your possible movements are \[b]{}\[o]'.format(
    ' '.join(directions)))


def main_loop():
    gameover: bool = False
    while not gameover:
        usr_input = input(prefix).lower()
        lib.check_input(usr_input, player)
        #		dead=True
        gameover = player.game_over
Ejemplo n.º 18
0
#!/usr/bin/env python

import main, time, subprocess, lib

logfile = open("server_log.tmp", "w")

subprocess.Popen("./runStanfordParserServer.sh", shell=True, stdout=logfile, stderr=logfile)

lib.pretty_print ("waiting for server")
time.sleep(30)
lib.pretty_print ("done!")

main.main()
Ejemplo n.º 19
0
 def use(self, item):
     if item in items:
         lib.pretty_print(item.interaction)
     else:
         lib.pretty_print("You don't have that item")
Ejemplo n.º 20
0
 def look(self):
     lib.pretty_print(self.desc)
Ejemplo n.º 21
0
 def look(self, player):
     lib.pretty_print(self.desc)
     self.print_exits()
     self.print_items()
     self.print_mobs()
Ejemplo n.º 22
0
 def grab(self):
     lib.pretty_print(self.grab_desc)
Ejemplo n.º 23
0
 def interact(self):
     lib.pretty_print(self.interaction)