Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite maps generator #21

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion fr/naulan/supermariobros/src/res/matrices/0.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
type_of_map:1
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
26 changes: 13 additions & 13 deletions fr/naulan/supermariobros/test/maps_engine_test.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
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):
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()