def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, '-', libtcod.sky, 'Dagger', equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(constants): """ Initialize player, entities list, and game map """ fighter_component = Fighter(hp=30, defense=2, power=5) inventory_component = Inventory(26) level_component = Level() player = Entity(0, 0, '@', tcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component) entities = [player] game_map = GameMap(constants["map_width"], constants["map_height"]) game_map.make_map( constants["max_rooms"], constants["room_min_size"], constants["room_max_size"], constants["map_width"], constants["map_height"], player, entities, constants["max_monsters_per_room"], constants["max_items_per_room"], ) message_log = MessageLog(constants["message_x"], constants["message_width"], constants["message_height"]) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=4) inventory_component = Inventory(26) level_component = Level() # initialize the player and an npc # place the player right in the middle of the screen player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component) # store the npc and player in a list, which will eventually hold all entities in the map entities = [player] # initialize the game map game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_players(constants, entities): players = [] for i in range(constants['player_count']): # Building the players fighter_component = Fighter(hp=30, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() vision_component = Vision(None, constants['fov_radius']) players.append( Entity(0, 0, '@', libtcod.blue, 'Player{0}'.format(i + 1), blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, vision=vision_component)) # Give the player a dagger to start with equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, '-', libtcod.sky, 'Dagger', equippable=equippable_component) players[-1].inventory.add_item(dagger) players[-1].equipment.toggle_equip(dagger) entities.append(players[-1]) return players
def get_game_variables(constants): """ Crée une nouvelle partie Parametres: ---------- constants : dict Renvoi: ------- player : Entity entities : list game_map : GameMap message_log : MessageLog game_state : int """ fighter_component = Fighter(hp=100, defense=1, power=3) inventory_component = Inventory() level_component = Level() equipment_component = Equipment() player = Entity(0, 0, constants.get('graphics').get('player'), libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, constants.get('graphics').get('dagger'), libtcod.sky, 'Dague', equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities, constants.get('graphics')) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(constants): fighter_component = Fighter(hp=80, defense=2, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, "@", (255, 255, 255), "Shark", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, "-", constants["colors"].get("sky"), "holdout blade", equippable=equippable_component) player.inventory.add_item(dagger, constants["colors"]) player.equipment.toggle_equip(dagger) game_map = GameMap(constants["map_width"], constants["map_height"]) make_map(game_map, constants["max_rooms"], constants["room_min_size"], constants["room_max_size"], constants["map_width"], constants["map_height"], player, entities, constants["colors"]) message_log = MessageLog(constants["message_x"], constants["message_width"], constants["message_height"]) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def troll(point=None, dungeon_level=1): #create a troll health_component = Health(30) ai_component = BasicNPC() npc = Character(point, 'T', 'troll', COLORS.get('troll'), ai=ai_component, species=Species.TROLL, health=health_component, act_energy=6) npc.add_component(Offence(base_power=12), 'offence') npc.add_component(Defence(defence=8), 'defence') npc.add_component(Level(xp_value=10), 'level') regen = Regeneration() npc.add_component(regen, 'regeneration') npc.add_component(DamageModifier(fire=1.5), 'damagemodifier') regen.start() npc.movement.routing_avoid.extend(npc_avoid) item = None dice = randint(1, 100) if dice > 75: item = equipment.create_weapon('heavy mace') equipment.add_smashing(item) else: item = equipment.create_weapon('longsword') item.lootable = False npc.inventory.add_item(item) npc.equipment.toggle_equip(item) return npc
def get_game_vars(constants): player = Entity(0, 0, '@', tcod.yellow, 'Ratiel Snailface the Snek Oil Snekman (Player Character)', block_movement=True, render_order=RenderOrder.ACTOR, combatant=Combatant(health=24, stamina=60, attack=3, ac=3), item=None, inventory=Inventory(26), level=Level(), equipment=Equipment()) entities = [player] dagger = Entity(0, 0, '!', tcod.sky, 'Ceremonial Dagger', render_order=RenderOrder.ITEM, equippable=Equippable(EquipmentSlots.MAIN_HAND, bonus_attack=2)) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYER_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(constants): player = Entity(0, 0, blocks_movement=True, render_order=RenderOrder.ACTOR, components={ 'fighter': Fighter(hp=100, defense=1, power=2), 'inventory': Inventory(26), 'level': Level(), 'equipment': Equipment(), }) player.set_appearance('@', tcod.white, 'Player') entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, components={ 'equippable': equippable_component, }) dagger.set_appearance( '-', tcod.sky, 'Dagger', ) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(constants['map_width'], constants['map_height'], constants['room_min_size'], constants['room_max_size']) entities.extend(game_map.make_map(constants['max_rooms'], player)) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(): fighter_component = Fighter(hp=100, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', colors.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, '-', colors.sky, 'Dagger', equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap() make_map(game_map, player, entities) message_log = MessageLog() game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(): fighter_component = Fighter(hp=100, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() position_component = Position(0, 0) player = Entity('@', tcod.white, 'Player', blocks=True, position=position_component, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity('-', tcod.sky, 'Dagger', equippable=equippable_component, position=position_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(c.MAP_WIDTH, c.MAP_HEIGHT) game_map.make_map(c.MAX_ROOMS, c.ROOM_MIN_SIZE, c.ROOM_MAX_SIZE, c.MAP_WIDTH, c.MAP_HEIGHT, player, entities) message_log = MessageLog(c.MESSAGE_X, c.MESSAGE_WIDTH, c.MESSAGE_HEIGHT) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def snake(point=None, dungeon_level=1): health_component = Health(8) creature = Character(point, 'S', 'snake', COLORS.get('snake'), ai=PredatorNPC(species=Species.RAT), species=Species.SNAKE, health=health_component, act_energy=3) creature.add_component(Offence(base_power=1), 'offence') creature.add_component(Defence(defence=1), 'defence') creature.add_component(Level(xp_value=10), 'level') creature.add_component(Spawn(2, egg), 'spawn') creature.movement.routing_avoid.extend(creature_avoid) teeth = equipment.teeth() if randint(1, 100) >= 50: equipment.add_poison(teeth, 1, 5) creature.add_component(Naming(creature.base_name, prefix='Poisonous'), 'naming') creature.color = COLORS.get('poisonous_snake') teeth.lootable = False creature.inventory.add_item(teeth) creature.equipment.toggle_equip(teeth) pubsub.pubsub.subscribe( pubsub.Subscription(creature, pubsub.PubSubTypes.DEATH, eat_rat)) return creature
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=2, magic=0, magic_defense=1, talismanhp=0, gold=0) inventory_component = Inventory(26) equipment_inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, equipment_inventory=equipment_inventory_component) entities = [player] gold_value = 1 equipment_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1, gold=gold_value) dagger = Entity(0, 0, '-', libtcod.darker_orange, "Terrium Dagger (+1 atk)", equippable=equipment_component) player.equipment_inventory.add_item(dagger) player.equipment.toggle_equip(dagger) gold_value = 2 item_component = Item(use_function=cast_magic, damage=2, maximum_range=3, gold=gold_value) magic_wand = Entity(0, 0, '|', libtcod.darker_sepia, "Magic Wand", item=item_component) player.inventory.add_item(magic_wand) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
if name == "": name = "The Unknown" player = Actor( char="@", color=(82, 216, 7), name=name, equipment=Equipment(), ai_cls=HostileEnemy, fighter=Fighter(hp=30, base_defense=2, base_power=5, max_hunger=100, hunger=100), inventory=Inventory(capacity=26), level=Level(level_up_base=300), ) rusty = Actor( char="R", color=(255, 8, 10), name="Rusty One", equipment=Equipment(), ai_cls=PermConfusedEnemy, fighter=Fighter(hp=22, base_defense=1, base_power=random.randint(4, 7), max_hunger=1000, hunger=1000), inventory=Inventory(capacity=0), level=Level(xp_given=35),
def get_new_game_variables(constants): race_component = None class_component = None game_state = GameStates.SELECT_SEX previous_game_state = game_state key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) libtcod.console_flush() action = handle_keys(key, game_state) if game_state == GameStates.SELECT_SEX: select_sex_menu(0, 50, constants['screen_width'], constants['screen_height'], constants['sexes']) action = handle_keys(key, game_state) male = action.get('male') female = action.get('female') exit = action.get('exit') if male: sex = 'Male' game_state = GameStates.ENTER_PLAYER_NAME elif female: sex = 'Female' game_state = GameStates.ENTER_PLAYER_NAME elif exit: break elif game_state == GameStates.ENTER_PLAYER_NAME: select_name_menu(0, 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() name = enter_player_name(constants['screen_width'], constants['screen_height']) if name == None: game_state = GameStates.SELECT_SEX else: game_state = GameStates.SELECT_RACE elif game_state == GameStates.SELECT_RACE: select_race_menu(0, 50, constants['screen_width'], constants['screen_height'], constants['races']) action = handle_keys(key, game_state) human = action.get('human') exit = action.get('exit') if human: race_component = Human() game_state = GameStates.SELECT_CLASS elif exit: game_state = GameStates.ENTER_PLAYER_NAME elif game_state == GameStates.SELECT_CLASS: select_combat_class_menu(0, 50, constants['screen_width'], constants['screen_height'], constants['combat_classes']) action = handle_keys(key, game_state) warrior = action.get('warrior') archer = action.get('archer') exit = action.get('exit') if warrior: class_component = Warrior() break if archer: class_component = Archer() break elif exit: game_state = GameStates.SELECT_RACE if exit: libtcod.console_clear(0) libtcod.console_flush() return None, None, None, None, None inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, 1, libtcod.white, name, sex, player=True, blocks=True, render_order=RenderOrder.ACTOR, combat_class=class_component, race=race_component, inventory=inventory_component, level=level_component, equipment=equipment_component) player = apply_class_stats_to_race(player) if player.combat_class.class_name == 'Warrior': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, min_damage_bonus=0, max_damage_bonus=1) dagger = Entity(0, 0, '-', libtcod.sky, 'Dagger', equippable=equippable_component) dagger.item.description = "Better than your bare hands." player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) elif player.combat_class.class_name == 'Archer': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, min_damage_bonus=0, max_damage_bonus=1) dagger = Entity(0, 0, '-', libtcod.sky, 'Dagger', equippable=equippable_component) dagger.item.description = "Better than your bare hands." player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) entities = [player] game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_log_x'], constants['message_width'], constants['message_panel_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def play_game(): screen_width = 70 screen_height = 45 bar_width = 20 panel_horiz_height = 10 panel_horiz_y = screen_height - panel_horiz_height panel_horiz = libtcod.console_new(screen_width, panel_horiz_height) panel_vert_height = panel_horiz_y panel_vert_y = 0 panel_vert = libtcod.console_new(48, panel_vert_height) message_x = 1 message_width = screen_width - 1 message_height = panel_horiz_height - 2 map_width = 47 map_height = panel_horiz_y room_max_size = 8 room_min_size = 3 max_rooms = 30 fov_algorithm = 0 fov_light_walls = True fov_radius = 10 max_monsters_per_room = 3 max_items_per_room = 2 colors = { 'dark_wall': libtcod.Color(0, 0, 100), 'dark_ground': libtcod.Color(50, 50, 150), 'light_wall': libtcod.Color(130, 110, 50), 'light_ground': libtcod.Color(200, 180, 50) } fighter_component = Fighter(hp=100, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, '-', libtcod.sky, 'Dagger', equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) libtcod.console_set_custom_font(consts.FONT, libtcod.FONT_LAYOUT_ASCII_INROW) libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False) con = libtcod.console_new(screen_width, screen_height) game_map = GameMap(map_width, map_height) game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player, entities) fov_recompute = True fov_map = initialize_fov(game_map) message_log = MessageLog(message_x, message_width, message_height) key = libtcod.Key() mouse = libtcod.Mouse() game_state = GameStates.PLAYERS_TURN previous_game_state = game_state targeting_item = None while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, fov_light_walls, fov_algorithm) render_all(con, panel_vert, panel_horiz, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_horiz_height, panel_horiz_y, panel_vert_height, panel_vert_y, mouse, colors, game_state) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key, game_state) mouse_action = handle_mouse(mouse) move = action.get('move') exit = action.get('exit') pickup = action.get('pickup') fullscreen = action.get('fullscreen') show_inventory = action.get('show_inventory') inventory_index = action.get('inventory_index') drop_inventory = action.get('drop_inventory') take_stairs = action.get('take_stairs') level_up = action.get('level_up') show_character_screen = action.get('show_character_screen') wait = action.get('wait') left_click = mouse_action.get('left_click') right_click = mouse_action.get('right_click') player_turn_results = [] if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(player.x + dx, player.y + dy): if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location(entities, destination_x, destination_y) if target: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True game_state = GameStates.ENEMY_TURN elif wait: message_log.add_message(Message('You wait for a moment.', libtcod.yellow)) game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message(Message('There is nothing here to pick up.', libtcod.yellow)) if show_inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend(player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if take_stairs and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.stairs and entity.x == player.x and entity.y == player.y: entities = game_map.next_floor(player, message_log, max_rooms, room_min_size, room_max_size, map_width, map_height) fov_map = initialize_fov(game_map) fov_recompute = True libtcod.console_clear(con) break else: message_log.add_message(Message('There are no stairs here.', libtcod.yellow)) if level_up: if level_up == 'hp': player.fighter.base_max_hp += 20 player.fighter.hp += 20 elif level_up == 'str': player.fighter.base_power += 1 elif level_up == 'def': player.fighter.base_defense += 1 game_state = previous_game_state if show_character_screen: previous_game_state = game_state game_state = GameStates.CHARACTER_SCREEN if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click item_use_results = player.inventory.use(targeting_item, entities=entities, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.extend(item_use_results) elif right_click: player_turn_results.append({'targeting_cancelled': True}) if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY, GameStates.CHARACTER_SCREEN): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') targeting = player_turn_result.get('targeting') targeting_cancelled = player_turn_result.get('targeting_cancelled') xp = player_turn_result.get('xp') equip = player_turn_result.get('equip') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_item = targeting message_log.add_message(targeting_item.item.targeting_message) if targeting_cancelled: game_state = previous_game_state message_log.add_message(Message('Targeting cancelled')) if xp: leveled_up = player.level.add_xp(xp) message_log.add_message(Message('You gain {0} experience points.'.format(xp))) if leveled_up: message_log.add_message(Message( 'Your battle skills grow stronger! You reached level {0}'.format( player.level.current_level) + '!', libtcod.yellow)) previous_game_state = game_state game_state = GameStates.LEVEL_UP if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if equip: equip_results = player.equipment.toggle_equip(equip) for equip_result in equip_results: equipped = equip_result.get('equipped') dequipped = equip_result.get('dequipped') if equipped: message_log.add_message(Message('You equipped the {0}'.format(equipped.name))) if dequipped: message_log.add_message(Message('You dequipped the {0}'.format(dequipped.name))) game_state = GameStates.ENEMY_TURN if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn(player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=2, magic=0, magic_defense=1, talismanhp=0, gold=0, status=None, mana=100) inventory_component = Inventory(26) equipment_inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, constants['player_tile'], libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, equipment_inventory=equipment_inventory_component) entities = [player] equipment_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1, gold=1) dagger = Entity(0, 0, constants['dagger_tile'], libtcod.white, "Terrium Dagger (+1 atk)", equippable=equipment_component) player.equipment_inventory.add_item(dagger) player.equipment.toggle_equip(dagger) item_component = Item(use_function=cast_magic, damage=2, maximum_range=3, gold=2) magic_wand = Entity(0, 0, constants['magic_wand_tile'], libtcod.white, "Magic Wand", item=item_component) player.inventory.add_item(magic_wand) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map( constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities, constants['orc_tile'], constants['healing_potion_tile'], constants['scroll_tile'], constants['troll_tile'], constants['stairs_tile'], constants['sword_tile'], constants['shield_tile'], constants['dagger_tile'], constants['magic_wand_tile'], constants['greater_healing_potion_tile'], constants['ghost_tile'], constants['slime_tile'], constants['corpse_tile'], constants['goblin_tile'], constants['baby_slime_tile'], constants['skeleton_tile'], constants['slime_corpse_tile'], constants['baby_slime_corpse_tile'], constants['skeleton_corpse_tile'], constants['mana_potion_tile'], constants['wizard_staff_tile'], constants['health_talisman_tile'], constants['basilisk_tile'], constants['treasure_tile'], constants['chestplate_tile'], constants['leg_armor_tile'], constants['helmet_tile'], constants['amulet_tile'], constants['floor_tile'], constants['long_bow_tile'], constants['arrow_tile']) item_descriptors = [ 'Valor', 'Power', 'Ingenuity', 'Glory', 'Strength', 'Speed', 'Wealth', 'Divinity', 'Energy', 'Honor', 'Resistance', 'Greatness', 'Courage', 'Intelligence' ] all_shop_equipment = [] sword_amount = randint(2, 4) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount, gold=10) item = Entity(0, 0, constants['sword_tile'], libtcod.white, "Terrium Sword of " + random.choice(item_descriptors) + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) all_shop_equipment.append(item) shield_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount, gold=7) item = Entity(0, 0, constants['shield_tile'], libtcod.white, "Terrium Shield of " + random.choice(item_descriptors) + " (+" + str(shield_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) chestplate_amount = randint(2, 3) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount, gold=20) item = Entity(0, 0, constants['chestplate_tile'], libtcod.darker_grey, "Terrium Chestplate of " + random.choice(item_descriptors) + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) leg_amount = randint(1, 3) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount, gold=15) item = Entity(0, 0, constants['leg_armor_tile'], libtcod.darker_grey, "Terrium Leg Armor of " + random.choice(item_descriptors) + " (+" + str(leg_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) helmet_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount, gold=5) item = Entity(0, 0, constants['helmet_tile'], libtcod.darker_grey, "Terrium Helmet of " + random.choice(item_descriptors) + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) amulet_amount = randint(1, 4) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount, gold=6) item = Entity(0, 0, constants['amulet_tile'], libtcod.darker_grey, "Terrium Amulet of " + random.choice(item_descriptors) + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) all_shop_equipment.append(item) sword_amount = randint(6, 10) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount, gold=35) item = Entity(0, 0, constants['sword_tile'], libtcod.white, "Ferrium Sword of " + random.choice(item_descriptors) + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) all_shop_equipment.append(item) shield_amount = randint(4, 6) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount, gold=30) item = Entity(0, 0, constants['shield_tile'], libtcod.white, "Ferrium Shield of " + random.choice(item_descriptors) + " (+" + str(shield_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) chestplate_amount = randint(5, 7) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount, gold=50) item = Entity(0, 0, constants['chestplate_tile'], libtcod.darker_orange, "Ferrium Chestplate of " + random.choice(item_descriptors) + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) leg_amount = randint(4, 6) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount, gold=40) item = Entity(0, 0, constants['leg_armor_tile'], libtcod.darker_orange, "Ferrium Leg Armor of " + random.choice(item_descriptors) + " (+" + str(leg_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) helmet_amount = randint(4, 5) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount, gold=15) item = Entity(0, 0, constants['helmet_tile'], libtcod.darker_orange, "Ferrium Helmet of " + random.choice(item_descriptors) + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) amulet_amount = randint(5, 9) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount, gold=25) item = Entity(0, 0, constants['amulet_tile'], libtcod.darker_orange, "Ferrium Amulet of " + random.choice(item_descriptors) + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) all_shop_equipment.append(item) sword_amount = randint(15, 20) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount, gold=100) item = Entity(0, 0, constants['sword_tile'], libtcod.white, "Aurium Sword of " + random.choice(item_descriptors) + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) all_shop_equipment.append(item) shield_amount = randint(8, 13) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount, gold=80) item = Entity(0, 0, constants['shield_tile'], libtcod.white, "Aurium Shield of " + random.choice(item_descriptors) + " (+" + str(shield_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) chestplate_amount = randint(10, 15) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount, gold=120) item = Entity(0, 0, constants['chestplate_tile'], libtcod.crimson, "Aurium Chestplate of " + random.choice(item_descriptors) + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) leg_amount = randint(8, 13) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount, gold=100) item = Entity(0, 0, constants['leg_armor_tile'], libtcod.crimson, "Aurium Leg Armor of " + random.choice(item_descriptors) + " (+" + str(leg_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) helmet_amount = randint(8, 12) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount, gold=90) item = Entity(0, 0, constants['helmet_tile'], libtcod.crimson, "Aurium Helmet of " + random.choice(item_descriptors) + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) amulet_amount = randint(10, 15) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount, gold=70) item = Entity(0, 0, constants['amulet_tile'], libtcod.crimson, "Aurium Amulet of " + random.choice(item_descriptors) + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) all_shop_equipment.append(item) all_shop_items = [] item_component = Item(use_function=heal, amount=20, gold=20) item = Entity(0, 0, constants['healing_potion_tile'], libtcod.white, "Health Potion (+20 HP)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=heal, amount=40, gold=40) item = Entity(0, 0, constants['greater_healing_potion_tile'], libtcod.white, "Greater Healing Potion (+40 HP)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( "Left click a target tile for the fireball, or right click to cancel.", libtcod.light_cyan), damage=15, radius=3, mana_cost=20, gold=70) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Fireball Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_confusion, targeting=True, targeting_message=Message( "Left click an enemy to confuse it, or right click to cancel.", libtcod.light_cyan), mana_cost=10, gold=30) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Confusion Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_sleep, targeting=True, targeting_message=Message( "Left click an enemy to make it fall asleep, or right click to cancel.", libtcod.light_cyan), mana_cost=10, gold=30) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Sleep Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_sleep_aura, targeting=True, targeting_message=Message( "Left click a target tile to cast the sleep aura, or right click to cancel.", libtcod.light_cyan), radius=3, mana_cost=20, gold=80) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Sleep Aura Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item( use_function=cast_mind_control, targeting=True, targeting_message=Message( "Left click a target tile to cast mind control, or right click to cancel.", libtcod.light_cyan), radius=3, mana_cost=15, gold=100) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Mind Control Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=health_talisman_sacrifice, amount=5, gold=200) item = Entity(0, 0, constants['health_talisman_tile'], libtcod.darker_orange, "Health Talisman", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=cast_magic, damage=5, maximum_range=5, gold=200) item = Entity(0, 0, constants['wizard_staff_tile'], libtcod.white, "Wizard Staff", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=necromancy, number_of_monsters=5, mana_cost=20, gold=200) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Necromancy Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=recover_mana, amount=20, gold=10) item = Entity(0, 0, constants['mana_potion_tile'], libtcod.white, "Mana Potion (+20 MANA)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=cast_lightning, damage=30, maximum_range=5, mana_cost=15, gold=50) item = Entity(0, 0, constants['scroll_tile'], libtcod.white, "Lightning Spell", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) number_of_shop_items = randint(3, 5) for i in range(number_of_shop_items): random_item = randint(0, len(all_shop_items) - 1) game_map.shop_items.append(all_shop_items[random_item]) number_of_shop_equipment = randint(3, 5) for i in range(number_of_shop_equipment): random_equipment = randint(0, len(all_shop_equipment) - 1) game_map.shop_equipment_items.append( all_shop_equipment[random_equipment]) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def test_experience_to_next_level(): l = Level() assert l.experience_to_next_level == 25
from components.energy import EnergyComponent from components.fighter import Fighter from components.item_comp import ItemComponent from components.level import Level from components.stackable import StackableComponent from src.entity import Entity from src.renderorder import RenderOrder actor_dict = { "grid bug": { "char": "x", "color": tcod.purple, "ai": GridAI(), "fighter": Fighter(max_hp=1, base_ac=10), "offense": OffenseComponent(Attack('zap', [1])), "level": Level(xp_given=1, difficulty=0), "energy": EnergyComponent(refill=12) }, "larva": { "char": "w", "color": tcod.white, "ai": HostileAI(), "fighter": Fighter(max_hp=1, base_ac=9), "offense": OffenseComponent(Attack('bite', [2])), "level": Level(xp_given=8, difficulty=2), "energy": EnergyComponent(refill=6) }, "brown mold": { "char": "F",
def test_requires_level_up(): l = Level() needed = l.experience_to_next_level l.add_xp(needed) assert l.requires_level_up
from components import consumable, equippable from components.equipment import Equipment from components.fighter import Fighter from components.inventory import Inventory from components.level import Level from entity import Actor, Item player = Actor( char="#", color=(255, 255, 255), name="player", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=30, base_defense=1, base_power=2), inventory=Inventory(capacity=26), level=Level(level_up_base=200), ) orc = Actor( char="o", color=(63, 127, 63), name="Orc", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=10, base_defense=0, base_power=3), inventory=Inventory(capacity=0), level=Level(xp_given=25), ) troll = Actor( char="T", color=(0, 127, 0),
def test_add_xp(): l = Level() xp = 30 l.add_xp(xp) assert l.current_xp == xp
from components.inventory import Inventory from components.level import Level from entity import Actor, Item player = Actor( char="@", color=(255, 255, 255), name="Player", ai_cls=HostileEnemy, faction="Holy", Class=Templar(), Subclass=NoClass(), equipment=Equipment(), fighter=Fighter(hp=500, base_defense=30, base_power=50,mana=150,mana_regen=20), inventory=Inventory(capacity=26), level=Level(), ) soldier = Actor( char="T", color=(255, 255, 255), name="Templar", ai_cls=HostileEnemy, faction="Holy", Class=Templar(), Subclass=Shadow(), equipment=Equipment(), fighter=Fighter(hp=150, base_defense=37, base_power=21,mana=5,mana_regen=5), inventory=Inventory(capacity=0), level=Level(xp_given=100, ), )
def test_increase_level__not_enough_xp(): l = Level() assert l.increase_level() is False
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=2, magic=0, magic_defense=1, talismanhp=0, gold=0, status=None, mana=100) inventory_component = Inventory(26) equipment_inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, constants['player_overworld_tile'], libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, equipment_inventory=equipment_inventory_component) entities = [player] equipment_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1, gold=1) dagger = Entity(0, 0, constants['dagger_tile'], libtcod.white, "Terrium Dagger (+1 atk)", equippable=equipment_component) player.equipment_inventory.add_item(dagger) player.equipment.toggle_equip(dagger) item_component = Item(use_function=cast_magic, damage=2, maximum_range=3, gold=2) magic_wand = Entity(0, 0, constants['magic_wand_tile'], libtcod.white, "Magic Wand", item=item_component) player.inventory.add_item(magic_wand) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map( constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities, constants['orc_tile'], constants['healing_potion_tile'], constants['scroll_tile'], constants['troll_tile'], constants['stairs_tile'], constants['sword_tile'], constants['shield_tile'], constants['dagger_tile'], constants['magic_wand_tile'], constants['greater_healing_potion_tile'], constants['ghost_tile'], constants['slime_tile'], constants['corpse_tile'], constants['goblin_tile'], constants['baby_slime_tile'], constants['skeleton_tile'], constants['slime_corpse_tile'], constants['baby_slime_corpse_tile'], constants['skeleton_corpse_tile'], constants['mana_potion_tile'], constants['wizard_staff_tile'], constants['health_talisman_tile'], constants['basilisk_tile'], constants['treasure_tile'], constants['chestplate_tile'], constants['leg_armor_tile'], constants['helmet_tile'], constants['amulet_tile'], constants['floor_tile'], constants['long_bow_tile'], constants['arrow_tile'], constants['wall_tile'], constants['grass_tile'], constants['path_tile'], constants['roof_tile'], constants['brick_tile'], constants['player_overworld_tile'], constants['player_tile'], constants['forest_tile'], constants['door_tile'], constants['sign_tile']) item_descriptors = [ 'Valor', 'Power', 'Ingenuity', 'Glory', 'Strength', 'Speed', 'Wealth', 'Divinity', 'Energy', 'Honor', 'Resistance', 'Greatness', 'Courage', 'Intelligence' ] all_shop_items = [] item_component = Item(use_function=heal, amount=20, gold=20) item = Entity(0, 0, constants['healing_potion_tile'], libtcod.white, "Health Potion (+20 HP)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=recover_mana, amount=20, gold=10) item = Entity(0, 0, constants['mana_potion_tile'], libtcod.white, "Mana Potion (+20 MANA)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) all_shop_equipment = [] sword_amount = randint(2, 4) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount, gold=10) item = Entity(0, 0, constants['sword_tile'], libtcod.white, "Terrium Sword of " + random.choice(item_descriptors) + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) all_shop_equipment.append(item) shield_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount, gold=7) item = Entity(0, 0, constants['shield_tile'], libtcod.white, "Terrium Shield of " + random.choice(item_descriptors) + " (+" + str(shield_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) chestplate_amount = randint(2, 3) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount, gold=20) item = Entity(0, 0, constants['chestplate_tile'], libtcod.darker_grey, "Terrium Chestplate of " + random.choice(item_descriptors) + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) leg_amount = randint(1, 3) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount, gold=15) item = Entity(0, 0, constants['leg_armor_tile'], libtcod.darker_grey, "Terrium Leg Armor of " + random.choice(item_descriptors) + " (+" + str(leg_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) helmet_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount, gold=5) item = Entity(0, 0, constants['helmet_tile'], libtcod.darker_grey, "Terrium Helmet of " + random.choice(item_descriptors) + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) amulet_amount = randint(1, 4) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount, gold=6) item = Entity(0, 0, constants['amulet_tile'], libtcod.darker_grey, "Terrium Amulet of " + random.choice(item_descriptors) + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) all_shop_equipment.append(item) number_of_shop_items = randint(1, 3) for i in range(number_of_shop_items): random_item = randint(0, len(all_shop_items) - 1) game_map.shop_items.append(all_shop_items[random_item]) number_of_shop_equipment = randint(1, 2) for i in range(number_of_shop_equipment): random_equipment = randint(0, len(all_shop_equipment) - 1) game_map.shop_equipment_items.append( all_shop_equipment[random_equipment]) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def test_increase_level__has_required_xp(): l = Level() needed = l.experience_to_next_level l.add_xp(needed) assert l.increase_level()
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=5, agility=1, job=0, mana=10, nutrition=500, base_psyche=2, starvation_bonus=0) inventory_component = Inventory(26) skills_component = Skills(15) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, skills=skills_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=4) item_component = Item(use_function=None) dagger = Entity(0, 0, '/', libtcod.sky, 'Carving Knife', equippable=equippable_component, item=item_component) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1, agility_bonus=-1) item_component = Item(use_function=None) buckler = Entity(0, 0, '{', libtcod.sky, 'Buckler', equippable=equippable_component, item=item_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) player.inventory.add_item(buckler) player.equipment.toggle_equip(buckler) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['max_maze_rooms'], constants['maze_min_size'], constants['maze_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.CHARACTER_CREATION ggender = Gender.male return player, entities, game_map, message_log, game_state, ggender
def test_init__is_BaseComponent(): l = Level() assert isinstance(l, Component)
from components import consumable, equippable from components.equipment import Equipment from components.fighter import Fighter from components.inventory import Inventory from components.level import Level from entity import Actor, Item player = Actor( char="@", color=(255, 255, 255), name="Player", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=30, base_defense=1, base_power=2), inventory=Inventory(capacity=26), level=Level(level_up_base=200), ) orc = Actor( char="o", color=(63, 127, 63), name="Orc", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=10, base_defense=0, base_power=3), inventory=Inventory(capacity=0), level=Level(xp_given=35), ) troll = Actor( char="T", color=(0, 127, 0), name="Troll",
from components.ai import HostileEnemy from components.fighter import Fighter from components import consumable from components.inventory import Inventory from components.level import Level from entity import Actor, Item player = Actor( char="@", color=(255, 255, 255), name="Player", ai_cls=HostileEnemy, fighter=Fighter(hp=30, defense=2, power=5), inventory=Inventory(capacity=26), level=Level(level_up_base=200), ) grunt = Actor(char="o", color=(63, 127, 63), name="grunt", ai_cls=HostileEnemy, fighter=Fighter(hp=10, defense=0, power=3), inventory=Inventory(capacity=0), level=Level(xp_given=50)) juggernaut = Actor( char="T", color=(0, 127, 0), name="juggernaut", ai_cls=HostileEnemy, fighter=Fighter(hp=16, defense=1, power=4), inventory=Inventory(capacity=0), level=Level(xp_given=100),