def __init__(self, name, sprite, hp, defense, res, strength, classes, equipments, race, gold, lvl, skills, compl_sprite=None): Character.__init__(self, name, (), sprite, hp, defense, res, strength, None, classes, equipments, 'MANUAL', lvl, skills, race, gold, compl_sprite) self.state = PlayerState.WAITING_SELECTION self.old_pos = () self._selected = False # Sprite displayed when player cannot be selected self.sprite_unavaible = self.sprite.copy() color_image = pg.Surface(self.sprite.get_size()).convert_alpha() color_image.fill(LIGHT_GREY) self.sprite_unavaible.blit(color_image, (0, 0), special_flags=pg.BLEND_RGBA_MULT) # Memorize normal state sprite self.normal_sprite = self.sprite # Memorize the current action performed by the player, it must be a value of CharacterMenu self.current_action = None
def draw(self, gameDisplay, draw): Character.draw(self, gameDisplay, draw) # Draw the H20 bar draw.rect(gameDisplay, [0, 0, 255, 100], [25, 25, self._water / 5, 5]) # Display the food bar draw.rect(gameDisplay, [255, 255, 0, 100], [25, 30, self._food / 10, 5])
def move(self): if self.state is PlayerState.ON_MOVE: Character.move(self) if not self.on_move: self.state = PlayerState.WAITING_POST_ACTION return True return False
def setUpClass(cls): from src.Level import Level from src.Character import Character from src import LoadFromXMLManager as Loader import src.fonts as font os.chdir(os.getcwd() + '/..') pg.init() font.init_fonts() cls.level_class = Level cls.buttons = [] cls.buttons.append( Rect(NEW_GAME_BUTTON_POS[0], NEW_GAME_BUTTON_POS[1], BUTTON_SIZE[0], BUTTON_SIZE[1])) cls.buttons.append( Rect(LOAD_GAME_BUTTON_POS[0], LOAD_GAME_BUTTON_POS[1], BUTTON_SIZE[0], BUTTON_SIZE[1])) cls.buttons.append( Rect(OPTIONS_BUTTON_POS[0], NEW_GAME_BUTTON_POS[1], BUTTON_SIZE[0], BUTTON_SIZE[1])) cls.buttons.append( Rect(EXIT_GAME_BUTTON_POS[0], NEW_GAME_BUTTON_POS[1], BUTTON_SIZE[0], BUTTON_SIZE[1])) races = Loader.load_races() classes = Loader.load_classes() Character.init_data(races, classes)
def setUpClass(cls): super(TestShop, cls).setUpClass() pg.init() font.init_fonts() # Window parameters pg.display.set_mode((MAIN_WIN_WIDTH, MAIN_WIN_HEIGHT)) # Load some data races = Loader.load_races() classes = Loader.load_classes() Character.init_data(races, classes)
def setUpClass(cls): super(TestLevel, cls).setUpClass() cls.save_url = "saves/main_save.xml" pg.init() font.init_fonts() # Window parameters screen = pg.display.set_mode((MAIN_WIN_WIDTH, MAIN_WIN_HEIGHT)) cls.start_screen = StartScreen(screen) cls.start_screen.display() # Load some data races = Loader.load_races() classes = Loader.load_classes() Character.init_data(races, classes)
def get_character(self): """ Return the character chosen by the player :return: """ # TODO fix function return Character(name='Billie the Kid', health=5)
def test_add_card(self): character = Character(name='Billie the Kid', health=5) player_samuel = Player(name='Samuel', role='Sheriff', character=character) self.assertEqual(len(player_samuel.hand), 0) player_samuel.add_cards(['Fake card1']) self.assertEqual(len(player_samuel.hand), 1) player_samuel.add_cards(['Fake card2']) self.assertEqual(len(player_samuel.hand), 2)
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 test_init(self): character = Character(name='Billie the Kid', health=5) player_samuel = Player(name='Samuel', role='Sheriff', character=character) self.assertEqual(player_samuel.health, 5) self.assertEqual(player_samuel.name, 'Samuel') self.assertEqual(player_samuel.role, 'Sheriff') self.assertIsNone(player_samuel.equipment) self.assertIsNone(player_samuel.weapon) self.assertEqual(len(player_samuel.hand), 0)
def __init__(self): pokemon_names = pd.read_csv("assets/pokemon_names.txt", sep='\n').values.tolist() self.character_list = [] for name in pokemon_names: self.character_list.append( Character(name[0], generate_random_stats()))
def save(self, tree_name): # Build XML tree tree = Character.save(self, tree_name) # Save if turn is finished or not state = etree.SubElement(tree, 'turnFinished') state.text = str(self.turn_is_finished()) return tree
def test_player_die(self): beer_card = BeerCard(Suit.HEARTS, 5) character = Character(name='Billie the Kid', health=1) player_samuel = Player(name='Samuel', role='Sheriff', character=character) self.assertEqual(player_samuel.health, 1) player_samuel.add_cards(beer_card) player_samuel.change_health(-1) self.assertEqual(player_samuel.health, 1) with self.assertRaises(PlayerDeadException): player_samuel.change_health(-1)
def setUpClass(cls): super(TestStartScreen, cls).setUpClass() pg.init() font.init_fonts() cls.save_url = "saves/main_save.xml" cls.level_class = Level cls.buttons = [] cls.buttons.append( Rect(NEW_GAME_BUTTON_POS[0], NEW_GAME_BUTTON_POS[1], BUTTON_SIZE[0], BUTTON_SIZE[1])) cls.buttons.append( Rect(LOAD_GAME_BUTTON_POS[0], LOAD_GAME_BUTTON_POS[1], BUTTON_SIZE[0], BUTTON_SIZE[1])) cls.buttons.append( Rect(OPTIONS_BUTTON_POS[0], NEW_GAME_BUTTON_POS[1], BUTTON_SIZE[0], BUTTON_SIZE[1])) cls.buttons.append( Rect(EXIT_GAME_BUTTON_POS[0], NEW_GAME_BUTTON_POS[1], BUTTON_SIZE[0], BUTTON_SIZE[1])) races = Loader.load_races() classes = Loader.load_classes() Character.init_data(races, classes)
def step(self): Character.step(self) self.water_priority.update(self._water) self.food_priority.update(self._water) self.companionship_priority.update(self._loneliness) self.step_counter += 1 if self.step_counter == 9: if self._experience.sees_player(): # move = self.intelligence.getMove(self._experience.get_player_location()) move = self.graph.BFS( self._x, self._y, self._experience.get_player_location()[0], self._experience.get_player_location()[1]) if move == 0: self._dx = 2 if move == 1: self._dx = -2 if move == 2: self._dy = -2 if move == 3: self._dy = 2 self.step_counter = 0
def __init__(self, name, sprite, hp, defense, res, max_move, strength, classes, equipments, race, gold, lvl=1, compl_sprite=None): Character.__init__(self, name, (), sprite, hp, defense, res, max_move, strength, None, classes, equipments, None, lvl, race, gold, compl_sprite) '''Possible states : - 0 : Waiting to be selected - 1 : Waiting to be moved - 2 : On move - 3 : Waiting an action post-move - 4 : Waiting a target selected to attack OR waiting an target to interact with - 5 : Turn finished''' self.old_pos = () self.state = 0 self.last_state = 5 self.selected = False # Sprite displayed when player cannot be selected self.sprite_unavaible = self.sprite.copy() color_image = pg.Surface(self.sprite.get_size()).convert_alpha() color_image.fill(LIGHT_GREY) self.sprite_unavaible.blit(color_image, (0, 0), special_flags=pg.BLEND_RGBA_MULT) # Memorize normal state sprite self.normal_sprite = self.sprite
def __init__(self, name, pos, sprite, hp, defense, res, max_move, strength, classes, equipments, lvl=1): Character.__init__(self, name, pos, sprite, hp, defense, res, max_move, strength, classes, equipments, lvl) '''Possible states : - 0 : Waiting to be selected - 1 : Waiting to be moved - 2 : On move - 3 : Waiting an action post-move - 4 : Waiting a target selected to attack OR waiting an target to interact with - 5 : Turn finished''' self.state = 0 self.last_state = 5 self.selected = False
def get_character(self, name): url_return = do_request("character/?name.first_lower=%s&c:resolve=world" % name.lower()) try: player_id = url_return["character_list"][0]["id"] player_name = url_return["character_list"][0]["name"]["first"] api_result = do_request("single_character_by_id/?id=%s&c:resolve=outfit,world" % player_id) player = Character(player_id, player_name) base = api_result["single_character_by_id_list"][0] self.get_character_info(base, player) self.get_kills_info(base, player) return player except: return "Not found."
def load_ally(ally, from_save, gap_x, gap_y): name = ally.find('name').text.strip() x = int(ally.find('position/x').text) * TILE_SIZE + gap_x y = int(ally.find('position/y').text) * TILE_SIZE + gap_y pos = (x, y) lvl = int(ally.find('level').text.strip()) infos = etree.parse('data/characters.xml').find(name) # Static data sprite = 'imgs/characs/' + infos.find('sprite').text.strip() race = infos.find('race').text.strip() classes = [infos.find('class').text.strip()] formatted_name = infos.find('name').text.strip() talks = infos.find('talks') dialog = [] for talk in talks.findall('talk'): dialog.append(talk.text.strip()) strategy = infos.find('strategy').text.strip() attack_kind = infos.find('attack_kind').text.strip() stats_tree = infos if from_save: stats_tree = ally hp = int(stats_tree.find('hp').text.strip()) move = int(stats_tree.find('move').text.strip()) strength = int(stats_tree.find('strength').text.strip()) defense = int(stats_tree.find('def').text.strip()) res = int(stats_tree.find('res').text.strip()) gold = int(stats_tree.find('gold').text.strip()) loaded_ally = Character(formatted_name, pos, sprite, hp, defense, res, move, strength, attack_kind, classes, [], strategy, lvl, race, gold, dialog) if from_save: current_hp = int(ally.find('currentHp').text.strip()) loaded_ally.set_current_hp(current_hp) xp = int(ally.find('exp').text.strip()) loaded_ally.earn_xp(xp) return loaded_ally
def unequip(self, eq): unequipped = Character.unequip(self, eq) if unequipped: self.state = PlayerState.WAITING_POST_ACTION_UNCANCELLABLE return unequipped
def move(self): Character.move(self) if not self.on_move: self.state = 3
def test_get_start_health(self): character = Character(name='Billie the Kid', health=5) player_samuel = Player(name='Samuel', role='Sheriff', character=character) self.assertEqual(player_samuel.get_start_health(), 5)
def attack(self, ent): damages = Character.attack(self, ent) self.state = self.last_state return damages
def use_item(self, item): used, result_msgs = Character.use_item(self, item) if used: self.state = PlayerState.WAITING_POST_ACTION_UNCANCELLABLE return used, result_msgs
def set_move(self, pos): Character.set_move(self, pos) self.state = PlayerState.ON_MOVE self.old_pos = self.pos
def display(self, screen): Character.display(self, screen) if self.state in range(PlayerState.WAITING_MOVE, PlayerState.WAITING_TARGET + 1): screen.blit(Player.SELECTED_DISPLAY, self.pos)
def equip(self, eq): equipped = Character.equip(self, eq) if equipped > -1: self.state = PlayerState.WAITING_POST_ACTION_UNCANCELLABLE return equipped
def new_turn(self): Character.new_turn(self) self.state = PlayerState.WAITING_SELECTION self.sprite = self.normal_sprite for eq in self.equipments: eq.unset_grey()
def __init__(self, players: List[Player]): # Todo: Should be self.players: Tuple[Player] = (player_1, player_2) self.players = players self.position_carlotta = 6 # position on the exit path # Todo: Should be removed and make the game ends when carlotta reach 0. self.exit = 22 self.num_tour = 1 # Todo: Should be a Dict[enum, Character] self.characters = set({Character(color) for color in colors}) # character_cards are used to draw 4 characters at the beginning # of each round self.character_cards = list(self.characters) self.active_cards = list() self.alibi_cards = self.character_cards.copy() self.fantom = choice(self.alibi_cards) # Todo: Should be placed in a logger section of the __init__() logger.info("the fantom is " + self.fantom.color) self.alibi_cards.remove(self.fantom) self.alibi_cards.extend(['fantom'] * 3) # log logger.info("\n=======\nnew game\n=======") # Todo: 1 Should be removed logger.info(f"shuffle {len(self.character_cards)} character_cards") # Todo: 2 Should be removed logger.info(f"shuffle {len(self.alibi_cards)} alibi cards") # work # Todo: 1 Should be removed shuffle(self.character_cards) # Todo: 2 Should be removed shuffle(self.alibi_cards) # Initialise character positions # Rooms at the center of the game are not available rooms_number = list(range(10)) start_rooms = rooms_number[:5] + rooms_number[7:] for character in self.characters: character.position = choice(start_rooms) for character in self.characters: # get position of grey character if character.color == "grey": grey_character_position = character.display()["position"] self.shadow = grey_character_position if character.color == "blue": blue_character_position = character.display()["position"] # initially the blocked passage is # next to blue character clockwise if blue_character_position == 0: self.blocked = (0, 1) elif blue_character_position == 1: self.blocked = (1, 2) elif blue_character_position == 2: self.blocked = (2, 3) elif blue_character_position == 3: self.blocked = (3, 4) elif blue_character_position == 4: self.blocked = (4, 5) elif blue_character_position == 7: self.blocked = (7, 9) elif blue_character_position == 9: self.blocked = (8, 9) elif blue_character_position == 8: self.blocked = (4, 8) else: print(blue_character_position) raise ValueError( "Wrong initial position of blue character") self.characters_display = [ character.display() for character in self.characters ] # Todo: should be removed self.character_cards_display = [ tile.display() for tile in self.character_cards ] self.active_cards_display = [ tile.display() for tile in self.active_cards ] self.game_state = { "position_carlotta": self.position_carlotta, "exit": self.exit, "num_tour": self.num_tour, "shadow": self.shadow, "blocked": self.blocked, "characters": self.characters_display, # Todo: should be removed "character_cards": self.character_cards_display, "active character_cards": self.active_cards_display, }
def attack(self, ent): damages = Character.attack(self, ent) self.state = PlayerState.FINISHED return damages