Пример #1
0
def New_Game():
    get_name()
    ECS_Storage.init()
    CM.new_Component('Poison')
    config.DungeonLevelIds = {}
    config.CurrentDungeonLevel = 0
    config.PlayerId = EM.new_Id()
    config.PlayerAttack = EM.new_Id()
    config.fov_recompute = True
    config.game_msg = []
    config.game_state = 'playing'
    config.xptolevel = 66.6
    CM.new_Component('ToLevel')
    CM.add_Component(config.PlayerId, 'Tile', Tile('Player', '@', False,
                                                   True, Color.sky))
    CM.add_Component(config.PlayerId, 'Coord',
                     Coord(config.playscreen_width / 2,
                           config.playscreen_height / 2))
    deatheffects = [player_death]
    CM.add_Component(config.PlayerId, 'Death',
                     Death('You have died. What a pity.' +
                           ' Did you even manage to get any loot?',
                           '%', effects=deatheffects))
    CM.add_Component(config.PlayerId, 'Creature', Creature(10, 0, 10,
                                                           10, 7, 0,
                                                           special={}))
    CM.add_Component(config.PlayerId, 'Level', Level())
    CM.add_Component(config.PlayerAttack, 'Attack', Attack(1, 4))
    next_level()
    Message('Welcome young adventurer! You have just entered my dungeon and' +
            ' through my deal with the adventurers guild you may explore my' +
            ' first 12 levels! Though of course everything will still try to' +
            ' kill you but atleast once finish there is an easy passage out!',
            Color.red)
Пример #2
0
def common_view_data():
    em = EntityManager()

    data = {
        'logged_in_user': em.find_one_by_id('User', bottle.request.session.user_id)
    }

    return data
Пример #3
0
    def __init__(self):
        print("Press Ctrl-C to quit")

        self.gamepad = GamePad()
        self.screen = Screen()
        self.entityManager = EntityManager()
        self.player = Player(self)
        self.world = World(self)
        self.entityManager.add(self.player)
Пример #4
0
def delete_messages(messageIds, deleted_by_user_id):
    if messageIds:
        em = EntityManager()

        for id in messageIds:
            m = em.find_one_by_id('Message', id)

            if m and str(m.for_user_id) == str(deleted_by_user_id):
                em.remove_one('Message', id)
Пример #5
0
    def DispatchDelayedMessages(self):
        #get current time
        CurrentTime = datetime.datetime.now().time()

        #now peek at the queue to see if any telegrams need dispatching.
        #remove all telegrams from the front of the queue that have gone
        #past their sell by date
        while (PriorityQ.isEmpty() is
               False) & (PriorityQ.last().DispatchTime <
                         CurrentTime) & (PriorityQ.last().DispatchTime > 0):
            #read the telegram from the front of the queue

            telegram = PriorityQ.last()

            #find the recipient
            pReceiver = EntityManager.getInstance().GetEntityFromID(
                telegram.Receiver)

            print("\nQueued telegram ready for dispatch: Sent to " +
                  EntityNames.GetNameOfEntity(pReceiver.ID()) + ". Msg is " +
                  MessageTypes.MsgToStr(telegram.Msg))

            #send the telegram to the recipient
            self.Discharge(pReceiver, telegram)

            #remove it from the queue
            PriorityQ.remove(PriorityQ.last())
Пример #6
0
def SetupMonitors():
    # Setup manager
    entityManager = EntityManager(config)

    # If I have not a list of monitors, I setup only a monitor
    if (consts.CONFIG_MONITORS_KEY not in config):
        monitor = Monitor(config, config, entityManager)
    else:  # More Monitors
        # Now setup monitors
        monitor_id = 0
        for monitor_config in config[consts.CONFIG_MONITORS_KEY]:
            monitor_id += 1
            monitor = Monitor(monitor_config, config, entityManager,
                              monitor_id)

    # Start sensors loop
    entityManager.Start()
Пример #7
0
    def __init__(self, key):
        """Constructor for a client object
    """
        self.key = key
        self.dictionaryManager = DictionaryManager(key)
        self.entityManager = EntityManager(key)
        self.conceptManager = ConceptManager(key)
        self.modelManager = ModelManager(key)
        self.categoryManager = CategoryManager(key)

        # Default parameter values for /semantic_tagging
        self.fields = ''
        self.filter_data = 'y'

        # Default parameter values for /check
        self.mode = 'all'
        self.group_errors = '2'
        self.check_spacing = 'n'
