- if isinstance(index, (tuple, list)):
- x = index[0]
- y = index[1]
- index = y * self._width + x
- elif isinstance(index, int):
- x = index % self._width
- y = index // self._width
- if x > self._width or y > self._height or index >= len(self._tiles):
- raise ValueError("Tile index out of bounds")