1
0

show players and items on the map

This commit is contained in:
andrea
2025-07-28 20:03:08 +02:00
parent 37578437f6
commit 9653965d2b
3 changed files with 45 additions and 12 deletions

View File

@@ -23,3 +23,7 @@ class BrSimItem():
def get_item_coordinates(self):
return self.coord_x, self.coord_y
def set_item_coordinates(self, x, y):
self.coord_x= x
self.coord_y= y

View File

@@ -1,20 +1,27 @@
import random as _random
import copy as _copy
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.world_width= 10 #seems a reasonable width for smartphones larger maps would go on a new line
self.world_height= 25
self.game_map= []
self.field_sym= '🟩'
self.player_sym= '🟠'
self.player_male_sym= '♂️'
self.player_female_sym= '♀️'
self.player_nonbinary_sym= '⚧️'
self.dead_player_sym= '💀'
self.item_sym= '📦'
self.mountain_sym = '⛰️'
self.init_map_matrix()
self.init_players_coordinates()
self.init_items_coordinates()
self.init_map_matrix()
self.populate_map()
def init_map_matrix(self):
# show a matrix representing the game's map
@@ -33,15 +40,19 @@ class BrSimMap():
if i == 0 or i == self.world_width - 1: width.append(self.mountain_sym)
else: width.append(self.field_sym)
for i in range(self.world_height):
if i == 0 or i == self.world_width - 1: self.game_map.append(mon)
else: self.game_map.append(width)
if i == 0 or i == self.world_height - 1: self.game_map.append(mon)
else: self.game_map.append(_copy.deepcopy(width))
_logs.log_debug(f'init_map_matrix: {self.game_map}')
def populate_map(self):
for player in self.players:
p_coord_x, p_coord_y= players.get_player_coordinates()
self.game_map[p_coord_y][p_coord_x]= self.player_sym
p_coord_x, p_coord_y= player.get_player_coordinates()
if player.player_gender_is_male(): self.game_map[p_coord_y][p_coord_x]= self.player_male_sym
elif player.player_gender_is_female(): self.game_map[p_coord_y][p_coord_x]= self.player_female_sym
else: self.game_map[p_coord_y][p_coord_x]= self.player_nonbinary_sym
for item in self.items:
i_coord_x, i_coord_y= item.get_item_coordinates()
self.game_map[i_coord_y][i_coord_x]= self.item_sym
_logs.log_debug(f'init_map_matrix: {self.game_map}')
def get_map_matrix(self):
return self.game_map
@@ -58,9 +69,23 @@ class BrSimMap():
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
for player in self.players:
x= _random.randint(1, self.world_width -2) # -2 because 1 cell is occupied by the mountain
y= _random.randint(1, self.world_height -2)
while self.get_map_matrix()[y][x] != self.field_sym:
print('init_players_coordinates: collision, regenerate coordinates')
x= _random.randint(1, self.world_width -2)
y= _random.randint(1, self.world_height -2)
player.set_player_coordinates(x, y)
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
for item in self.items:
x= _random.randint(1, self.world_width -2) # -2 because 1 cell is occupied by the mountain
y= _random.randint(1, self.world_height -2)
while self.get_map_matrix()[y][x] != self.field_sym:
print('init_items_coordinates: collision, regenerate coordinates')
x= _random.randint(1, self.world_width -2)
y= _random.randint(1, self.world_height -2)
item.set_item_coordinates(x, y)

View File

@@ -25,7 +25,11 @@ class BrSimPlayer():
### control methods
def get_player_coordinates(self):
return self.coord_x. self.coord_y
return self.coord_x, self.coord_y
def set_player_coordinates(self, x, y):
self.coord_x= x
self.coord_y= y
def get_name_and_stats(self):
health= '♥️' * self.health or '☠️'