Example #1
0
async def create_characters(server):
    for member in server.members:
        if member == server.owner or member == client.user:
            continue
        elif member not in toons:
            if is_parse(member.nick):
                tag_nick = member.nick.split(" ")
                full_nick = " ".join(tag_nick[2:])
                toons[member] = Character(full_nick, tag_nick[1])
            else:
                nickname = "Name" if len(member.name) > 24 else member.name
                toons[member] = Character(nickname, 1)
            await client.change_nickname(member, toons[member].tag_nick)
Example #2
0
def run_game():
    pygame.init()
    game_settings = Settings()
    screen = Screen(game_settings)
    pygame.display.set_caption("BOMBERMAN")
    character = Character(game_settings, screen.screen, (0, 0))
    character2 = Character(game_settings, screen.screen, (1, 1))
    bombs_handler = BombsHandler(Group(), Group())
    obstacles = Group()
    hard_obstacles = Group()
    explosions = Group()
    treasures = Group()
    obstacle_placer = ObstaclePlacer()
    obstacle_placer.create_obstacles(game_settings, screen.screen, obstacles)
    obstacle_placer.create_hard_obstacles(game_settings, screen.screen,
                                          hard_obstacles)
    joystick = Joystick()
    smile_of_fate = SmileOfFate(game_settings)
    latest_choices = (0, 0)
    controller = Controller()
    while True:
        pygame.event.pump()
        controller.check_events(game_settings, screen.screen, character,
                                bombs_handler.bombs[0], character2,
                                bombs_handler.bombs[1])
        character.update(obstacles, hard_obstacles)
        if joystick.is_joystick():
            latest_choices = controller.check_joystick_events(
                character2, joystick.is_joystick(), latest_choices)
        character2.update(obstacles, hard_obstacles)
        bombs_handler.update_bombs(bombs_handler.bombs[0], game_settings,
                                   screen.screen, explosions, obstacles,
                                   treasures, smile_of_fate)
        bombs_handler.update_bombs(bombs_handler.bombs[1], game_settings,
                                   screen.screen, explosions, obstacles,
                                   treasures, smile_of_fate)
        bombs_handler.kill_your_heroes(explosions, character, character2)
        if len(obstacles.sprites()) < 5:
            treasures.empty()
            character.reset_character_status()
            character2.reset_character_status()
            obstacle_placer.create_obstacles(game_settings, screen.screen,
                                             obstacles)
        smile_of_fate.player_collected_treasure(character, treasures)
        smile_of_fate.player_collected_treasure(character2, treasures)
        screen.update_screen(game_settings, character, obstacles,
                             bombs_handler.bombs[0], character2,
                             bombs_handler.bombs[1], hard_obstacles,
                             explosions, treasures)
def random_character_entity(min_hp=10, max_defense=10, max_res=10):
    attrs = random_character_attributes(min_hp, max_defense, max_res)
    return Character(attrs['name'], attrs['pos'], attrs['sprite'], attrs['hp'],
                     attrs['defense'], attrs['res'], attrs['strength'],
                     attrs['attack_kind'], attrs['classes'],
                     attrs['equipments'], attrs['strategy'], attrs['lvl'],
                     attrs['skills'], attrs['race'], attrs['gold'],
                     attrs['interaction'])
 def spawn_starting_ai(self, app):
     # - 1 because we spawn the player character separately
     for _ in range(0, constants.CHARACTER_SPAWNER_MAX_CHARACTERS):
         controller = app.ai_controllers.pop()
         app.objects.append(
             Character(Helpers.get_random_pos(),
                       "AI {}".format(controller.index), controller))
         self.ai_spawned += 1
    def test_1_init_character(self):

        testothy = Character(id=123,
                             name="Testothy Jones",
                             properties={},
                             inventory={})

        self.assertEqual(testothy.name, 'Testothy Jones')
 def characters(self):
     """
     Get all characters in the account
     """
     characters = self.api.make_get_call(
         '/Destiny2/{}/Profile/{}'.format(self.api.membership_type,
                                          self.api.membership_id),
         {'components': '200'})['Response']['characters']['data']
     return [Character(self.api, x, self) for x in characters.values()]
