def get_event(self, events, mouse_pos):
     for event in events:
         if event.type == pygame.QUIT:
             leave()
         if event.type == pygame.MOUSEBUTTONDOWN:
             for button in self.list_buttons:
                 if button.rect.collidepoint(mouse_pos):
                     show_loading_screen(self.screen)
                     button.on_clic(button.parameters)
 def calculate_actions_squares(self):
     """
     Calcule les cases disponibles en fonction des différentes actions
     """
     show_loading_screen(self.screen)
     self.available_movement_squares = {}
     self.available_attack_squares = []
     self.available_magic_squares = {}
     if self.current_player_action_points > 0:
         self.calculate_available_movement_squares()
         self.calculate_available_attack_squares()
         if self.current_hero.magic > 0:
             self.calculate_available_magic_squares()
         if self.current_hero.scope > 0:
             self.calculate_available_ranged_squares()
Exemple #3
0
 def start_overlay_points_left(self):
     """
     Compare le nombre de points restants avec le prix du héros le moins cher dans une liste de héros non
     sélectionnés.
     Si la team du premier joueur est vide, affecte l'équipe et passe à la deuxième instance de la page (ou à
     l'overlay indiquant qu'il reste des points le cas échéant), à la page de sélection du deck sinon.
     """
     capture = self.screen.copy()
     heroes_left = set(self.list_heroes) - set(
         hero for hero in self.list_in_team if hero.unique)
     if self.fplayer_team is None:
         for hero in self.list_in_team:
             # Indique le nom du joueur sur les héros sélectionnés
             hero.player_name = self.fplayer_name
         self.fplayer_team = self.list_in_team
         if min([hero.cost for hero in heroes_left]) < self.total_points - \
                 sum([hero.cost for hero in self.list_in_team]):
             overlay_points_left_team_selection.OverlayPointsLeftTeamSelection(
                 self.screen, capture, self.clock, self.total_points,
                 self.fplayer_name, self.splayer_name, self.fplayer_team,
                 self.splayer_team)
             self.fplayer_team = None
         else:
             show_loading_screen(self.screen)
             self.__init__((self.screen, self.clock, self.total_points,
                            self.fplayer_name, self.splayer_name,
                            self.fplayer_team, None, list()))
     else:
         for hero in self.list_in_team:
             # Indique le nom du joueur sur les héros sélectionnés
             hero.player_name = self.splayer_name
         self.splayer_team = self.list_in_team
         if min([hero.cost for hero in heroes_left]) < self.total_points - \
                 sum([hero.cost for hero in self.list_in_team]):
             overlay_points_left_team_selection.OverlayPointsLeftTeamSelection(
                 self.screen, capture, self.clock, self.total_points,
                 self.fplayer_name, self.splayer_name, self.fplayer_team,
                 self.splayer_team)
             self.splayer_team = None
         else:
             show_loading_screen(self.screen)
             deck_selection.DeckSelection(
                 (self.screen, self.clock, self.total_points,
                  self.fplayer_name, self.splayer_name, self.fplayer_team,
                  self.splayer_team, None, None, list()))
 def get_event(self, events, mouse_pos):
     for event in events:
         if event.type == pygame.QUIT:
             leave()
         if event.type == pygame.MOUSEBUTTONDOWN:
             for button in self.list_buttons:
                 if button.rect.collidepoint(mouse_pos):
                     if button.text == constants.Texts.NO:
                         self.to_return = True
                     else:
                         if self.splayer_team is None:
                             team_selection.TeamSelection((self.screen, self.clock, self.total_points,
                                                           self.fplayer_name, self.splayer_name, self.fplayer_team,
                                                           None, list()))
                         else:
                             show_loading_screen(self.screen)
                             deck_selection.DeckSelection((self.screen, self.clock, self.total_points,
                                                           self.fplayer_name, self.splayer_name, self.fplayer_team,
                                                           self.splayer_team, None, None, list()))
