diff --git a/entities/gamemap.py b/entities/gamemap.py index 1b66dda..2ec92cf 100644 --- a/entities/gamemap.py +++ b/entities/gamemap.py @@ -66,32 +66,37 @@ class BrSimMap(): self.game_map[p_coord_y][p_coord_x]= item #self.game_map[i_coord_y][i_coord_x]= self.item_sym - def _set_coordinates(self, target): - x= _random.randint(1, self.world_width -2) # from 1 to width-2 because 1 cell is occupied by the mountain - y= _random.randint(1, self.world_height -2) + def _put_resource_on_map(self, target): + #x= _random.randint(1, self.world_width -2) # from 1 to width-2 because 1 cell is occupied by the mountain + #y= _random.randint(1, self.world_height -2) + x= _random.randint(0, self.world_width -1) + y= _random.randint(0, self.world_height -1) resource= self.get_map_matrix()[y][x] while resource: #while self.get_map_matrix()[y][x] != self.field_sym: - _logs.log_debug('_set_coordinates: collision, regenerate coordinates') - x= _random.randint(1, self.world_width -2) - y= _random.randint(1, self.world_height -2) + _logs.log_debug('_put_resource_on_map: collision, regenerate coordinates') + x= _random.randint(0, self.world_width -1) + y= _random.randint(0, self.world_height -1) + resource= self.get_map_matrix()[y][x] + print(f'{target.get_name()} >>> ({x},{y})') target.set_coordinates(x, y) + self.get_map_matrix()[y][x]= target def init_players_coordinates(self): for player in self.players: - self._set_coordinates(player) + self._put_resource_on_map(player) def init_items_coordinates(self): for item in self.items: - self._set_coordinates(item) + self._put_resource_on_map(item) def add_player_to_map(self, player): self.players.append(player) - self._set_coordinates(player) + self._put_resource_on_map(player) def add_item_to_map(self, item): self.items.append(item) - self._set_coordinates(item) + self._put_resource_on_map(item) def get_map_matrix(self): return self.game_map @@ -99,16 +104,37 @@ class BrSimMap(): def get_player_available_directions(self, Player): coord_x, coord_y= Player.get_coordinates() avail_directions= [] - if self.get_map_matrix()[coord_x - 1][coord_y] not in [self.mountain_sym]: + #XXX for now move only on available cells, no over other players/items + if coord_x > 0 and not self.get_map_matrix()[coord_x - 1][coord_y]: avail_directions.append((-1, 0, 'sinistra')) - if self.get_map_matrix()[coord_x + 1][coord_y] not in [self.mountain_sym]: + if coord_x < self.world_width -1 and not self.get_map_matrix()[coord_x + 1][coord_y]: avail_directions.append((1, 0, 'destra')) - if self.get_map_matrix()[coord_x][coord_y - 1] not in [self.mountain_sym]: + if coord_y > 0 and not self.get_map_matrix()[coord_x][coord_y - 1]: avail_directions.append((0, -1, 'su')) - if self.get_map_matrix()[coord_x][coord_y + 1] not in [self.mountain_sym]: + if coord_y < self.world_height -1 and not self.get_map_matrix()[coord_x][coord_y + 1]: avail_directions.append((0, 1, 'giu\'')) return avail_directions + def check_near_players(self): + # TODO Implement me + return True + + def check_near_items(self): + # TODO Implement me + return False + + def get_player_available_actions(self, Player): + # TODO: define actions list + coord_x, coord_y= Player.get_coordinates() + avail_actions= [] + + if self.check_near_players(Player): + avail_actions.append(1) #XXX replace with attack action (or maybe other actions on players) + if self.get_player_available_directions(Player): + avail_actions.append(2) #XXX replace with action move + if self.check_near_items(Items): + avail_actions.append(3) #XXX replace with get item action + def get_renderized_map(self): res= '' self.populate_map() @@ -118,7 +144,8 @@ class BrSimMap(): if not x: el= self.field_sym #XXX how to manage mountains? elif x.is_player(): - if x.player_gender_is_male(): el= self.player_male_sym + if not x.is_alive(): el= self.dead_player_sym + elif x.player_gender_is_male(): el= self.player_male_sym elif x.player_gender_is_female(): el= self.player_female_sym else: el= self.player_nonbinary_sym elif x.is_item():