Пример #8
0
def create_stairs(dungeonlevelid):
    stairs = EM.new_Id()
    CM.add_Component(stairs, 'Tile', Tile('Stairs Down', '>', True,
                                          True, Color.map_tile_visible))
    CM.add_Component(stairs, 'Coord', Coord(config.playscreen_width / 2,
                                            config.playscreen_height / 2))
    CM.add_Component(stairs, 'ToLevel', ToLevel(2))
    CM.add_Component(stairs, 'Seen', Seen(seen=True))
    dungeonlevelid = config.DungeonLevelIds[config.CurrentDungeonLevel]
    firstlevel = CM.get_Component('DungeonLevel', dungeonlevelid)
    firstlevel.FeatureIds.append(stairs)
Пример #9
0
def log():
    lat = bottle.request.POST.get('lat')
    lng = bottle.request.POST.get('lng')

    l = Location()
    l.lat = lat
    l.lng = lng 

    em = EntityManager()

    userdata = em.find_one('UserData', {'user_id':bottle.request.session.user_id})
    if not userdata:
        userdata = UserData()
        userdata.user_id = bottle.request.session.user_id
        userdata.health = 100

    userdata.location = l

    em.save('UserData', userdata)

    return ''
Пример #10
0
def make_imp(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Imp', 'i', False, True,
                          color=Color.red))
    CM.add_Component(newmonsterid, 'Death',
                     Death('The dead imp quickly fades from reality.',
                           '.', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(20, 0, 10, 18, 4, 79))
    CM.add_Component(newmonsterid, 'Action', Imp_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #11
0
def make_bat(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Bat', 'b', False, True,
                          color=Color.dark_gray))
    CM.add_Component(newmonsterid, 'Death',
                     Death('The small bat lets out one final pitiful squeak.',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(3, 0, 8, 10, 5, 15))
    CM.add_Component(newmonsterid, 'Action', Bat_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #12
0
def index():
    timeout_counter = 0

    if bottle.request.GET.getall('readIds[]'):
        delete_messages(bottle.request.GET.getall('readIds[]'), bottle.request.session.user_id)

    messages = get_messages(bottle.request.session.user_id)

    while not messages:
        timeout_counter += 1

        messages = get_messages(bottle.request.session.user_id)

        if timeout_counter > 100:
            return ''
        else:
            time.sleep(0.2)

    em = EntityManager()

    bottle.response.content_type = 'text/json'
    return json.dumps({'messages':[em.entity_to_json_safe_dict(m) for m in messages]})
Пример #13
0
def make_kangaroo(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Kangaroo', 'k', False, True,
                          color=Color.dark_sepia))
    CM.add_Component(newmonsterid, 'Death',
                     Death('This kangaroo won\'t be hopping anymore.',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(10, 0, 10, 25, 10, 73))
    CM.add_Component(newmonsterid, 'Action', Kangaroo_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #14
0
def make_lion(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Lion', 'l', False, True,
                          color=Color.yellow))
    CM.add_Component(newmonsterid, 'Death',
                     Death('Dead on the floor a lion lays.',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(30, 2, 10, 15, 6, 81))
    CM.add_Component(newmonsterid, 'Action', Lion_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #15
0
def make_dog(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Dog', 'd', False, True,
                          color=Color.darker_yellow))
    CM.add_Component(newmonsterid, 'Death',
                     Death('The little doggie wimpers as it falls over.',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(12, 1, 14, 8, 5, 26, special={'Dodge': 10}))
    CM.add_Component(newmonsterid, 'Action', Dog_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #16
0
def make_frog(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Frog', 'f', False, True,
                          color=Color.lighter_green))
    CM.add_Component(newmonsterid, 'Death',
                     Death('Squished frog, how droll.',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(10, 0, 5, 20, 5, 61))
    CM.add_Component(newmonsterid, 'Action', Frog_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #17
0
def make_hawk(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Hawk', 'h', False, True,
                          color=Color.darker_orange))
    CM.add_Component(newmonsterid, 'Death',
                     Death('The dead hawk flutters to the ground dead.',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(10, 0, 10, 25, 10, 73))
    CM.add_Component(newmonsterid, 'Action', Hawk_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #18
0
    def DispatchMessage(self, delay, sender, receiver, msg, ExtraInfo):

        #get pointers to the sender and receiver
        pSender = EntityManager.getInstance().GetEntityFromID(sender)
        pReceiver = EntityManager.getInstance().GetEntityFromID(receiver)

        #make sure the receiver is valid
        if pReceiver is None:
            print("\nWarning! No Receiver with ID of " + receiver + " found")
            return

        #create the telegram
        telegram = Telegram(0, sender, receiver, msg, ExtraInfo)

        #if there is no delay, route telegram immediately
        if delay <= 0.0:
            print("\nInstant telegram dispatched at time: " +
                  datetime.datetime.now().time() + " by " +
                  EntityNames.GetNameOfEntity(pSender.ID()) + " for " +
                  EntityNames.GetNameOfEntity(pReceiver.ID()) + ". Msg is " +
                  MessageTypes.MsgToStr(msg))

            #send the telegram to the recipient
            self.Discharge(pReceiver, Telegram)
        #else calculate the time when the telegram should be dispatched
        else:
            CurrentTime = datetime.datetime.now().time()

            telegram.DispatchTime = CurrentTime + delay

            #and put it in the queue
            self.PriorityQ.add(Telegram)

            print("\nDelayed telegram from " +
                  EntityNames.GetNameOfEntity(pSender.ID()) +
                  " recorded at time " + datetime.datetime.now().time() +
                  " for " + EntityNames.GetNameOfEntity(pReceiver.ID()) +
                  ". Msg is " + MsgToStr(msg))
Пример #19
0
def make_elephant(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Elephant', 'e', False, True,
                          color=Color.gray))
    CM.add_Component(newmonsterid, 'Death',
                     Death('Before like an angry mountain this elephant ' +
                           'is now just a boulder.',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(30, 1, 10, 5, 7, 42))
    CM.add_Component(newmonsterid, 'Action', Elephant_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #20
0
def make_ant(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Ant', 'a', False, True,
                          color=Color.darker_red))
    CM.add_Component(newmonsterid, 'Death',
                     Death('The ants shell now smashed gives way ' +
                           'as it breaths it\'s final breath',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(1, 5, 10, 5, 5, 8))
    CM.add_Component(newmonsterid, 'Action', Ant_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #21
0
def make_jellyfish(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Jellyfish', 'j', False, True,
                          color=Color.white))
    CM.add_Component(newmonsterid, 'Death',
                     Death('The jellyfish splats onto the floor. Wonder ' +
                           'how it was floating in the first place.',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(10, 10, 10, 10, 4, 84))
    CM.add_Component(newmonsterid, 'Action', Jellyfish_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #22
0
def make_hobgoblin(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Hobgoblin', 'G', False, True,
                          color=Color.dark_green))
    deatheffects = [death_cleanup, hobs_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('Hobgoblins die like goblins, just darker.',
                           '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(30, 3, 12, 10, 8, 272))
    CM.add_Component(newmonsterid, 'Action', Goblin_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #23
0
def make_goblin(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Goblin', 'g', False, True,
                          color=Color.green))
    CM.add_Component(newmonsterid, 'Death',
                     Death('A dead goblin, now this is ' +
                           'generic adventuring fair!',
                           '~', effects=[death_cleanup]))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(20, 2, 10, 10, 8, 68))
    CM.add_Component(newmonsterid, 'Action', Goblin_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #24
0
def make_poison_frog(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Poison Frog', 'F', False, True,
                          color=Color.red))
    deatheffects = [death_cleanup, poison_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('Congradulations! You didn\'t even need a blender.',
                           '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(20, 0, 10, 21, 5, 244))
    CM.add_Component(newmonsterid, 'Action', Frog_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #25
0
def make_pink_elephant(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Pink Elephant', 'E', False, True,
                          color=Color.pink))
    deatheffects = [death_cleanup, pink_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('The Pink Elephant disapeers. Now you just ' +
                           'have to ask, was it there to begin with?',
                           '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(60, 2, 10, 5, 7, 168))
    CM.add_Component(newmonsterid, 'Action', Elephant_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #26
0
def make_blue_imp(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Blue Imp', 'I', False, True,
                          color=Color.blue))
    deatheffects = [death_cleanup, blue_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('The Blue Imp\'s body bursts into a ' +
                           'flame and burns away to nothing.',
                           '.', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(25, 1, 10, 20, 4, 316))
    CM.add_Component(newmonsterid, 'Action', Imp_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #27
0
def make_savage_hawk(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Savage Hawk', 'H', False, True,
                          color=Color.dark_crimson))
    deatheffects = [death_cleanup, savage_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('The Savage Hawks eye dim as it ' +
                           'falls to the ground.',
                           '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(12, 0, 10, 30, 10, 293))
    CM.add_Component(newmonsterid, 'Action', Hawk_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #28
0
def make_queen_ant(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Queen Ant', 'A', False, True,
                          color=Color.silver))
    deatheffects = [death_cleanup, queens_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('The Ant Queen shudders and slumps over now dead.' +
                           ' The once majestic creature now pitiful.',
                           '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(5, 10, 10, 5, 4, 32))
    CM.add_Component(newmonsterid, 'Action', Ant_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #29
0
def make_dire_lion(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Dire Lion', 'L', False, True,
                          color=Color.dark_yellow))
    deatheffects = [death_cleanup, dire_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('The Dire Lions no longer able to support ' +
                           'itself slumps to the ground.',
                           '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(30, 6, 12, 20, 6, 324))
    CM.add_Component(newmonsterid, 'Action', Lion_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #30
0
def make_vampire_bat(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Vampire Bat', 'B', False, True,
                          color=Color.gray))
    deatheffects = [death_cleanup, vampires_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('The Vampire Bat falls to the floor.' +
                           ' The once dread creature is no more.',
                           '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(6, 0, 10, 11, 5, 60))
    CM.add_Component(newmonsterid, 'Action', Bat_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #31
0
def make_electric_kangaroo(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Electric Kangaroo', 'K', False, True,
                          color=Color.cyan))
    deatheffects = [death_cleanup, electric_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('The Electric Kangaroos eye dim as it ' +
                           'falls to the ground.',
                           '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(12, 0, 10, 30, 10, 293))
    CM.add_Component(newmonsterid, 'Action', Kangaroo_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #32
0
def make_rabid_dog(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Rabid Dog', 'D', False, True,
                          color=Color.dark_yellow))
    deatheffects = [death_cleanup, rabid_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('The Rabid Dog foams at the mouth then slumps ' +
                           'over. It might be a dog eat dog world but ' +
                           'don\'t eat it.', '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(16, 2, 14, 6, 5, 104))
    CM.add_Component(newmonsterid, 'Action', Dog_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
Пример #33
0
def make_clear_jellyfish(coord, dungeonlevel):
    newmonsterid = EM.new_Id()
    CM.add_Component(newmonsterid, 'Coord', coord)
    CM.add_Component(newmonsterid, 'Tile',
                     Tile('Clear Jellyfish', 'J', False, True,
                          color=Color.map_tile_visible))
    deatheffects = [death_cleanup, clear_choice]
    CM.add_Component(newmonsterid, 'Death',
                     Death('The Clear Jellyfishs falls but upward.' +
                           'How weird...',
                           '~', effects=deatheffects))
    CM.add_Component(newmonsterid, 'Creature',
                     Creature(10, 10, 10, 15, 4, 336))
    CM.add_Component(newmonsterid, 'Action', Jellyfish_AI(newmonsterid))
    dungeonlevel.MonsterIds.append(newmonsterid)
	def __init__(self,key):
		""" Constructor for a client object """
		self.key = key;
		self.dictionaryManager = DictionaryManager(key)
		self.entityManager      = EntityManager(key)
		self.conceptManager     = ConceptManager(key)
		self.modelManager       = ModelManager(key)
		self.categoryManager    = CategoryManager(key)

		# Default parameter values for /semantic_tagging 
		self.fields = ''
		self.filter_data = 'y'

		# Default parameter values for /check 
		self.mode = 'all'
		self.group_errors = '2'
		self.check_spacing = 'n' 
Пример #35
0
    def call(self, entity, placeHolder, paramters):
        if not isinstance(paramters, dict):
            _logger.warn('call: paramter decode failed in RPC %s(%s)', self.func.__name__, str(self.argTypes))
            return
        args = []
        first = True

        autoParameters = paramters.get('_')
        if autoParameters:
            paramters = autoParameters
            if self.argTypes:
                paramters = autoParameters[0]
            else:
                return self.func(entity, *autoParameters)

        for argType in self.argTypes:
            if first:
                first = False
                if isinstance(argType, Avatar):
                    avatar = EntityManager.getEntity(placeHolder)
                    args.append(avatar)
                    continue
                elif isinstance(argType, MailBox):
                    args.append(placeHolder)
                    continue

            try:
                arg = paramters[argType.getName()]
            except KeyError:
                _logger.warn('call: paramter %s not found in RPC %s, use default value', argType.getName(), self.func.__name__)
                arg = argType.defaultValue()

            try:
                if arg == None and argType.getType() == 'Uuid':
                    arg = None
                else:
                    arg = argType.convert(arg)
            except ConvertError as e:
                _logger.error('call: paramter %s cannot convert input %s for RPC %s exception %s', argType.getName(), str(arg), self.func.__name__, str(e))
                return
            args.append(arg)

        return self.func(entity, *args)
Пример #36
0
from Miner import Miner
from MinersWife import MinersWife
from EntityNames import EntityNames
from EntityManager import EntityManager
import time

# create a miner
Bob = Miner(EntityNames.ent_Miner_Bob)

# create his wife
Elsa = MinersWife(EntityNames.ent_Elsa)

#register them with the entity manager
#EntityMgr = EntityManager()
EntityManager.getInstance().RegisterEntity(Bob)
EntityManager.getInstance().RegisterEntity(Elsa)

for x in range(0, 20):
    Bob.Update()
    Elsa.Update()
    time.sleep(1)
Пример #37
0
class Game:

    gamepad = None
    player = None
    screen = None
    entityManager = None
    world = None

    FRAMES_PER_SECOND = 25

    game_is_running = False

    def __init__(self):
        print("Press Ctrl-C to quit")

        self.gamepad = GamePad()
        self.screen = Screen()
        self.entityManager = EntityManager()
        self.player = Player(self)
        self.world = World(self)
        self.entityManager.add(self.player)

    def update(self, dt):

        self.gamepad.update()

        if (self.gamepad.pressed[GAMEPAD_BUTTON.START]):
            self.game_is_running = False
            return

        self.world.update()
        self.entityManager.update(dt)

    def draw(self):
        self.screen.clear()
        self.world.draw()
        self.entityManager.draw()
        self.screen.draw()

    def start(self):
        print("GO!")
        self.loop()

    def loop(self):

        self.game_is_running = True

        lastFrameTime = time.time()

        try:
            while self.game_is_running:
                currentTime = time.time()
                dt = currentTime - lastFrameTime

                sleepTime = 1. / self.FRAMES_PER_SECOND - (currentTime -
                                                           lastFrameTime)

                if sleepTime > 0:
                    time.sleep(sleepTime)

                self.update(dt)
                self.draw()

                lastFrameTime = currentTime
            self.screen.off()
        except KeyboardInterrupt:
            self.screen.off()
            sys.exit()
Пример #38
0
                if filterManaBar:
                    if h >= 4:
                        pass
                    else:
                        toPop.append(i)
            else:
                toPop.append(i)
        else:
            toPop.append(i)
    for i in sorted(toPop,reverse=True):
        mc.pop(i)
    return mc

wName="Controls"
wImageName="Image"
entityManager = EntityManager()
lower = np.array([162,183,186], dtype="uint8")
upper = np.array([179, 255, 219], dtype="uint8")
lowerBlue = np.array([77, 188, 167], dtype="uint8")
upperBlue = np.array([123, 255, 255], dtype="uint8")
# lower = np.array([158, 204, 4], dtype="uint8")
# upper = np.array([179, 255, 255], dtype="uint8")
# lowerBlue = np.array([73, 50, 182], dtype="uint8")
# upperBlue = np.array([109, 219, 255], dtype="uint8")
lowerGreen = np.array([36 ,145,189], dtype="uint8")
upperGreen = np.array([82,243,223], dtype="uint8")
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5))
cv2.namedWindow(wName,cv2.WINDOW_AUTOSIZE)
cv2.createTrackbar('AspectRatio',wName,1,1000,nothing)
cv2.setTrackbarPos('AspectRatio', wName, minAspectRatioThreshold)
cv2.createTrackbar('minArea',wName,1,1000,nothing)
Пример #39
0
class SemPubClient:
    def __init__(self, key):
        """Constructor for a client object
    """
        self.key = key
        self.dictionaryManager = DictionaryManager(key)
        self.entityManager = EntityManager(key)
        self.conceptManager = ConceptManager(key)
        self.modelManager = ModelManager(key)
        self.categoryManager = CategoryManager(key)

        # Default parameter values for /semantic_tagging
        self.fields = ''
        self.filter_data = 'y'

        # Default parameter values for /check
        self.mode = 'all'
        self.group_errors = '2'
        self.check_spacing = 'n'

    # Setters for configuration parameters
    def setAnalysisFields(self, fields):
        self.fields = fields

    def setAnalysisFilterData(self, filter_data):
        self.filter_data = filter_data

    def setCheckMode(self, mode):
        self.model = mode

    def setCheckGroupErrors(self, group_errors):
        self.group_errors = group_errors

    def setCheckSpacing(self, check_spacing):
        self.check_spacing = check_spacing

    def __parseResponse(self, response):
        """
      Helper method that parses the result or throws an Exception if the service returns an error
    """

        if response.status_code == requests.codes.ok:
            r = response.json()
            return r['result']
        else:
            r = response.json()
            raise SemPubException(response.status_code, r['status'])

        # Semantic tagging service operations
    def analyzeDocument(self, document, dictionary=None, models=None):
        """ Returns the text of the document analyzed including all the extracted semantic information. 
      It takes into account document metadata (language, source, timeref) to build a more accurate analysis
      
      :param document: :class:'Document' to be analyzed 
      :param dictionary (optional): a user defined :class:'Dictionary' to include for tagging 
      :param models (optional): a list of user defined :class:'Model: to include for classification
    """
        payload = {
            'key': self.key,
            'doc': str(document),
            'filter_data': self.filter_data,
            'fields': self.fields
        }
        if (dictionary is not None):
            payload['dictionary'] = dictionary['name']
        if (models is not None):
            if (isinstance(models, list)):
                modelnames = map(lambda x: x['name'], models)
                payload['model'] = modelnames
            else:
                payload['model'] = models['name']
        payload['src'] = 'sdk-python-1.0'
        endpoint = TAGGING_SERVICE_ENDPOINT
        response = requests.post(endpoint, data=payload)
        return self.__parseResponse(response)

    def analyzeText(self, text, lang, dictionary=None, models=None):
        """ Returns the text analyzed including all the extracted semantic information
      
      :param text: text to be analyzed 
      :param lang: language of the text 
      :param dictionary (optional): a user defined :class:'Dictionary' to include for tagging 
      :param models (optional): a list of user defined :class:'Model: to include for classification
    """
        doc = Document(1, text)
        doc['language'] = lang
        return self.analyzeDocument(doc, dictionary, models)

    # Text proofreading service operations
    def checkDocument(self, document, doc_offset=0, dictionary=None):
        """ Returns the proofreading issues found in the document text 
      It takes into account document metadata (language)
      
      :param document: :class:'Document' to be analyzed 
      :param doc_offset: offset in characters from where to start proofreading 
      :param dictionary (optional): a user defined :class:'Dictionary' that marks words in our dictionary as known 
    """
        payload = {
            'key': self.key,
            'doc': str(document),
            'doc_offset': doc_offset,
            'mode': self.mode,
            'group_errors': self.group_errors,
            'check_spacing': self.check_spacing
        }
        if (dictionary is not None):
            payload['dictionary'] = dictionary['name']
        payload['src'] = 'sdk-python-1.0'
        endpoint = CHECK_SERVICE_ENDPOINT
        response = requests.post(endpoint, data=payload)
        return self.__parseResponse(response)

    def checkText(self, text, lang, doc_offset=0, dictionary=None):
        """ Returns the proofreading issues found in the text
      
      :param text: text to be analyzed 
      :param lang: language of the text
      :param doc_offset: offset in characters from where to start proofreading 
      :param dictionary (optional): a user defined :class:'Dictionary'that marks words in our dictionary as known 
    """
        doc = Document(1, text)
        doc['language'] = lang
        return self.checkDocument(doc, doc_offset, dictionary)

    # CRUD operations on Dictionary
    def getDictionaryList(self, query, lang):
        """ List of user-defined dictionaries

      :param query: regular expresion to filter dictionaries
      :param lang: filter dictionaries in this language, use 'all' if a multilingual dictionary  
    """
        return self.dictionaryManager.getList(query, lang)

    def createDictionary(self, dictionary):
        return self.dictionaryManager.create(dictionary)

    def readDictionary(self, name):
        return self.dictionaryManager.read(name)

    def updateDictionary(self, dictionary):
        return self.dictionaryManager.update(dictionary)

    def deleteDictionary(self, name):
        return self.dictionaryManager.delete(name)

    def deleteDictionary(self, dictionary):
        return self.dictionaryManager.delete(dictionary.getId())

    # CRUD operations on Entity
    def getEntityList(self, dictionary, query):
        """ Shows a list of entities (:class:'Entity') included in the dictionary matching the query  

      :param dictionary: a :class:'Dictionary' object 
      :param query: a regular expression
    """
        return self.entityManager.getList(dictionary.getId(), query)

    def createEntity(self, entity, dictionary):
        return self.entityManager.create(entity, dictionary.getId())

    def readEntity(self, id, dictionary):
        return self.entityManager.read(id, dictionary.getId())

    def updateEntity(self, entity, dictionary):
        return self.entityManager.update(entity, dictionary.getId())

    def deleteEntity(self, id, dictionary):
        return self.entityManager.delete(id, dictionary.getId())

    def deleteEntity(self, entity, dictionary):
        return self.entityManager.delete(entity.getId(), dictionary.getId())

        # CRUD operations on Concept
    def getConceptList(self, dictionary, query):
        """ Shows a list of concepts (:class:'Concept') included in the dictionary matching the query  

      :param dictionary: a :class:'Dictionary' object 
      :param query: a regular expression
    """
        return self.conceptManager.getList(dictionary.getId(), query)

    def createConcept(self, concept, dictionary):
        return self.conceptManager.create(concept, dictionary.getId())

    def readConcept(self, id, dictionary):
        return self.conceptManager.read(id, dictionary.getId())

    def updateConcept(self, concept, dictionary):
        return self.conceptManager.update(concept, dictionary.getId())

    def deleteConcept(self, id, dictionary):
        return self.conceptManager.delete(id, dictionary.getId())

    def deleteConcept(self, concept, dictionary):
        return self.conceptManager.delete(concept.getId(), dictionary.getId())

        # CRUD operations on Model
    def getModelList(self, query, lang):
        """ List of user-defined models

      :param query: regular expresion to filter dictionaries
      :param lang: filter dictionaries in this language 
    """
        return self.modelManager.getList(query, lang)

    def createModel(self, model):
        return self.modelManager.create(model)

    def readModel(self, name):
        return self.modelManager.read(name)

    def updateModel(self, model):
        return self.modelManager.update(model)

    def deleteModel(self, name):
        return self.modelManager.delete(name)

    def deleteModel(self, model):
        return self.modelManager.delete(model.getId())

    # CRUD operation on Category
    def getCategoryList(self, model, query):
        """ Show a list of categories (:class:'Category') included in the model matching the query  

      :param model: a :class:'Model' object 
      :param query: a regular expression
    """
        return self.categoryManager.getList(model.getId(), query)

    def createCategory(self, category, model):
        return self.categoryManager.create(category, model.getId())

    def readCategory(self, id, model):
        return self.categoryManager.read(id, model.getId())

    def updateCategory(self, category, model):
        return self.categoryManager.update(category, model.getId())

    def deleteCategory(self, id, model):
        return self.categoryManager.delete(id, model.getId())

    def deleteCategory(self, category, model):
        return self.categoryManager.delete(category.getId(), model.getId())