Sanitizing data structure
This commit is contained in:
		@@ -22,28 +22,19 @@ class Map:
 | 
				
			|||||||
        lines = [line for line in lines if line]
 | 
					        lines = [line for line in lines if line]
 | 
				
			||||||
        height = len(lines)
 | 
					        height = len(lines)
 | 
				
			||||||
        width = len(lines[0])
 | 
					        width = len(lines[0])
 | 
				
			||||||
        chars = [[Tile.from_char(c, x, y)
 | 
					        return Map(width, height, lines)
 | 
				
			||||||
                  for x, c in enumerate(line)] for y, line in enumerate(lines)]
 | 
					 | 
				
			||||||
        return Map(width, height, chars)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Tile:
 | 
					 | 
				
			||||||
    x: int
 | 
					 | 
				
			||||||
    y: int
 | 
					 | 
				
			||||||
    char: str
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @staticmethod
 | 
					 | 
				
			||||||
    def from_char(c: str, x: int, y: int):
 | 
					 | 
				
			||||||
        t = Tile()
 | 
					 | 
				
			||||||
        t.x = x
 | 
					 | 
				
			||||||
        t.y = y
 | 
					 | 
				
			||||||
        t.char = c
 | 
					 | 
				
			||||||
        return c
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Entity:
 | 
					class Entity:
 | 
				
			||||||
    tile: Tile
 | 
					    y: int
 | 
				
			||||||
 | 
					    x: int
 | 
				
			||||||
 | 
					    img: str
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __init__(self, y: int, x: int, img: str):
 | 
				
			||||||
 | 
					        self.y = y
 | 
				
			||||||
 | 
					        self.x = x
 | 
				
			||||||
 | 
					        self.img = img
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def move(self, x: int, y: int) -> None:
 | 
					    def move(self, x: int, y: int) -> None:
 | 
				
			||||||
        self.tile.x = x
 | 
					        self.x = x
 | 
				
			||||||
        self.tile.y = y
 | 
					        self.y = y
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user