diff --git a/game/map.py b/game/map.py index 6bb41f7..82e42f6 100644 --- a/game/map.py +++ b/game/map.py @@ -23,6 +23,10 @@ class Map: if 0 <= x < self.width and 0 <= y < self.height: return self.layout[y][x] return None + + def is_position_in_bounds(self, position): + x, y = position + return 0 <= x < self.width and 0 <= y < self.height def get_first_block_type_position(self, block_type): for y in range(self.height): @@ -31,6 +35,13 @@ class Map: if block and block.type == block_type: return (x, y) return None + + def count_blocks_of_type(self, block_type): + return sum( + block is not None and block.type == block_type + for row in self.layout + for block in row + ) def get_block_type_at_position(self, position): x, y = position @@ -55,4 +66,11 @@ class Map: else: string_array_row.append(block.to_string()) string_array.append(string_array_row) - return string_array \ No newline at end of file + return string_array + + def to_type_dict(self): + """Returns a matrix containing block types and None for empty spaces.""" + return [ + [block.type if block is not None else None for block in row] + for row in self.layout + ] \ No newline at end of file