diff --git a/fr/naulan/supermariobros/src/maps/engine.py b/fr/naulan/supermariobros/src/maps/maps_generator.py similarity index 94% rename from fr/naulan/supermariobros/src/maps/engine.py rename to fr/naulan/supermariobros/src/maps/maps_generator.py index 103f6fa..b213879 100644 --- a/fr/naulan/supermariobros/src/maps/engine.py +++ b/fr/naulan/supermariobros/src/maps/maps_generator.py @@ -11,14 +11,14 @@ from fr.naulan.supermariobros.src.maps.type_of_map import TypeOfMap -class MapsEngine(object): +class MapsGenerator(object): SEPARATOR = ',' data = list() def new(self, raw_data: Union[str, List], name: str, have_header: bool = True) -> None: lines = raw_data.splitlines() if isinstance(raw_data, str) else raw_data - tile_width = len(lines[0 if not have_header else 1].split(MapsEngine.SEPARATOR)) + tile_width = len(lines[0 if not have_header else 1].split(MapsGenerator.SEPARATOR)) tile_height = len(lines) # Load camera @@ -36,7 +36,7 @@ def new(self, raw_data: Union[str, List], name: str, have_header: bool = True) - player = None sprites = LayeredUpdates() for y, line in enumerate(lines[0:] if have_header else lines): - columns = line.split(MapsEngine.SEPARATOR) + columns = line.split(MapsGenerator.SEPARATOR) for x, col in enumerate(columns): type_of_tile = int(col) if type_of_tile != TypeOfTile.EMPTY: diff --git a/fr/naulan/supermariobros/src/res/matrices/0.txt b/fr/naulan/supermariobros/src/res/matrices/0.txt index 2a08b3e..e7c7747 100644 --- a/fr/naulan/supermariobros/src/res/matrices/0.txt +++ b/fr/naulan/supermariobros/src/res/matrices/0.txt @@ -1 +1,5 @@ -type_of_map:1 \ No newline at end of file +type_of_map:1 +0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0 +0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0 +0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0,0;0 +1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0,1;0 \ No newline at end of file diff --git a/fr/naulan/supermariobros/test/maps_engine_test.py b/fr/naulan/supermariobros/test/maps_engine_test.py index 9a575e5..8f3fd4c 100644 --- a/fr/naulan/supermariobros/test/maps_engine_test.py +++ b/fr/naulan/supermariobros/test/maps_engine_test.py @@ -1,7 +1,9 @@ +import os + from unittest import TestCase from fr.naulan.supermariobros.src.entities.player import Player -from fr.naulan.supermariobros.src.maps.engine import MapsEngine +from fr.naulan.supermariobros.src.maps.maps_generator import MapsGenerator class MapsEngineTest(TestCase): @@ -9,31 +11,29 @@ def test_empty_map(self): """ Test with full empty tiles """ - maps_engine = MapsEngine() + maps_generator = MapsGenerator() - raw_data = open("./res/matrices/empty.txt", "r") - maps_engine.new(raw_data.readlines(), raw_data.name, False) - self.assertTrue(len(maps_engine.data) == 1, "Have a map generated") + with open(os.getcwd() + "/fr/naulan/supermariobros/test/res/matrices/empty.txt", "r") as f: + maps_generator.new(f.readlines(), f.name, False) + self.assertTrue(len(maps_generator.data) == 1, "Have a map generated") - empty_map = maps_engine.data[0] + empty_map = maps_generator.data[0] self.assertTrue(len(empty_map.data) == 0, "Is really empty") - raw_data.close() def test_player(self): """ Test with only player on the map """ - maps_engine = MapsEngine() + maps_generator = MapsGenerator() - raw_data = open("./res/matrices/player.txt", "r") - maps_engine.new(raw_data.readlines(), raw_data.name, False) - self.assertTrue(len(maps_engine.data) == 1, "Have a map generated") + with open(os.getcwd() + "/fr/naulan/supermariobros/test/res/matrices/player.txt", "r") as f: + maps_generator.new(f.readlines(), f.name, False) + self.assertTrue(len(maps_generator.data) == 1, "Have a map generated") - player_map = maps_engine.data[0] + player_map = maps_generator.data[0] self.assertTrue(len(player_map.data) == 1, "Have player into the list of entities") self.assertTrue(isinstance(player_map.player, Player), "Is really a player ?") player = player_map.player self.assertTrue(player.x == 4*16, "Generated at a good position on x axis") self.assertTrue(player.y == 16, "Generated at a good position on y axis") - raw_data.close()