Example #7
0
class Player:
    name: str
    team_name: str
    taken: int = 0
    left: int = PLAYER_STOCKS
    char: Character = Character('', bot=None)

    def set_char(self, char: Character) -> None:
        self.char = char

    def __str__(self) -> str:
        return f'{self.name} {self.char}'
    def test_2_add_character_to_db(self):

        session = Session()

        testothy = Character(id=123,
                             name="Testothy Jones",
                             properties={},
                             inventory={})

        session.add(testothy)
        session.commit()

        session.close()
    def test_4_attempt_to_create_duplicate_testothy(self):
        session = Session()

        with self.assertRaises(Exception):
            testothy = Character(id=123,
                                 name="Testothy Jones",
                                 properties={},
                                 inventory={})

            session.add(testothy)
            session.commit()

        session.close()
Example #10
0
    def create_new_character(self, dt):
        # switch to the character generation screen
        self.gui.clear()

        # init a blank character for us to send.
        self.character = Character()

        self.gui.add(CustomBackground())
        self.CharacterGenerationWindow = CharacterGenerationWindow()
        self.CharacterGenerationWindow.finish_button.push_handlers(
            on_click=self.send_completed_character)

        self.gui.add(self.CharacterGenerationWindow)
        self.state = "character_gen"
Example #11
0
    def __init__(self):
        super().__init__()

        self.game_over = False

        self.grid = Grid(num_tiles=9)
        self.add(self.grid)

        self.objects = {}

        self.create_game_over_text((Window.width, Window.height))

        # Add the character to the game
        self.character = Character(self)
        self.add(self.character)
    def update(self, app):
        current_time = pygame.time.get_ticks()

        if self.last_spawn + constants.CHARACTER_SPAWNER_COOLDOWN <= current_time:
            character_count = 0

            for obj in app.objects:
                if type(obj) is Character:
                    character_count += 1

            if character_count < constants.CHARACTER_SPAWNER_MAX_CHARACTERS:
                # print("SPAWNING NEW AI")
                controller = app.ai_controllers.pop()
                app.objects.append(
                    Character(Helpers.get_random_pos(),
                              "AI {}".format(controller.index), controller))
                self.ai_spawned += 1
                self.last_spawn = pygame.time.get_ticks()
Example #13
0
    def test_random_distribution(self, mocked_randint):
        c = Character()
        simulation = Simulation(
            Evaluator(actors=[c],
                      rules=[
                          Rule('rule1', [], [Predicate('p1', 0)], prob=1),
                          Rule('rule2', [], [Predicate('p2', 0)], prob=4)
                      ]))

        mocked_randint.return_value = 1
        simulation.step()
        self.assertStateContains(PredicateInstance('p1', c),
                                 simulation.evaluator)
        self.assertStateDoesNotContain(PredicateInstance('p2', c),
                                       simulation.evaluator)

        mocked_randint.return_value = 2
        simulation.step()
        self.assertStateContains(PredicateInstance('p1', c),
                                 simulation.evaluator)
        self.assertStateContains(PredicateInstance('p2', c),
                                 simulation.evaluator)
    def handle_new_character(self, ident, character_name, world_state):
        characters = world_state.characters
        worldmap = world_state.worldmap
        character = characters[character_name] = Character(character_name)

        character["position"] = worldmap.find_spawn_point_for_new_character()
        worldmap.put_object_at_position(character, character["position"])
        world_state.localmaps[
            character_name] = worldmap.get_chunks_near_position(
                character["position"])

        # give the character their starting items by referencing their profession.
        profession = self.profession_manager.get_profession(
            character["profession"]["ident"])
        self.equip_items(profession, character)
        self.put_items_in_containers(profession, character)

        character_dir = f"./accounts/{ident}/characters"
        os.makedirs(character_dir, exist_ok=True)

        character_resource_path = f"{character_dir}/{character_name}.character"
        with open(character_resource_path, "w") as fp:
            json.dump(character, fp)
            print(f"New character added to world: {character_name}")
