def init_online_menu(self): play_online_menu_2_players_game_button = Button( text_start_2_players_game, play_online_menu_2_players_game_button_px, play_online_menu_2_players_game_button_py, action=self.launch_work_in_progress_menu) play_online_menu_3_players_game_button = Button( text_start_3_players_game, play_online_menu_3_players_game_button_px, play_online_menu_3_players_game_button_py, action=self.launch_work_in_progress_menu) play_online_menu_return_to_main_menu_button = Button( text_return_to_menu, oneline_menu_return_to_main_menu_button_px, oneline_menu_return_to_main_menu_button_py) self.online_game_menu = Menu( self.main_menu, buttons=[ play_online_menu_2_players_game_button, play_online_menu_3_players_game_button ], quit_button=play_online_menu_return_to_main_menu_button)
def init_offline_menu(self): play_offline_menu_versus_ia_game_button = Button( text_start_game_versus_ia, play_offline_menu_versus_ia_game_button_px, play_offline_menu_versus_ia_game_button_py, action=self.create_game_versus_ia) play_offline_menu_tutorial_game_button = Button( text_tutotial, play_offline_menu_tutorial_game_button_px, play_offline_menu_tutorial_game_button_py, action=self.create_game_tutorial) play_offline_menu_test_game_button = Button( text_test_game, play_offline_menu_test_game_button_px, play_offline_menu_test_game_button_py, action=self.create_game) play_offline_menu_return_to_main_menu_button = Button( text_return_to_menu, play_offline_menu_return_to_main_menu_button_px, play_offline_menu_return_to_main_menu_button_py) self.offline_game_menu = Menu( self.main_menu, buttons=[ play_offline_menu_versus_ia_game_button, play_offline_menu_tutorial_game_button, play_offline_menu_test_game_button ], quit_button=play_offline_menu_return_to_main_menu_button)
def init_confirm_capitulate_menu(self): confirm_capitulate_menu_rect = RectCenter( quit_game_menu_px, quit_game_menu_py, confirm_capitulate_menu_width, confirm_capitulate_menu_height) confirm_capitulate_menu_message = Message( confirm_capitulate_menu_message_px, confirm_capitulate_menu_message_py, text_capitulate_game_question) confirm_capitulate_menu_yes_button = Button( text_yes, confirm_capitulate_menu_yes_button_px, confirm_capitulate_menu_yes_button_py, action=self.capitulate) confirm_capitulate_menu_no_button = Button( text_no, confirm_capitulate_menu_no_button_px, confirm_capitulate_menu_no_button_py) self.confirm_capitulate_menu = Menu( self, quit_button=confirm_capitulate_menu_no_button, buttons=[confirm_capitulate_menu_yes_button], messages=[confirm_capitulate_menu_message], rect=confirm_capitulate_menu_rect)
def init_in_game_menu(self): in_game_menu_rect = RectCenter(in_game_menu_px, in_game_menu_py, in_game_menu_width, in_game_menu_height) in_game_menu_capitulate_button = Button( text_capitulate_game, in_game_menu_capitulate_button_px, in_game_menu_capitulate_button_py, action=self.launch_confirm_capitulate_menu) in_game_menu_options_button = Button( text_options, in_game_menu_options_button_px, in_game_menu_options_button_py, action=self.parent.launch_options_menu) in_game_menu_return_to_game_button = Button( text_return_to_game, in_game_menu_return_to_game_button_px, in_game_menu_return_to_game_button_py) self.in_game_menu = Menu( self, buttons=[ in_game_menu_capitulate_button, in_game_menu_options_button ], quit_button=in_game_menu_return_to_game_button, rect=in_game_menu_rect)
def init_end_game_menu(self): end_game_menu_rect = RectCenter(end_game_menu_px, end_game_menu_py, end_game_menu_width, end_game_menu_height) end_game_menu_continue_button = Button( text_continue, end_game_menu_continue_button_px, end_game_menu_continue_button_py, action=self.end_game) self.end_game_menu = Menu(self, quit_button=end_game_menu_continue_button, messages=[], rect=end_game_menu_rect)
def init_work_in_progress_menu(self): work_in_progress_menu_rect = RectCenter(work_in_progress_menu_px, work_in_progress_menu_py, work_in_progress_menu_width, work_in_progress_menu_height) work_in_progress_menu_message = Message( work_in_progress_menu_message_px, work_in_progress_menu_message_py, text_work_in_progress) work_in_progress_menu_quit_button = Button( text_validate, work_in_progress_menu_quit_button_px, work_in_progress_menu_quit_button_py) self.work_in_progress_menu = Menu( self.main_menu, quit_button=work_in_progress_menu_quit_button, messages=[work_in_progress_menu_message], rect=work_in_progress_menu_rect)
def init_quit_game_menu(self): quit_game_menu_rect = RectCenter(quit_game_menu_px, quit_game_menu_py, quit_game_menu_width, quit_game_menu_height) quit_game_menu_message = Message(quit_game_menu_message_px, quit_game_menu_message_py, text_quit_game_question) quit_game_menu_yes_button = Button(text_yes, quit_game_menu_yes_button_px, quit_game_menu_yes_button_py, action=self.exit) quit_game_menu_no_button = Button(text_no, quit_game_menu_no_button_px, quit_game_menu_no_button_py) self.quit_game_menu = Menu(self, quit_button=quit_game_menu_no_button, buttons=[quit_game_menu_yes_button], messages=[quit_game_menu_message], rect=quit_game_menu_rect)
def init_main_menu(self): main_menu_play_online_button = Button( text_online_menu, main_menu_play_online_button_px, main_menu_play_online_button_py, action=self.launch_online_game_menu) main_menu_play_offline_button = Button( text_offline_menu, main_menu_play_offline_button_px, main_menu_play_offline_button_py, action=self.launch_offline_game_menu) main_menu_option_button = Button(text_options, main_menu_option_button_px, main_menu_option_button_py, action=self.launch_options_menu) main_menu_chest_button = Button( text_chest, main_menu_chest_button_px, main_menu_chest_button_py, action=self.launch_work_in_progress_menu) main_menu_quit_button = Button(text_quit_game, main_menu_quit_button_px, main_menu_quit_button_py, action=self.launch_quit_game_menu) self.main_menu = Menu(self, buttons=[ main_menu_play_online_button, main_menu_play_offline_button, main_menu_option_button, main_menu_chest_button, main_menu_quit_button ])
class Runes(): def __init__(self): #1 pygame.init() pygame.font.init() #2 #initialize the screen self.screen = pygame.display.set_mode((window_width, window_height)) pygame.display.set_caption("Runes") pygame.key.set_repeat(400, 30) #3 #initialize pygame clock self.clock = pygame.time.Clock() self.player = None self.init_connexion_menu() self.init_main_menu() self.init_quit_game_menu() self.init_options_menu() self.init_online_menu() self.init_offline_menu() self.init_work_in_progress_menu() def __bool__(self): # To avoid trying to draw this class with menus return False def create_game(self): game = Game(self, self.player) game.play_game() def create_game_versus_ia(self): game = GameOffline(self, self.player, self.screen) game.play_game() def create_game_tutorial(self): game = GameTutorial(self, self.player, self.screen) game.play_game() def exit(self): exit() def Quit(self): self.quit_game_menu.launch() # MENUS # CONNEXION MENU def init_connexion_menu(self): connexion_menu_choose_name_message = Message( connexion_menu_choose_name_message_px, connexion_menu_choose_name_message_py, text_enter_login) connexion_menu_name_input_box = InputBox( connexion_menu_name_input_box_px, connexion_menu_name_input_box_py, "", name='player_name') connexion_menu_choose_element_message = Message( connexion_menu_choose_element_message_px, connexion_menu_choose_element_message_py, text_choose_color) connexion_menu_red_choice = ColorBox(connexion_menu_red_choice_px, connexion_menu_red_choice_py, red, name='player_color') connexion_menu_blue_choice = ColorBox(connexion_menu_blue_choice_px, connexion_menu_blue_choice_py, blue, name='player_color') connexion_menu_yellow_choice = ColorBox( connexion_menu_yellow_choice_px, connexion_menu_yellow_choice_py, yellow, name='player_color') connexion_menu_green_choice = ColorBox(connexion_menu_green_choice_px, connexion_menu_green_choice_py, green, name='player_color') connexion_menu_brown_choice = ColorBox(connexion_menu_brown_choice_px, connexion_menu_brown_choice_py, brown, name='player_color') connexion_menu_grey_choice = ColorBox(connexion_menu_grey_choice_px, connexion_menu_grey_choice_py, grey, name='player_color') connexion_menu_purple_choice = ColorBox( connexion_menu_purple_choice_px, connexion_menu_purple_choice_py, purple, name='player_color') connexion_menu_clear_blue_choice = ColorBox( connexion_menu_clear_blue_choice_px, connexion_menu_clear_blue_choice_py, clearblue, name='player_color') connexion_menu_connect_button = Button( text_connexion, connexion_menu_connect_button_px, connexion_menu_connect_button_py, action=self.launch_main_menu) connexion_menu_quit_button = Button(text_quit_game, connexion_menu_quit_button_px, connexion_menu_quit_button_py, action=self.launch_quit_game_menu) connexion_menu_french_button = Button(None, connexion_menu_french_button_px, connexion_menu_french_button_py, image=french_flag_image_key, action=load_texts, parameters=(french_key)) connexion_menu_english_button = Button( None, connexion_menu_english_button_px, connexion_menu_english_button_py, image=english_flag_image_key, action=load_texts, parameters=(english_key)) self.connexion_menu = Menu( self, buttons=[ connexion_menu_french_button, connexion_menu_english_button, connexion_menu_connect_button, connexion_menu_quit_button ], inputs=[connexion_menu_name_input_box], messages=[ connexion_menu_choose_name_message, connexion_menu_choose_element_message ], colors=[ connexion_menu_red_choice, connexion_menu_blue_choice, connexion_menu_yellow_choice, connexion_menu_green_choice, connexion_menu_brown_choice, connexion_menu_grey_choice, connexion_menu_purple_choice, connexion_menu_clear_blue_choice ]) # MAIN MENU def init_main_menu(self): main_menu_play_online_button = Button( text_online_menu, main_menu_play_online_button_px, main_menu_play_online_button_py, action=self.launch_online_game_menu) main_menu_play_offline_button = Button( text_offline_menu, main_menu_play_offline_button_px, main_menu_play_offline_button_py, action=self.launch_offline_game_menu) main_menu_option_button = Button(text_options, main_menu_option_button_px, main_menu_option_button_py, action=self.launch_options_menu) main_menu_chest_button = Button( text_chest, main_menu_chest_button_px, main_menu_chest_button_py, action=self.launch_work_in_progress_menu) main_menu_quit_button = Button(text_quit_game, main_menu_quit_button_px, main_menu_quit_button_py, action=self.launch_quit_game_menu) self.main_menu = Menu(self, buttons=[ main_menu_play_online_button, main_menu_play_offline_button, main_menu_option_button, main_menu_chest_button, main_menu_quit_button ]) def launch_main_menu(self): #print(str(self.connexion_menu.parameters)) name = self.connexion_menu.parameters.get('player_name') color = self.connexion_menu.parameters.get('player_color') if not name or not color: return self.player = Player(name, color, self.screen) self.connexion_menu.run = False self.back_ground_menu = self.main_menu self.main_menu.launch() # OPTIONS MENU def init_options_menu(self): options_menu_french_button = Button(None, options_menu_french_button_px, options_menu_french_button_py, image=french_flag_image_key, action=load_texts, parameters=(french_key)) options_menu_english_button = Button(None, options_menu_english_button_px, options_menu_english_button_py, image=english_flag_image_key, action=load_texts, parameters=(english_key)) options_menu_choose_element_message = Message( options_menu_choose_element_message_px, options_menu_choose_element_message_py, text_choose_color) options_menu_red_choice = ColorBox(options_menu_red_choice_px, options_menu_red_choice_py, red, name='player_color') options_menu_blue_choice = ColorBox(options_menu_blue_choice_px, options_menu_blue_choice_py, blue, name='player_color') options_menu_yellow_choice = ColorBox(options_menu_yellow_choice_px, options_menu_yellow_choice_py, yellow, name='player_color') options_menu_green_choice = ColorBox(options_menu_green_choice_px, options_menu_green_choice_py, green, name='player_color') options_menu_brown_choice = ColorBox(options_menu_brown_choice_px, options_menu_brown_choice_py, brown, name='player_color') options_menu_grey_choice = ColorBox(options_menu_grey_choice_px, options_menu_grey_choice_py, grey, name='player_color') options_menu_purple_choice = ColorBox(options_menu_purple_choice_px, options_menu_purple_choice_py, purple, name='player_color') options_menu_clear_blue_choice = ColorBox( options_menu_clear_blue_choice_px, options_menu_clear_blue_choice_py, clearblue, name='player_color') options_online_menu_return_to_main_menu_button = Button( text_return_to_menu, options_online_menu_return_to_main_menu_button_px, options_online_menu_return_to_main_menu_button_py) self.options_menu = Menu( self.main_menu, buttons=[options_menu_french_button, options_menu_english_button], colors=[ options_menu_red_choice, options_menu_blue_choice, options_menu_yellow_choice, options_menu_green_choice, options_menu_brown_choice, options_menu_grey_choice, options_menu_purple_choice, options_menu_clear_blue_choice ], messages=[options_menu_choose_element_message], quit_button=options_online_menu_return_to_main_menu_button) def launch_options_menu(self): for color_box in self.options_menu.color_boxes: if color_box.color_key == self.player.color: color_box.active = True self.options_menu.parameters[ 'player_color'] = self.player.color self.options_menu.launch() self.player.color = self.options_menu.parameters.get('player_color') # ONLINE MENU def init_online_menu(self): play_online_menu_2_players_game_button = Button( text_start_2_players_game, play_online_menu_2_players_game_button_px, play_online_menu_2_players_game_button_py, action=self.launch_work_in_progress_menu) play_online_menu_3_players_game_button = Button( text_start_3_players_game, play_online_menu_3_players_game_button_px, play_online_menu_3_players_game_button_py, action=self.launch_work_in_progress_menu) play_online_menu_return_to_main_menu_button = Button( text_return_to_menu, oneline_menu_return_to_main_menu_button_px, oneline_menu_return_to_main_menu_button_py) self.online_game_menu = Menu( self.main_menu, buttons=[ play_online_menu_2_players_game_button, play_online_menu_3_players_game_button ], quit_button=play_online_menu_return_to_main_menu_button) def launch_online_game_menu(self): self.online_game_menu.launch() # OFFLINE MENU def init_offline_menu(self): play_offline_menu_versus_ia_game_button = Button( text_start_game_versus_ia, play_offline_menu_versus_ia_game_button_px, play_offline_menu_versus_ia_game_button_py, action=self.create_game_versus_ia) play_offline_menu_tutorial_game_button = Button( text_tutotial, play_offline_menu_tutorial_game_button_px, play_offline_menu_tutorial_game_button_py, action=self.create_game_tutorial) play_offline_menu_test_game_button = Button( text_test_game, play_offline_menu_test_game_button_px, play_offline_menu_test_game_button_py, action=self.create_game) play_offline_menu_return_to_main_menu_button = Button( text_return_to_menu, play_offline_menu_return_to_main_menu_button_px, play_offline_menu_return_to_main_menu_button_py) self.offline_game_menu = Menu( self.main_menu, buttons=[ play_offline_menu_versus_ia_game_button, play_offline_menu_tutorial_game_button, play_offline_menu_test_game_button ], quit_button=play_offline_menu_return_to_main_menu_button) def launch_offline_game_menu(self): self.offline_game_menu.launch() # WORK IN PROGRESS MENU def init_work_in_progress_menu(self): work_in_progress_menu_rect = RectCenter(work_in_progress_menu_px, work_in_progress_menu_py, work_in_progress_menu_width, work_in_progress_menu_height) work_in_progress_menu_message = Message( work_in_progress_menu_message_px, work_in_progress_menu_message_py, text_work_in_progress) work_in_progress_menu_quit_button = Button( text_validate, work_in_progress_menu_quit_button_px, work_in_progress_menu_quit_button_py) self.work_in_progress_menu = Menu( self.main_menu, quit_button=work_in_progress_menu_quit_button, messages=[work_in_progress_menu_message], rect=work_in_progress_menu_rect) def launch_work_in_progress_menu(self): self.work_in_progress_menu.launch() # QUIT GAME MENU def init_quit_game_menu(self): quit_game_menu_rect = RectCenter(quit_game_menu_px, quit_game_menu_py, quit_game_menu_width, quit_game_menu_height) quit_game_menu_message = Message(quit_game_menu_message_px, quit_game_menu_message_py, text_quit_game_question) quit_game_menu_yes_button = Button(text_yes, quit_game_menu_yes_button_px, quit_game_menu_yes_button_py, action=self.exit) quit_game_menu_no_button = Button(text_no, quit_game_menu_no_button_px, quit_game_menu_no_button_py) self.quit_game_menu = Menu(self, quit_button=quit_game_menu_no_button, buttons=[quit_game_menu_yes_button], messages=[quit_game_menu_message], rect=quit_game_menu_rect) def launch_quit_game_menu(self): self.quit_game_menu.launch() def draw(self, update=True): pass
def init_options_menu(self): options_menu_french_button = Button(None, options_menu_french_button_px, options_menu_french_button_py, image=french_flag_image_key, action=load_texts, parameters=(french_key)) options_menu_english_button = Button(None, options_menu_english_button_px, options_menu_english_button_py, image=english_flag_image_key, action=load_texts, parameters=(english_key)) options_menu_choose_element_message = Message( options_menu_choose_element_message_px, options_menu_choose_element_message_py, text_choose_color) options_menu_red_choice = ColorBox(options_menu_red_choice_px, options_menu_red_choice_py, red, name='player_color') options_menu_blue_choice = ColorBox(options_menu_blue_choice_px, options_menu_blue_choice_py, blue, name='player_color') options_menu_yellow_choice = ColorBox(options_menu_yellow_choice_px, options_menu_yellow_choice_py, yellow, name='player_color') options_menu_green_choice = ColorBox(options_menu_green_choice_px, options_menu_green_choice_py, green, name='player_color') options_menu_brown_choice = ColorBox(options_menu_brown_choice_px, options_menu_brown_choice_py, brown, name='player_color') options_menu_grey_choice = ColorBox(options_menu_grey_choice_px, options_menu_grey_choice_py, grey, name='player_color') options_menu_purple_choice = ColorBox(options_menu_purple_choice_px, options_menu_purple_choice_py, purple, name='player_color') options_menu_clear_blue_choice = ColorBox( options_menu_clear_blue_choice_px, options_menu_clear_blue_choice_py, clearblue, name='player_color') options_online_menu_return_to_main_menu_button = Button( text_return_to_menu, options_online_menu_return_to_main_menu_button_px, options_online_menu_return_to_main_menu_button_py) self.options_menu = Menu( self.main_menu, buttons=[options_menu_french_button, options_menu_english_button], colors=[ options_menu_red_choice, options_menu_blue_choice, options_menu_yellow_choice, options_menu_green_choice, options_menu_brown_choice, options_menu_grey_choice, options_menu_purple_choice, options_menu_clear_blue_choice ], messages=[options_menu_choose_element_message], quit_button=options_online_menu_return_to_main_menu_button)
def init_connexion_menu(self): connexion_menu_choose_name_message = Message( connexion_menu_choose_name_message_px, connexion_menu_choose_name_message_py, text_enter_login) connexion_menu_name_input_box = InputBox( connexion_menu_name_input_box_px, connexion_menu_name_input_box_py, "", name='player_name') connexion_menu_choose_element_message = Message( connexion_menu_choose_element_message_px, connexion_menu_choose_element_message_py, text_choose_color) connexion_menu_red_choice = ColorBox(connexion_menu_red_choice_px, connexion_menu_red_choice_py, red, name='player_color') connexion_menu_blue_choice = ColorBox(connexion_menu_blue_choice_px, connexion_menu_blue_choice_py, blue, name='player_color') connexion_menu_yellow_choice = ColorBox( connexion_menu_yellow_choice_px, connexion_menu_yellow_choice_py, yellow, name='player_color') connexion_menu_green_choice = ColorBox(connexion_menu_green_choice_px, connexion_menu_green_choice_py, green, name='player_color') connexion_menu_brown_choice = ColorBox(connexion_menu_brown_choice_px, connexion_menu_brown_choice_py, brown, name='player_color') connexion_menu_grey_choice = ColorBox(connexion_menu_grey_choice_px, connexion_menu_grey_choice_py, grey, name='player_color') connexion_menu_purple_choice = ColorBox( connexion_menu_purple_choice_px, connexion_menu_purple_choice_py, purple, name='player_color') connexion_menu_clear_blue_choice = ColorBox( connexion_menu_clear_blue_choice_px, connexion_menu_clear_blue_choice_py, clearblue, name='player_color') connexion_menu_connect_button = Button( text_connexion, connexion_menu_connect_button_px, connexion_menu_connect_button_py, action=self.launch_main_menu) connexion_menu_quit_button = Button(text_quit_game, connexion_menu_quit_button_px, connexion_menu_quit_button_py, action=self.launch_quit_game_menu) connexion_menu_french_button = Button(None, connexion_menu_french_button_px, connexion_menu_french_button_py, image=french_flag_image_key, action=load_texts, parameters=(french_key)) connexion_menu_english_button = Button( None, connexion_menu_english_button_px, connexion_menu_english_button_py, image=english_flag_image_key, action=load_texts, parameters=(english_key)) self.connexion_menu = Menu( self, buttons=[ connexion_menu_french_button, connexion_menu_english_button, connexion_menu_connect_button, connexion_menu_quit_button ], inputs=[connexion_menu_name_input_box], messages=[ connexion_menu_choose_name_message, connexion_menu_choose_element_message ], colors=[ connexion_menu_red_choice, connexion_menu_blue_choice, connexion_menu_yellow_choice, connexion_menu_green_choice, connexion_menu_brown_choice, connexion_menu_grey_choice, connexion_menu_purple_choice, connexion_menu_clear_blue_choice ])
class Game(object): # PROPERTIES # CONSTRUCTORS def __init__(self, parent, player): # Est ce qu'il n'y a pas une meilleur façon d'avoir acces a la couche du dessus ? self.parent = parent self.screen = self.parent.screen self.board = Board(self, size_of_board, size_of_board, rocks=Coin()) self.rect_up = pygame.Rect(0, 0, board_max_right, board_max_top) self.rect_left = pygame.Rect(0, board_max_top, board_max_left, board_max_bottom) self.rect_bottom = pygame.Rect(board_max_left, board_max_bottom, board_max_right, board_max_top) self.rect_right = pygame.Rect(board_max_right, 0, board_max_left, board_max_bottom) self.message = Message(0, 0, None) self.message.rect.width = self.rect_up.width self.message.rect.center = self.rect_up.center self.last_winner = None self.selected_card = None self.selected_case = None self.game_over = False self.round_over = False self.selected_case = None self.selected_card = None self.played = 0 self.turn_count = 0 self.rounds = rounds_to_win self.number_of_players = 2 self.turn = bool(Coin()) self.init_player(player) self.init_opponent() self.init_in_game_menu() self.init_end_round_menu() self.init_end_game_menu() self.init_confirm_capitulate_menu() # FUNCTIONS def play_game(self): while not self.game_over: self.new_round() self.message.text_key = text_choose_card self.draw() while not self.round_over: self.game_loop_function() if self.turn: self.play_player_turn(self.player) else: self.play_opponnent_turn() self.draw() if self.all_hands_are_empty(): self.launch_end_round_menu() if self.player.round == self.rounds or self.opponent.round == self.rounds: self.launch_end_game_menu() def play_player_turn(self, player): for event in pygame.event.get(): if event.type == pygame.QUIT: # confirmation message to capitulate. self.parent.Quit() elif event.type == pygame.KEYUP: if event.key == pygame.K_ESCAPE: self.in_game_menu.launch() elif event.type == pygame.MOUSEMOTION: pass elif event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: click_x = event.pos[0] click_y = event.pos[1] if not self.selected_card and not self.selected_case: self.selected_card = player.select_card( click_x, click_y) elif self.selected_card and not self.selected_case: self.selected_case = self.board.select_case( click_x, click_y) if not self.selected_case: self.selected_card = player.select_card( click_x, click_y) elif self.selected_card and self.selected_case: if self.board.has_click_on_selected_case( click_x, click_y): self.play_selected_card(player) else: self.selected_case = self.board.select_case( click_x, click_y) if not self.selected_card and not self.selected_case: self.message.text_key = text_choose_card elif self.selected_card and not self.selected_case: self.message.text_key = text_choose_case elif self.selected_card and self.selected_case: self.message.text_key = text_validate_case def actualize_turn_count(self): self.played += 1 if self.played == self.number_of_players: self.turn_count += 1 self.played = 0 def actualize_scores(self): self.player.score = self.board.get_player_score(self.player.number) self.opponent.score = self.board.get_player_score(self.opponent.number) def all_hands_are_empty(self): return len(self.player.hand) == 0 and len(self.opponent.hand) == 0 # MENUS def init_end_round_menu(self): end_round_menu_rect = RectCenter(end_round_menu_px, end_round_menu_py, end_round_menu_width, end_round_menu_height) end_round_menu_continue_button = Button( text_continue, end_round_menu_continue_button_px, end_round_menu_continue_button_py, action=self.end_round) self.end_round_menu = Menu(self, quit_button=end_round_menu_continue_button, messages=[], rect=end_round_menu_rect) def launch_end_round_menu(self): draw = self.player.score == self.opponent.score if draw: end_round_menu_message = Message(end_round_menu_message_px, end_round_menu_message_py, text_draw) else: winner = self.player if self.player.score > self.opponent.score else self.opponent winner.round += 1 self.last_winner = winner end_round_menu_message = Message(end_round_menu_message_px, end_round_menu_message_py, text_player_won_round, argument=winner.name) self.end_round_menu.messages = [end_round_menu_message] self.end_round_menu.launch() def init_end_game_menu(self): end_game_menu_rect = RectCenter(end_game_menu_px, end_game_menu_py, end_game_menu_width, end_game_menu_height) end_game_menu_continue_button = Button( text_continue, end_game_menu_continue_button_px, end_game_menu_continue_button_py, action=self.end_game) self.end_game_menu = Menu(self, quit_button=end_game_menu_continue_button, messages=[], rect=end_game_menu_rect) def launch_end_game_menu(self): winner = self.player if self.player.score == self.rounds else self.opponent end_game_menu_message = Message(end_game_menu_message_px, end_game_menu_message_py, text_player_won, argument=winner.name) self.end_game_menu.messages = [end_game_menu_message] self.end_game_menu.launch() def init_confirm_capitulate_menu(self): confirm_capitulate_menu_rect = RectCenter( quit_game_menu_px, quit_game_menu_py, confirm_capitulate_menu_width, confirm_capitulate_menu_height) confirm_capitulate_menu_message = Message( confirm_capitulate_menu_message_px, confirm_capitulate_menu_message_py, text_capitulate_game_question) confirm_capitulate_menu_yes_button = Button( text_yes, confirm_capitulate_menu_yes_button_px, confirm_capitulate_menu_yes_button_py, action=self.capitulate) confirm_capitulate_menu_no_button = Button( text_no, confirm_capitulate_menu_no_button_px, confirm_capitulate_menu_no_button_py) self.confirm_capitulate_menu = Menu( self, quit_button=confirm_capitulate_menu_no_button, buttons=[confirm_capitulate_menu_yes_button], messages=[confirm_capitulate_menu_message], rect=confirm_capitulate_menu_rect) def launch_confirm_capitulate_menu(self): self.confirm_capitulate_menu.launch() # OVERRIDED FUNCTIONS def init_in_game_menu(self): in_game_menu_rect = RectCenter(in_game_menu_px, in_game_menu_py, in_game_menu_width, in_game_menu_height) in_game_menu_capitulate_button = Button( text_capitulate_game, in_game_menu_capitulate_button_px, in_game_menu_capitulate_button_py, action=self.launch_confirm_capitulate_menu) in_game_menu_options_button = Button( text_options, in_game_menu_options_button_px, in_game_menu_options_button_py, action=self.parent.launch_options_menu) in_game_menu_return_to_game_button = Button( text_return_to_game, in_game_menu_return_to_game_button_px, in_game_menu_return_to_game_button_py) self.in_game_menu = Menu( self, buttons=[ in_game_menu_capitulate_button, in_game_menu_options_button ], quit_button=in_game_menu_return_to_game_button, rect=in_game_menu_rect) def init_player(self, player): self.player = player self.player.number = 0 self.player.rect = self.rect_left self.player.reset_hand() def init_opponent(self): self.opponent = Player("myself", blue, self.screen) self.opponent.number = 1 self.opponent.rect = self.rect_right self.opponent.reset_hand() def capitulate(self): self.opponent.round = self.rounds self.round_over = True self.game_over = True self.confirm_capitulate_menu.run = False self.in_game_menu.run = False self.draw() def play_selected_card(self, player): player.unselect_all_cards() self.board.unselect_all_cases() card = player.get_card(self.selected_card.number) self.draw() self.board.play(card, self.selected_case, None) self.actualize_scores() self.turn = not self.turn self.selected_case = None self.selected_card = None self.actualize_turn_count() def play_opponnent_turn(self): self.message.text_key = text_opponent_turn self.play_player_turn(self.opponent) def game_loop_function(self): pass def new_round(self): self.player.reset_hand() self.opponent.reset_hand() self.board = Board(self, size_of_board, size_of_board, rocks=True) if self.last_winner: if self.last_winner.number != self.player.number: self.turn = True else: self.turn = False self.actualize_scores() self.round_over = False self.turn_count = 0 self.played = 0 def end_round(self): self.end_round_menu.run = False self.round_over = True def end_game(self): self.game_over = True self.player.round = 0 self.opponent.round = 0 self.player.hand = [] self.opponent.hand = [] # DRAWING FUNCTION def draw(self, update=True): self.screen.fill(get_color(white)) text_turn = get_text(text_turn_count, text_completion=str(self.turn_count)) self.screen.blit(get_text_image(text_turn), (self.rect_up.x + 10, self.rect_up.y + 10)) self.player.draw() if self.opponent is not None: self.opponent.draw(card_hidden=False) pygame.draw.rect(self.screen, get_color(black), self.rect_up, border) pygame.draw.rect(self.screen, get_color(black), self.rect_left, border) pygame.draw.rect(self.screen, get_color(black), self.rect_bottom, border) pygame.draw.rect(self.screen, get_color(black), self.rect_right, border) self.message.draw(self.screen) self.board.draw(update=False) if update: pygame.display.update()