Exemple #1
0
 def move_tile_on_grid(self, tile: Tile, coordinates: Coordinates):
     if self.tiles_from_index.get(tile.get_id()) is None:
         raise TileNotExistsException("tile: (" + str(tile) +
                                      ") was not added")
     tile_on_coordinates = self.get_tile_from_grid(coordinates)
     if tile_on_coordinates is not None:
         if tile_on_coordinates.id != tile.id:
             raise TileTakenException(
                 tile_on_coordinates,
                 f"there is already tile: ({str(tile)}) on {str(coordinates)}"
             )
         # else it means we move to same tile we were on
     previous_coordinates = self.coordinates_from_index.get(tile.get_id())
     if previous_coordinates is None:
         raise TileNotExistsException("tile: (" + str(tile) +
                                      ") did not have coordinates")
     self.coordinates_from_index[tile.get_id()] = coordinates.copy()
     self.tile_grid[
         previous_coordinates.get_array_index()] = BaseGrid.empty_tile_id
     self.tile_grid[coordinates.get_array_index()] = tile.get_id()
     self.tiles_from_index[tile.get_id()] = tile
     if tile.get_type() == TileType.BLOCK:
         self.block_tile_grid[
             previous_coordinates.get_array_index()] = False
         self.block_tile_grid[coordinates.get_array_index()] = True
Exemple #2
0
 def get_coord_from_tile(self, tile: Tile) -> Coordinates:
     coordinates = self.coordinates_from_index.get(tile.get_id())
     if coordinates is None:
         raise TileNotExistsException("tile: (" + str(tile) +
                                      ") was not added")
     # print("coord from tile: ", tile, "was", coordinates)
     return coordinates.copy()
Exemple #3
0
 def add_tile_to_grid(self, tile: Tile, coordinates: Coordinates):
     if self.tiles_from_index.get(tile.get_id()) is None:
         self.add_new_tile(tile)
     else:
         tile_coordinates = self.coordinates_from_index.get(tile.get_id())
         if tile_coordinates is not None:
             raise AddDuplicateTileError("tile " + str(tile) +
                                         " already exists on " +
                                         str(tile_coordinates))
     tile_on_coordinates = self.get_tile_from_grid(coordinates)
     if tile_on_coordinates is not None:
         raise TileTakenException(
             tile_on_coordinates,
             f"there is already tile: ({str(tile)}) on {str(coordinates)}")
     self.tile_grid[coordinates.get_array_index()] = tile.get_id()
     self.coordinates_from_index[tile.get_id()] = coordinates
     if tile.get_type() == TileType.BLOCK:
         self.block_tile_grid[coordinates.get_array_index()] = True
Exemple #4
0
 def update_tile(self, tile: Tile):
     self.tiles_from_index[tile.get_id()] = tile
Exemple #5
0
 def add_new_tile(self, tile: Tile):
     if self.tiles_from_index.get(tile.get_id()) is not None:
         raise TileAlreadyAddedException("tile " + str(tile) +
                                         " already exists")
     self.tiles_from_index[tile.get_id()] = tile