Exemplo n.º 1
0
 def use(self, target):
     """
     Attempt to go up.
     """
     from dungeon import DungeonException
     try:
         self.dungeon.go_to_previous_level()
     except DungeonException:
         message("You can't leave yet!", Colors.WHITE)
Exemplo n.º 2
0
def main():
    # First of all, load the registry
    registry = Registry()

    # Initialize player, display_manager
    player = Actor(Actors.HERO,
                   "Player",
                   '@',
                   Colors.WHITE,
                   behavior=None,
                   registry=registry)
    # XXX: Give player level boost for testing purposes
    player.level = 10

    # Initialize Dungeon
    dungeon = Dungeon()
    dungeon.initialize(player, registry)

    # Initialize Display Manager
    display_manager = DisplayManager(player, dungeon)
    message("Hello world!", Colors.RED)

    # Initialize Action Manager
    action_manager = ActionManager(player, dungeon)

    # Game loop
    while not tdl.event.is_window_closed():
        display_manager.refresh()
        # TODO: Add player and enemy turn states and cycle between both
        # Player turn
        # TODO: Use game states to handle turns

        action_manager.get_user_input()
        if action_manager.handle_key_input() is False:
            continue

        # Enemy turn
        for entity in dungeon.current_level.entities:
            entity.take_turn(player)

        # Check for player death
        # TODO: Handle player death as a game state
        if player.dead:
            # TODO: Show death screen
            print("You died!")
            return 0
Exemplo n.º 3
0
    def use(self, target):
        """
        Use the item upon the specified target, activating its effect. See Effect for more info.

        Args:
            target (Actor): The actor that will be affected by the item's effect.

        Returns:
            bool: True if the effect was successfully used, False otherwise.
        """
        if self.effect is not None:
            # Execute the effect
            self.effect(target)
            # If the item was used from an interaction in the map, remove it from the map
            if self.game_map is not None:
                self.game_map.entities.remove(self)
            return True
        else:
            message("Nothing happened...")
        return False
Exemplo n.º 4
0
 def test_message_non_default_color(self):
     from display_manager import DisplayManager
     message("Foo", Colors.BLUE)
     assert ("Foo", Colors.BLUE) in DisplayManager.game_msgs
Exemplo n.º 5
0
 def test_message_added(self):
     from display_manager import DisplayManager
     message("Hello world!")
     assert ("Hello world!", Colors.WHITE) in DisplayManager.game_msgs