diff --git a/bot.py b/bot.py index bfa41ab..119f81c 100644 --- a/bot.py +++ b/bot.py @@ -24,7 +24,7 @@ async def bot_start(update, context): ['Init/Restart'], ['Add Player', 'Add random Players', 'Add random color Players'], ['Get Players', 'Get Alive Players', 'Get Death Players', 'Get Ranking Players',], - ['Simulate Day', 'Run Periodically'] + ['Simulate Day', 'Run Periodically', 'Show Map'] ] reply_markup= ReplyKeyboardMarkup(keyboard, one_time_keyboard=False, resize_keyboard=True) @@ -64,6 +64,8 @@ async def bot_commands(update, context): return await _cmd.cmd_add_random_players(context, update, chat_id) if text == 'Add random color Players': return await _cmd.cmd_add_random_color_players(context, update, chat_id) + if text == 'Show Map': + return await _cmd.cmd_show_game_map(context, update, chat_id) # special commands if text == 'upstart': return await _scmd.update_bot(update, context) diff --git a/bot_libs/commands_handling.py b/bot_libs/commands_handling.py index 5d703c0..a6ac0a6 100644 --- a/bot_libs/commands_handling.py +++ b/bot_libs/commands_handling.py @@ -61,6 +61,12 @@ async def cmd_get_ranking_players(context, update, chat_id): async def cmd_simulate_day(context, update, chat_id): return await _bot_simulation.simulate_day(context, chat_id) +async def cmd_show_game_map(context, update, chat_id): + Arena= context.application.bot_data['arena'] + Gamemap= Arena.get_map() + rendered_map= Gamemap.get_renderized_map() + return await update.message.reply_text(rendered_map) + async def cmd_simulate_day_cron(context, update, chat_id): context.application.bot_data['ask_seconds'] = 1 if 'ask_name' in context.application.bot_data: diff --git a/bot_libs/player_handling.py b/bot_libs/player_handling.py index 5789012..78af5b7 100644 --- a/bot_libs/player_handling.py +++ b/bot_libs/player_handling.py @@ -5,7 +5,8 @@ from bot_libs import syms as _bot_syms async def add_player(update, context, chat_id, name): _log.log_info(f'add_player: {chat_id} - {name}') Arena= context.application.bot_data['arena'] - if len(Arena.get_players()) >= 70: return # prevent message too long error + #if len(Arena.get_players()) >= 70: return # prevent message too long error + if len(Arena.get_players()) >= 20: return # maybe this should depend on the map dimension Arena.add_player(name) async def add_random_players(update, context, chat_id, colors_names= False): diff --git a/entities/arena.py b/entities/arena.py index 9756b40..626fcb8 100644 --- a/entities/arena.py +++ b/entities/arena.py @@ -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 diff --git a/entities/map.py b/entities/gamemap.py similarity index 87% rename from entities/map.py rename to entities/gamemap.py index ddcc8a7..6dfb390 100644 --- a/entities/map.py +++ b/entities/gamemap.py @@ -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