Пример #1
0
    def _is_path_clear(self, tile_model: TileModel, dirn: str) -> bool:
        """
        Determines if there is an obstacle blocking the
        way from the tile in the direction 'dirn'.

        :param tile_model: tile the player is moving from
        :param dirn: direction from tile in which moving
        :return: True if the path from the first tile to
                the second is clear, False otherwise.
        """
        has_obstacle = tile_model.has_obstacle_in_direction(dirn)
        obstacle = tile_model.get_obstacle_in_direction(dirn)
        is_open_door = isinstance(obstacle, DoorModel) and obstacle.door_status == DoorStatusEnum.OPEN
        is_damaged_wall = isinstance(obstacle, WallModel) and obstacle.wall_status == WallStatusEnum.DAMAGED
        is_carrying_victim = isinstance(self.target.carrying_victim, VictimModel)
        # there is a destroyed door or a destroyed wall or no obstacle or an open door or a damaged wall
        if self.current_player.role == PlayerRoleEnum.DOGE:
            if not has_obstacle or is_open_door or is_damaged_wall:
                # The Doge is not allowed to carry a
                # victim through a damaged wall.
                if is_carrying_victim and is_damaged_wall:
                    return False
                else:
                    return True

        # there is a destroyed door or a destroyed wall or no obstacle or an open door
        else:
            if not has_obstacle or is_open_door:
                return True

        return False
Пример #2
0
    def shockwave(self, tile: TileModel, direction: str):
        """
        Send shockwave along a direction.

        :param tile: the tile where the shockwave starts
        :param direction: direction in which shockwave continues
        :return:
        """
        game_state = GameStateModel.instance()
        should_stop = False
        while not should_stop:
            # if there is no obstacle in the given direction -
            #   1. if neighbouring tile is not on fire, set it to fire
            #       and stop the shockwave.
            #   2. else set the current tile to the neighbouring tile
            #       and continue the shockwave.
            if not tile.has_obstacle_in_direction(direction):
                nb_tile: TileModel = tile.get_tile_in_direction(direction)
                if nb_tile.space_status != SpaceStatusEnum.FIRE:
                    nb_tile.space_status = SpaceStatusEnum.FIRE
                    should_stop = True

                else:
                    tile = nb_tile

            # if there is an obstacle in the given direction
            else:
                # 1. if obstacle is a wall, inflict damage on it, increment
                #   game state damage and stop the shockwave.
                # 2. if obstacle is an open door, continue the shockwave
                #   and destroy the door.
                # 3. if obstacle is a closed door, stop the shockwave
                #   and destroy the door.
                obstacle = tile.get_obstacle_in_direction(direction)
                if isinstance(obstacle, WallModel):
                    obstacle.inflict_damage()
                    game_state.damage = game_state.damage + 1
                    should_stop = True

                elif isinstance(obstacle, DoorModel):
                    if obstacle.door_status == DoorStatusEnum.CLOSED:
                        should_stop = True
                    obstacle.destroy_door()

                else:
                    pass