define Map class with basics rendering and parsing methods

This commit is contained in:
andrea
2025-07-27 23:23:21 +02:00
parent 172b387dcc
commit a7fd66e9e4

57
entities/map.py Normal file
View File

@@ -0,0 +1,57 @@
from utils import logs as _logs
class BrSimMap():
def __init__(self, players= None, items= None):
self.players= players or []
self.items= items or []
self.world_width= 15 #seems a reasonable width for smartphones larger maps would go on a new line
self.world_height= 15
self.game_map= []
self.field_sym= '🟩'
self.player_sym= '🟠'
self.item_sym= '📦'
self.init_players_coordinates()
self.init_items_coordinates()
self.init_map_matrix()
def init_map_matrix(self):
# TODO map matrix:
# show a matrix representing the game's map
# 🟩 is and empty cell
# (tomorrow we can choose different colors for different locations
# 🟠 this is a player (we could use different colors for different genders)
# 📦 this is an item (weapon or another item)
width= []
for i in range(self.world_width):
width.append(self.field_sym)
for i in range(self.world_height):
self.game_map.append(width)
# TODO add players and items on map
for player in self.players:
self.game_map[player.coord_y][player.coord_x]= self.player_sym
for item in self.items:
self.game_map[item.coord_y][item.coord_x]= self.item_sym
_logs.log_debug(f'init_map_matrix: {self.game_map}')
def get_map_matrix(self):
return self.game_map
def get_renderized_map(self):
res= ''
game_map= self.get_map_matrix()
for y in game_map:
for x in y:
res+= x
res+= '\n'
return res
def init_players_coordinates(self):
# XXX init random player.coord_x and player.coord_y (of course not already used coords)
# parse all self.players and define random coordinates (player.coord_x, and player.coord_y)
pass
def init_items_coordinates(self):
# XXX init random item.coord_x and item.coord_y (of course not already used coords)
# parse all self.items and define random coordinates (item.coord_x, and item.coord_y)
pass