Example #15
0
def load_ally(ally, from_save, gap_x, gap_y):
    name = ally.find('name').text.strip()
    infos = etree.parse('data/characters.xml').find(name)

    entity_attributes = load_artificial_entity(ally, infos, from_save, gap_x,
                                               gap_y)

    # Static data character
    race = infos.find('race').text.strip()
    classes = [infos.find('class').text.strip()]
    interaction_el = infos.find('interaction')
    dialog = []
    for talk in interaction_el.findall('talk'):
        dialog.append(talk.text.strip())
    interaction = {
        'dialog': dialog,
        'join_team': interaction_el.find('join_team') is not None
    }

    # Dynamic data character
    dynamic_data = infos
    if from_save:
        dynamic_data = ally
    gold = int(dynamic_data.find('gold').text.strip())

    equipments = []
    for eq in dynamic_data.findall('equipment/*'):
        equipments.append(parse_item_file(eq.text.strip()))

    if from_save:
        skills = [(load_skill(skill.text.strip())
                   if not skill.text.strip() in skills_infos else
                   skills_infos[skill.text.strip()])
                  for skill in dynamic_data.findall('skills/skill/name')]
    else:
        skills = Character.classes_data[
            classes[0]]['skills'] + Character.races_data[race]['skills']

    loaded_ally = Character(
        entity_attributes['name'], entity_attributes['position'],
        entity_attributes['sprite'], entity_attributes['hp'],
        entity_attributes['defense'], entity_attributes['resistance'],
        entity_attributes['strength'], classes, equipments,
        entity_attributes['strategy'], entity_attributes['level'], skills,
        race, gold, interaction)

    inventory = infos.find('inventory')
    if inventory is not None:
        for it in inventory.findall('item'):
            item = parse_item_file(it.text.strip())
            loaded_ally.set_item(item)

    if from_save:
        current_hp = int(ally.find('current_hp').text.strip())
        loaded_ally.hp = current_hp

        xp = int(ally.find('exp').text.strip())
        loaded_ally.earn_xp(xp)
    else:
        # Up stats according to current lvl
        loaded_ally.stats_up(entity_attributes['level'] - 1)
        # Restore hp due to lvl up
        loaded_ally.healed()

    return loaded_ally
Example #16
0
async def on_member_join(member):
    nickname = "Name" if len(member.name) > 24 else member.name
    toons[member] = Character(nickname, 1)
    await client.change_nickname(member, toons[member].tag_nick)
    await change_member_role(member)
 def spawn_starting_player(self, app):
     return Character(Helpers.get_random_pos(), "Player",
                      PlayerController())
def run_game():
    # 初始化背景设置
    pygame.init()

    # 创建游戏设置类的实例
    ai_settings = Settings()

    # 创建屏幕
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))  # 创建surface对象
    pygame.display.set_caption("Alien Invasion")

    # 创建Play按钮
    play_button = Button(screen, "Play")

    # 创建一艘飞船
    ship = Ship(ai_settings, screen)

    # 创建一个用于存储子弹的编组
    bullets = Group()

    # 创建一组外星人
    aliens = Group()
    gf.create_fleet(ai_settings, screen, aliens)

    # 创建游戏角色
    character = Character(screen)

    # 创建一个用于存储游戏统计信息的实例
    stats = GameStats(ai_settings)

    # 创建记分牌
    sb = Scoreboard(ai_settings, screen, stats)

    # 开始游戏的主循环
    while True:

        # 监听事件
        gf.check_events(ai_settings=ai_settings,
                        screen=screen,
                        stats=stats,
                        play_button=play_button,
                        sb=sb,
                        ship=ship,
                        aliens=aliens,
                        bullets=bullets)

        if stats.game_active:
            # 根据标志修改飞船位置
            ship.update()
            # 更新子弹
            gf.update_bullets(ai_settings, screen, stats, sb, aliens, bullets)
            # 更新外星人
            gf.update_aliens(ai_settings, stats, screen, sb, ship, aliens,
                             bullets)

        # 更新屏幕
        gf.update_screen(ai_settings=ai_settings,
                         screen=screen,
                         stats=stats,
                         ship=ship,
                         character=character,
                         aliens=aliens,
                         bullets=bullets,
                         play_button=play_button,
                         sb=sb)
Example #19
0
import pygame
import time
from src.engineSettings import *
from src.gameObject import GameObject
from src.character import Character

pygame.init()
win = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

pygame.display.set_caption("game")

prevTime = time.time()
run = True
character = Character(YELLOW, 'assets/spritesheet.png')


def checkInput():
    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT]:
        actions['moveLeft'] = True
    else:
        actions['moveLeft'] = False

    if keys[pygame.K_RIGHT]:
        actions['moveRight'] = True
    else:
        actions['moveRight'] = False

    if keys[pygame.K_UP]:
        actions['moveUp'] = True
Example #20
0
from src.character import Character, Enemy

dave = Enemy("Dave", "A smelly zombie")  #Enemy is a Character
pea_shooter = Character("Pea Shooter",
                        "A plant that will shoot peas any zombie in sight")

dave.set_conversation("Brainnnnnnn")
dave.talk()

pea_shooter.set_conversation("Pew Pew Pew")
pea_shooter.talk()