Add some comments
This commit is contained in:
@ -3,6 +3,10 @@ from enum import Enum
|
||||
|
||||
|
||||
class Map:
|
||||
"""
|
||||
Object that represents a Map with its width, height
|
||||
and the whole tiles, with their custom properties.
|
||||
"""
|
||||
width: int
|
||||
height: int
|
||||
tiles: list
|
||||
@ -14,12 +18,18 @@ class Map:
|
||||
|
||||
@staticmethod
|
||||
def load(filename: str):
|
||||
"""
|
||||
Read a file that contains the content of a map, and build a Map object.
|
||||
"""
|
||||
with open(filename, "r") as f:
|
||||
file = f.read()
|
||||
return Map.load_from_string(file)
|
||||
|
||||
@staticmethod
|
||||
def load_from_string(content: str):
|
||||
"""
|
||||
Load a map represented by its characters and build a Map object.
|
||||
"""
|
||||
lines = content.split("\n")
|
||||
lines = [line for line in lines if line]
|
||||
height = len(lines)
|
||||
@ -29,6 +39,10 @@ class Map:
|
||||
return Map(width, height, tiles)
|
||||
|
||||
def draw_string(self) -> str:
|
||||
"""
|
||||
Draw the current map as a string object that can be rendered
|
||||
in the window.
|
||||
"""
|
||||
return "\n".join("".join(tile.value for tile in line)
|
||||
for line in self.tiles)
|
||||
|
||||
@ -42,6 +56,9 @@ class Tile(Enum):
|
||||
return self == Tile.WALL
|
||||
|
||||
def can_walk(self) -> bool:
|
||||
"""
|
||||
Check if an entity (player or not) can move in this tile.
|
||||
"""
|
||||
return not self.is_wall()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user