Exemple #5
0
 def get_event(self, events, mouse_pos):
     for event in events:
         # Events de la textbox de recherche
         self.text_box.get_event(event)
         if event.type == pygame.QUIT:
             leave()
         if event.type == pygame.MOUSEBUTTONDOWN:
             # Clic gauche
             if event.button == 1:
                 # Zoom de la carte
                 if self.button_image_zoom.rect.collidepoint(mouse_pos):
                     screen_capture = self.screen.copy()
                     overlay_zoom_card.OverlayZoomCard(
                         self.screen, screen_capture, self.clock,
                         self.current_card)
                 else:
                     # Sélectionne la carte
                     for card in self.current_cards[
                             self.start_list_card:self.end_list_card]:
                         if card.miniature_rect.collidepoint(mouse_pos):
                             if card == self.current_card and self.current_card.available > 0:
                                 if self.current_card.possessed - self.current_card.available < \
                                         self.current_card.limited_to:
                                     if sum(card.possessed - card.available for card in self.cards_in_deck) < \
                                             constants.DeckSelection.TOTAL_CARDS:
                                         self.add_card_in_deck()
                             self.current_card = card
                 # Clic sur les boutons images
                 for button in self.list_buttons_image:
                     if button.rect.collidepoint(mouse_pos):
                         # Si le bouton est actif, lance la fonction liée
                         if button.active:
                             button.on_clic()
                 # Clic sur les boutons texte liés aux listes de cartes
                 for button in self.list_buttons_text_lists_cards:
                     if button.rect.collidepoint(mouse_pos):
                         if button.active:
                             button.on_clic()
                 # Clic sur les boutons texte liés aux tris
                 for button in self.list_buttons_text_sort:
                     if button.rect.collidepoint(mouse_pos):
                         if button.active:
                             button.on_clic()
                 # Clic sur les boutons texte divers
                 for button in self.list_buttons:
                     if button.rect.collidepoint(mouse_pos):
                         if button.active:
                             if button.text == constants.Texts.REMOVE:
                                 button.on_clic(self.current_card)
                             elif button.text == constants.Texts.START:
                                 if self.fplayer_deck is None:
                                     self.fplayer_deck = self.cards_in_deck
                                     show_loading_screen(self.screen)
                                     self.__init__(
                                         (self.screen, self.clock,
                                          self.total_points,
                                          self.fplayer_name,
                                          self.splayer_name,
                                          self.fplayer_team,
                                          self.splayer_team,
                                          self.fplayer_deck,
                                          self.splayer_deck, list()))
                                 else:
                                     self.splayer_deck = self.cards_in_deck
                                     show_loading_screen(self.screen)
                                     heroes_deployment.HeroesDeployment(
                                         self.screen, self.clock,
                                         self.fplayer_name,
                                         self.splayer_name,
                                         self.fplayer_team,
                                         self.splayer_team,
                                         self.fplayer_deck,
                                         self.splayer_deck, False)
                             elif button.text == constants.Texts.BACK:
                                 if self.fplayer_deck is not None:
                                     self.__init__((self.screen, self.clock,
                                                    self.total_points,
                                                    self.fplayer_name,
                                                    self.splayer_name,
                                                    self.fplayer_team,
                                                    self.splayer_team, None,
                                                    self.splayer_deck,
                                                    self.fplayer_deck))
                                 else:
                                     team_selection.TeamSelection(
                                         (self.screen, self.clock,
                                          self.total_points,
                                          self.fplayer_name,
                                          self.splayer_name,
                                          self.fplayer_team, None,
                                          self.splayer_team))
                             else:
                                 if button.parameters is not None:
                                     button.on_clic(button.parameters)
                                 else:
                                     button.on_clic()
                 # Supprime une carte de la liste des cartes sélectionnées
                 for i in range(len(self.cards_in_deck)):
                     temp_rect = self.cards_in_deck[
                         i].surface_list_rect.inflate(-2, -2)
                     if temp_rect.collidepoint(mouse_pos):
                         self.del_card_in_deck(self.cards_in_deck[i])
                         break
             # Clic droit
             if event.button == 3:
                 # Supprime le héros si il est dans la liste des héros sélectionnés
                 for card in self.current_cards:
                     if card.miniature_rect.collidepoint(mouse_pos):
                         if card == self.current_card and card.search_card_in_list(
                                 self.cards_in_deck):
                             self.del_card_in_deck(self.current_card)
             # Scroll up
             elif event.button == 4:
                 if self.current_page * constants.DeckSelection.CARDS_PER_PAGE < len(
                         self.current_cards):
                     self.list_right()
             # Scroll down
             elif event.button == 5:
                 if self.current_page > 1:
                     self.list_left()
         if event.type == pygame.KEYDOWN:
             # Fléche de droite
             if event.key == pygame.K_RIGHT:
                 if (self.current_cards.index(self.current_card) +
                         1) % 5 != 0:
                     self.current_card = self.current_cards[
                         self.current_cards.index(self.current_card) + 1]
                 elif self.current_page * constants.DeckSelection.CARDS_PER_PAGE < len(
                         self.current_cards):
                     self.list_right()
                     if self.current_cards.index(
                             self.current_card) + 11 < len(
                                 self.current_cards):
                         self.current_card = self.current_cards[
                             self.current_cards.index(self.current_card) +
                             11]
                     else:
                         self.current_card = self.current_cards[
                             self.start_list_card]
             # Flèche de gauche
             if event.key == pygame.K_LEFT:
                 if self.current_cards.index(self.current_card) % 5 != 0:
                     self.current_card = self.current_cards[
                         self.current_cards.index(self.current_card) - 1]
                 elif self.current_page > 1:
                     self.list_left()
                     self.current_card = self.current_cards[
                         self.current_cards.index(self.current_card) - 11]
             # Flèche du haut
             if event.key == pygame.K_UP:
                 if self.current_cards.index(
                         self.current_card) - 5 > self.start_list_card:
                     self.current_card = self.current_cards[
                         self.current_cards.index(self.current_card) - 5]
             # Flèche du bas
             if event.key == pygame.K_DOWN:
                 if self.current_cards.index(
                         self.current_card) + 5 < self.end_list_card:
                     self.current_card = self.current_cards[
                         self.current_cards.index(self.current_card) + 5]
             # Page suivante
             if event.key == pygame.K_PAGEUP:
                 if self.current_page * constants.DeckSelection.CARDS_PER_PAGE < len(
                         self.current_cards):
                     self.list_right()
             # Page précédente
             if event.key == pygame.K_PAGEDOWN:
                 if self.current_page > 1:
                     self.list_left()
             # Touche entrée
             if event.key == pygame.K_RETURN:
                 if self.current_card.available > 0 and self.current_card.possessed - self.current_card.available < \
                         self.current_card.limited_to and sum(card.possessed - card.available
                                                              for card in self.cards_in_deck) < \
                         constants.DeckSelection.TOTAL_CARDS:
                     self.add_card_in_deck()
                 elif self.current_card.search_card_in_list(
                         self.cards_in_deck):
                     self.del_card_in_deck(self.current_card)
             # Touche supprimer
             if event.key == pygame.K_DELETE:
                 if self.current_card.search_card_in_list(
                         self.cards_in_deck):
                     self.del_card_in_deck(self.current_card)
     # Met à jour la position de l'image du zoom en fonction de la carte sélectionnée
     self.button_image_zoom.rect.centerx = self.current_card.miniature_rect.centerx
     self.button_image_zoom.rect.centery = self.current_card.miniature_rect.centery