Ejemplo n.º 1
0
    def run(self, char):
        if char == '\\':
            self.change_parent_dir_with_func(lambda dir: Pos(dir.y, dir.x))
        elif char == '/':
            self.change_parent_dir_with_func(lambda dir: Pos(-dir.y, -dir.x))
        elif char == '(':
            self.set_parent_direction(RIGHT)
        elif char == ')':
            self.set_parent_direction(LEFT)
        elif char == '>' and self.is_moving_vert():
            self.set_parent_direction(RIGHT)
        elif char == '<' and self.is_moving_vert():
            self.set_parent_direction(LEFT)
        elif char == '^' and self.is_moving_horiz():
            self.set_parent_direction(UP)
        elif char == 'v' and self.is_moving_horiz():
            self.set_parent_direction(DOWN)
        elif char == '*':
            for dir in DIRECTIONS:
                if self.parent.dir in (dir, -dir):
                    continue

                next_pos = self.parent.pos + dir

                if self.env.world.does_loc_exist(
                        next_pos
                ) and self.env.world.get_char_at(next_pos) != ' ':
                    new_dot = self.parent.copy()
                    new_dot.dir = dir
                    new_dot.move()

                    self.env.dots.append(new_dot)
        elif isinstance(char, SingletonLibInnerWarpChar):
            if len(self.parent.stack) == 0:
                raise RuntimeError(
                    'Dot tried to exit library it never entered.\nThis is likely caused by a dot spawned inside a library trying to teleport out.'
                )

            self.parent.pos = self.parent.stack.pop()
        elif char.isWarp():
            if char.isSingletonLibWarp():
                self.parent.stack.append(self.parent.pos)

            char_dest_loc = char.get_dest_loc()
            if char_dest_loc is not None:
                self.parent.pos = char.get_dest_loc()
            else:
                raise RuntimeError('Warp "{}" has no destination'.format(char))

        self.move_parent()
Ejemplo n.º 2
0
    def run(self, char):
        if char == '\\':
            self.change_parent_dir_with_func(lambda dir: Pos(dir.y, dir.x))
        elif char == '/':
            self.change_parent_dir_with_func(lambda dir: Pos(-dir.y, -dir.x))
        elif char == '(':
            self.set_parent_direction(RIGHT)
        elif char == ')':
            self.set_parent_direction(LEFT)
        elif char == '>':
            if self.is_moving_vert():
                self.set_parent_direction(RIGHT)
        elif char == '<':
            if self.is_moving_vert():
                self.set_parent_direction(LEFT)
        elif char == '^':
            if self.is_moving_horiz():
                self.set_parent_direction(UP)
        elif char == 'v':
            if self.is_moving_horiz():
                self.set_parent_direction(DOWN)
        elif char == '*':
            for dir in DIRECTIONS:

                if self.parent.dir in (dir, -dir):
                    continue

                next_pos = self.parent.pos + dir

                if self.env.world.does_loc_exist(
                        next_pos
                ) and self.env.world.get_char_at(next_pos) != ' ':

                    new_dot = self.parent.copy()
                    new_dot.dir = dir
                    new_dot.move()

                    self.env.dots.append(new_dot)
        elif char.isSingletonLibReturnWarp():
            self.parent.pos = self.parent.stack.pop()
        elif char.isWarp():
            if char.isSingletonLibWarp():
                self.parent.stack.append(self.parent.pos)

            self.parent.pos = char.get_dest_loc()
        else:
            pass

        self.move_parent()
Ejemplo n.º 3
0
 def _setup_tildes(self):
     for y, line in enumerate(self.map):
         for x, char in enumerate(line):
             if char == '~':
                 inverted = self._is_inversion_char_at(Pos(x, y + 1))
                 self.map[y][x] = TildeChar("~")
                 self.map[y][x].set_inverted(inverted)
Ejemplo n.º 4
0
    def get_coords_of_dots(self):
        """Yiels the cordinates of every dot char in the world."""
        for y, line in enumerate(self.map):
            if line and line[0] == '%':
                continue

            for x, char in enumerate(line):
                if char.isDot():
                    yield Pos(x, y)
Ejemplo n.º 5
0
    def _find_companion_warp_char_loc_of(self, orig_char, warp_id, orig_pos: Pos):
        for y, line in enumerate(self.map):
            if line[0] == '%':
                continue

            for x, char in enumerate(line):
                if char.isWarp() and char.get_id() == warp_id and orig_pos != (x, y):
                    if isinstance(orig_char, SingletonLibOuterWarpChar):
                        if not isinstance(char, SingletonLibInnerWarpChar):
                            continue
                    return Pos(x, y)
Ejemplo n.º 6
0
    def _find_companion_warp_char_loc_of(self, warp_id, orig_pos: Pos):
        for y, line in enumerate(self.map):
            if line[0] == '%':
                continue

            if orig_pos.y == y:
                continue

            for x, char in enumerate(line):
                if char.isWarp() and char.get_id() == warp_id and orig_pos != (
                        x, y):
                    return Pos(x, y)
Ejemplo n.º 7
0
    def _connect_warps(self):
        for y, line in enumerate(self.map):
            if line[0] == '%':
                continue

            for x, char in enumerate(line):
                if char.isWarp() and not char.isSingletonLibReturnWarp():
                    warp_id = char.get_id()
                    companion_warp_loc = self._find_companion_warp_char_loc_of(
                        warp_id, Pos(x, y))

                    if companion_warp_loc is not None:
                        self.map[y][x].set_dest_loc(companion_warp_loc)
Ejemplo n.º 8
0
"""
Here are defined the constants of the language.
You will alos find shortcuts for repetitive values in the code like UP and DOWN.
"""

from dots.vector import Pos

# Defining directions
UP = Pos(0, -1)
DOWN = Pos(0, 1)
LEFT = Pos(-1, 0)
RIGHT = Pos(1, 0)

DIRECTIONS = (UP, RIGHT, DOWN, LEFT)

# Defining Chars
COMMENT_START = '``'
ID_MODE = '@'
VALUE = '#'
Ejemplo n.º 9
0
 def _char_obj_array_iter_with_coords(self, obj_array):
     for y, char_list in enumerate(obj_array):
         for x, char in enumerate(char_list):
             yield Pos(x, y), char