1
0

show map with players on telegram bot

This commit is contained in:
andrea
2025-07-28 20:45:42 +02:00
parent 5002890540
commit 56da6031f2
5 changed files with 48 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
from entities import player as _player
from entities import event_picker as _events
from entities import gamemap as _map
from entities.items import weapons as _weapons
class BrSimArena():
@@ -14,6 +15,7 @@ class BrSimArena():
self.eventClass = _events.ArenaEventPicker(self.players)
self.init_players(players)
self.init_weapons(weapons)
self.Map= _map.BrSimMap(self.players, self.weapons)
def init_players(self, players):
if not players: return
@@ -110,10 +112,12 @@ class BrSimArena():
def add_player(self, name, inventory= None):
player= _player.BrSimPlayer(name, inventory)
self.players.append(player)
self.Map.add_player_to_map(player)
def add_weapon(self, weapon_type):
weapon= _weapons.BrSimWeapon(weapon_type)
self.weapons.append(weapon)
self.Map.add_item_to_map(item)
def get_players(self):
return self.players
@@ -124,3 +128,6 @@ class BrSimArena():
#XXX implement me
res.append(w)
return res
def get_map(self):
return self.Map

View File

@@ -54,38 +54,44 @@ class BrSimMap():
i_coord_x, i_coord_y= item.get_item_coordinates()
self.game_map[i_coord_y][i_coord_x]= self.item_sym
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)
for player in self.players:
def _set_coordinates(self, target):
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)
target.set_player_coordinates(x, y)
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)
for player in self.players:
self._set_coordinates(target)
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)
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)
self._set_coordinates(item)
def add_player_to_map(self, player):
self.players.append(player)
self._set_coordinates(player)
def add_item_to_map(self, item):
self.items.append(item)
self._set_coordinates(item)
def get_map_matrix(self):
return self.game_map
def get_renderized_map(self):
res= ''
self.populate_map()
game_map= self.get_map_matrix()
for y in game_map:
for x in y:
res+= x
res+= '\n'
return res