Verify player is in bound of the map
This commit is contained in:
+18
@@ -24,6 +24,10 @@ class Map:
|
||||
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):
|
||||
for x in range(self.width):
|
||||
@@ -32,6 +36,13 @@ class Map:
|
||||
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
|
||||
block = self.get_block_at(x, y)
|
||||
@@ -56,3 +67,10 @@ class Map:
|
||||
string_array_row.append(block.to_string())
|
||||
string_array.append(string_array_row)
|
||||
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
|
||||
]
|
||||
Reference in New Issue
Block a user