def create_hero(hero_name, universe):
     hero = Hero()
     hero.name = hero_name
     hero.description = '{0} description'.format(hero_name)
     hero.universe = universe
     hero.save()
     return hero
Example #2
0
def test_hero_initialize():
    test_dice = Dice([0])
    test_hero = Hero(test_dice)

    assert test_hero.hp == hero_config.BASE_HP
    assert test_hero.sp == hero_config.BASE_SP
    assert test_hero.dp == 0
Example #3
0
def test_1():
    map = Map("ressource/map01.txt")
    assert len(map.start) == 1
    assert len(map.goal) == 1
    toto = Hero(map)
    toto.position = map.start[0]
    assert toto.position.getx == 0
    assert toto.position.gety == 0
    toto.move('left')  # outside the map
    assert toto.position.getx == 0
    assert toto.position.gety == 0
    toto.move('up')  # outside the map
    assert toto.position.getx == 0
    assert toto.position.gety == 0
    toto.move('right')  # in the wall
    assert toto.position.getx == 0
    assert toto.position.gety == 0
    toto.move('down')  # OK
    assert toto.position.getx == 1  # new x
    assert toto.position.gety == 0

    map.items.append(Position(5, 5))  # put an Item in the list
    len_items = len(map.items)
    toto.position = Position(4, 5)  # put the hero near the item
    toto.move('down')  # move onto the new items
    print('coucou {}'.format(toto.position))
    assert len_items == len(
        map.items) + 1  # the item  has been removed from the list
Example #4
0
    def test_save_and_get_hero(self):
        """Test save and get hero"""
        # Criando o novo heroi
        new_hero = Hero()
        new_hero.name = 'Superman'
        new_hero.description = 'Superman'
        new_hero.universe = 'dc'
        new_hero.save()

        # Obtendo o heroi pelo id
        hero = Hero.get_hero(new_hero.id)
        self.assertEqual(hero.name, 'Superman')
        self.assertEqual(hero.id, new_hero.id)
Example #5
0
    def create(cls, params):
        """"""
        if not params.get('name'):
            return {'error': str('name is required')}, 400
        if not params.get('universe'):
            return {'error': str('universe is required')}, 400

        hero = Hero()
        hero.name = cls.title_case(params.get('name'))
        hero.image_url = cls.title_case(params.get('imageUrl'))
        hero.description = cls.title_case(params.get('description'))
        hero.universe = cls.title_case(params.get('universe'))
        hero.save()

        return hero.to_dict()
Example #6
0
 def create(params):
     """
     Create a new hero
     :param dict params: Request dict params
     :return Hero: Hero created
     """
     hero = Hero()
     hero.name = params['name']
     hero.description = params['description']
     hero.imageUrl = params['imageUrl']
     hero.universe = params['universe']
     HeroModule.format_hero_params(hero)
     HeroModule.valid_hero_params(hero)
     hero.save()
     return hero
Example #7
0
    def __init__(self):
        pygame.init()

        self.laby = Laby()
        self.hero = Hero(self.laby)
        self.needle = Item("needle", self.laby)
        self.ether = Item("Ether", self.laby)
        self.tube = Item("Tube", self.laby)

        self.screen = pygame.display.set_mode((480, 520))
        self.title_screen = title_screen
        self.logo_screen = logo_screen

        self.background = pygame.Surface((710, 700))
        self.background.fill((255, 255, 255))
        self.start_img = start
        self.end_img = end

        self.wall = walls

        for wall in self.laby.walls:
            x, y = wall
            self.background.blit(self.wall, (x * sprite_size, y * sprite_size))

        self.path = paths
        for path in self.laby.paths:
            x, y = path
            self.background.blit(self.path, (x * sprite_size, y * sprite_size))

        self.end_pos = end
        for end_pos in self.laby.end:
            x, y = end_pos
            self.background.blit(self.end_pos,
                                 (x * sprite_size, y * sprite_size))

        self.allsprites = pygame.sprite.Group()
        self.allsprites.add(ItemSprite(self.needle, needle))
        self.allsprites.add(ItemSprite(self.ether, ether))
        self.allsprites.add(ItemSprite(self.tube, tube))
        self.allsprites.add(HeroSprite(self.hero))

        pygame.display.update()
Example #8
0
def main():
    """
    parse parameters.
    The init is done here :
    - The map object remain the same in text or graphic mode --> instantiated at the begining and once
    - the hero and the output (text or graphic) mode are also instantiated here
        (toto is for the film 'toto le heros')
    """

    args = parse_arguments()
    map = Map(MAP_FILE)
    if args.text:
        clear()
        toto = Hero(map)
        game_text(map, toto)
    else:
        clear()
        pygame.init()
        screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGTH))
        toto = HeroGraph(map)
        game_graphic(map, toto, screen)
Example #9
0
    def start(self):
        '''
        Setting up the elements of the game
        '''
        # We set up all the elements
        labyrinthe = Map()
        labyrinthe.load_map_data('map.csv')
        df = labyrinthe.create_dataframe()
        labyrinthe.items_random_position()
        start = list(labyrinthe.start)
        mcgyver = Hero(int(start[0].position[0] / CELL_SIZE),
                       int(start[0].position[1] / CELL_SIZE), HERO_CELL,
                       'hero.png')
        interface.display_map(labyrinthe)
        interface.display_items(labyrinthe)
        interface.display_text_zone1()

        # We bring the hero to life
        running = True
        while running:
            interface.display_hero(mcgyver)
            interface.pyg_events(mcgyver, labyrinthe)
Example #10
0
def get_heroes_from_db():
    conn = sqlite3.connect(DB_DIR)
    cursor = conn.cursor()
    query = 'select id, name, hp, defence, speed, recovery, mind, path from Hero'
    cursor.execute(query)
    db_heroes = cursor.fetchall()

    query = '''
        select name, power, speed, cost, type, sacrifice, range, user 
        from Move
    '''
    cursor.execute(query)
    db_moves = cursor.fetchall()

    heroes = {}
    moves = []

    for db_hero in db_heroes:
        hero_id, name, hp, defence, speed, recovery, mind, img_path = db_hero
        hero = Hero(name, hp, defence, speed, recovery, mind, img_path)
        heroes[hero_id] = hero

    for db_move in db_moves:
        name, power, speed, cost, type_, sacrifice, range_, user = db_move
        assert range_ in ('target', 'area', 'self', 'self area')
        power = power if power else 0

        move = Attack(name, power, speed, cost, sacrifice, type_, range_)
        moves.append((user, move))

    for hero_id, move in moves:
        hero = heroes[hero_id]
        if move.speed is None:
            move.speed = hero.speed
            move.initial_speed = hero.speed
        hero.add_move(move)

    return list(heroes.values())