예제 #1
0
def input_laser(container):
    """
       Builds a Laser object entering in container from user input.
    """
    valid_input = False
    while (not valid_input):
        try:
            direction = input("Direction initiale du laser ? [>|<|^|v] > ")
            assert direction in conf.allowed_directions
        except:
            "Erreur : direction invalide."
            continue
        try:
            entry_point = string_utils.cap_letter_to_rank(
                input("Point"
                      " d'entrée du laser ? [A|B|...] > "))
            if direction in ['>', '<']:
                assert 0 <= entry_point < container.height
            else:
                assert 0 <= entry_point < container.width
        except:
            "Erreur : point d'entrée invalide pour la direction fournie."
            continue
        valid_input = True
    if direction in ['>', '<']:
        x, y = entry_point, 0 if direction == '>' else container.width - 1
    else:
        x, y = 0 if direction == 'v' else container.height - 1, entry_point
    return laser.Laser(x, y, direction, container)
예제 #2
0
 def __init__(self, _grid, _laser):
     super().__init__()
     self._grid = _grid
     self._laser = _laser
     _laser_copy = laser.Laser(_laser.x, _laser.y, _laser.direction, _grid)
     self._solution = self._grid.compute_all_laser_exits(_laser_copy)
     self._buttons_active = False
     self._side_labels = []
     self._laser_label = QtGui.QLabel()
     self._graphic_grid = QtGui.QGridLayout()
     self.initialize_user_interface()
     QtCore.QTimer.singleShot(conf.phase_one_duration, self.enter_phase_two)
예제 #3
0
def random_laser(_grid):
    """
       Builds a laser object entering the grid _grid from a random cell on the
       side.
    """
    random_direction = choice(conf.allowed_directions)
    if random_direction in ['>', '<']:
        random_x, random_y = (randint(0, _grid.height - 1),
                              0 if random_direction == '>' else _grid.width -
                              1)
    else:
        random_x, random_y = (0 if random_direction == 'v' else _grid.height -
                              1, randint(0, _grid.width - 1))
    return laser.Laser(random_x, random_y, random_direction, _grid)
예제 #4
0
 def build_top_laser(self, _grid):
     return laser.Laser(0, 1, 'v', _grid)
예제 #5
0
 def build_right_laser(self, _grid):
     return laser.Laser(1, self.grid_width - 1, '<', _grid)
예제 #6
0
 def build_bottom_laser(self, _grid):
     return laser.Laser(self.grid_height - 1, 1, '^', _grid)
예제 #7
0
 def build_left_laser(self, _grid):
     return laser.Laser(1, 0, '>', _grid)
예제 #8
0
 def build_laser(self, _grid):
     return laser.Laser(self._laser_x, self._laser_y, self._laser_direction,
                        _grid)