def create_ship(self, start_x, start_y, length, direction, state='ship', managed=False): ship = None if managed: ship = Ship() ship.create(start_x, start_y, length, direction, state) ship.cells = [None] * length for i in range(0, length): x_ = start_x y_ = start_y if direction == "V": y_ = start_y + i elif direction == "H": x_ = start_x + i ship.cells[i] = self.composite(x_, y_, state) else: cells = self.take_cells(start_x, start_y, length, direction) if self.add_ship(cells): for c in cells: c.state = state ship = self.ships[-1] return ship