def __init__(self, current_player: PlayerModel): super().__init__(current_player) if VehiclePlacementController._instance: self._current_player = current_player # raise Exception(f"{VehiclePlacementController.__name__} is a singleton!") self.choose_engine_prompt = RectLabel( 500, 30, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Choose Engine Position", Color.GREEN2)) self.choose_engine_prompt.change_bg_image(WOOD) self.choose_engine_prompt.add_frame(FRAME) self.choose_ambulance_prompt = RectLabel( 500, 30, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Choose Ambulance Position", Color.GREEN2)) self.choose_ambulance_prompt.change_bg_image(WOOD) self.choose_ambulance_prompt.add_frame(FRAME) self.wait_prompt = RectLabel( 500, 580, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Host Is Placing Vehicles...", Color.GREEN2)) self.wait_prompt.change_bg_image(WOOD) self.wait_prompt.add_frame(FRAME) self.game_board_sprite = GameBoard.instance() self.ambulance_placed = False self.engine_placed = False VehiclePlacementController._instance = self
def draw(self, screen): self.button.draw(screen) x_offset1 = 0 y_offset1 = 0 if self.menu_shown: if self.button_input.enabled: screen.blit(self.button_input.image, self.button_input.rect) if self.orientation == "vertical": x_offset1 = -22 y_offset1 = 40 if self.orientation == "horizontal": x_offset1 = 34 y_offset1 = -18 if self.destroyed: self.marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 50, 50, "media/Threat_Markers/damageMarker.png") self.marker.draw(screen) if self.open: self.marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 50, 50, "media/Door_Markers/Open_Door.png") self.marker.draw(screen) if self.closed: self.marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 50, 50, "media/Door_Markers/Closed_Door.png") self.marker.draw(screen)
def _init_background_player(self, rect): if not self._game.rules == GameKindEnum.FAMILY and self._current_player.role: role_path = self.get_path_from_character_enum( self._current_player.role) user_box = RectLabel(rect[0], rect[1], rect[2], rect[3], role_path) else: user_box = RectLabel(rect[0], rect[1], rect[2], rect[3], MEDIA_CONSTS.FAMILY) return user_box
def _init_back_box(self, x_pos: int, y_pos: int, text: str, color: Color, color_text: Color): user_box = RectLabel( x_pos, y_pos, 500, 500, color, 0, Text(pygame.font.SysFont('Agency FB', 25), text, color_text)) self.sprite_grp.add(user_box)
def _init_slots(self): """ Initialize the profile slots :return: """ # margin between two buttons margin = 30 width = (self.width / self._limit) - margin height = self.height - 40 for i in range(self._limit): # draw the profile button for each profile x = self.x + ((width + margin) * i) + (margin / 2) y = self.y + 20 btn = RectButton( x, y, width, height, color.STANDARDBTN, 0, Text(pygame.font.SysFont('Agency FB', 25), "Empty", color.BLACK)) remove_btn = RectButton( btn.x, (btn.y + self.height - 80) + 10, btn.width, 30, color.YELLOW, 0, Text(pygame.font.SysFont('Agency FB', 16), "Remove", color.BLACK)) s = RectLabel( btn.x, (btn.y + self.height - 120), btn.width, 30, color.STANDARDBTN, 0, Text(pygame.font.SysFont('Agency FB', 16), "dadsad", color.BLACK)) s.set_transparent_background(True) self._stats_list.append(s) self._remove_btn_list.append(remove_btn) self._btn_list.append(btn) self._profile_list.add(btn)
def _init_text_box(self, position, text, color): box_size = (position[2], position[3]) user_box = RectLabel( position[0], position[1], box_size[0], box_size[1], color, 0, Text(pygame.font.SysFont('Agency FB', 20), text, (0, 255, 0, 0))) return user_box
def _init_message_box(self): message_box_x = self.offset message_box_w = self.chat_history_bg.rect.w - 2 * self.offset message_box_h = TEXT_BOX_FONT_SIZE + 2 chat_hist_bottom = self.chat_history_bg.rect.h max_messages = math.floor(self.chat_history_bg.rect.h / message_box_h) count = 0 self.to_be_renamed = [] for old_message in reversed(self.chat_history): if count < max_messages: message_box_y = chat_hist_bottom - (message_box_h * (count + 1)) old_message_box = RectLabel( message_box_x, message_box_y, message_box_w, message_box_h, background=Color.WHITE, txt_pos=Text.Position.LEFT, txt_obj=Text(font=pg.font.SysFont("Agency FB", TEXT_BOX_FONT_SIZE - 2), text=f"{old_message[1]}: {old_message[0]}")) self.to_be_renamed.append(old_message_box) count += 1 else: break
def __init__(self): self.bg = pygame.image.load(WOOD) self.frame = pygame.image.load(FRAME) self.frame = pygame.transform.scale(self.frame, (400, 100)) self.accept_button = RectButton( 550 - 75, 310, 75, 50, Color.ORANGE, 0, Text(pygame.font.SysFont('Agency FB', 25), "Accept", Color.GREEN2)) self.accept_button.change_bg_image(WOOD) self.accept_button.add_frame(FRAME) self.deny_button = RectButton( 550 + 200, 310, 75, 50, Color.ORANGE, 0, Text(pygame.font.SysFont('Agency FB', 25), "Deny", Color.GREEN2)) self.deny_button.change_bg_image(WOOD) self.deny_button.add_frame(FRAME) self.accept_button.on_click(self._accept_on_click) self.deny_button.on_click(self._deny_on_click) self.background = RectLabel( 550, 300, 200, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 25), "Dodge?", Color.GREEN2)) self.background.change_bg_image(WOOD) self.background.add_frame(FRAME) self.enabled = False self.disable()
def _init_log_box(self): box_size = (self.resolution[0] / 2, self.resolution[1] / 2) x_pos = self.resolution[0] / 2 - box_size[0] / 2 y_pos = self.resolution[1] / 2 - box_size[1] / 2 log_box = RectLabel(x_pos, y_pos, box_size[0], box_size[1], Color.GREEN) self.sprite_grp.add(log_box)
def create_label(self, x_pos: int, y_pos: int, width: int, height: int, count: int): role: PlayerRoleEnum = self.decide_enum(count) accept = True if any([player.role == role for player in self._game.players]): accept = False if not accept: label = RectLabel(x_pos - 15, y_pos - 15, width + 30, height + 30, Color.RED) label.change_bg_image(MEDIA_CONSTS.WOOD) return label else: label = RectLabel(x_pos - 15, y_pos - 15, width + 30, height + 30, Color.GREEN) label.change_bg_image(MEDIA_CONSTS.WOOD) return label
def _init_text_box(self, x_pos, y_pos, w, h, text, color, color_text): box_size = (w, h) user_box = RectLabel(x_pos, y_pos, box_size[0], box_size[1], color, 0, Text(pygame.font.SysFont('Agency FB', 25), text, color_text)) user_box.change_bg_image(WOOD) user_box.add_frame(FRAME) self.sprite_grp.add(user_box)
def init_error_message(self, msg): label_width = 400 label_left = (pygame.display.get_surface().get_size()[0] / 2) - (label_width / 2) label_top = (pygame.display.get_surface().get_size()[1] / 6) * 2 error_msg_label = RectLabel(label_left, label_top, label_width, label_width, (255, 255, 255), txt_obj=(Text(pygame.font.SysFont('Agency FB', 24), msg, Color.RED))) error_msg_label.set_transparent_background(True) self.error_msg = error_msg_label
def _init_log_box(self, clr): box_size = (self.resolution[0] / 2, self.resolution[1] / 2) x_pos = self.resolution[0] / 2 - box_size[0] / 2 y_pos = self.resolution[1] / 2 - box_size[1] / 2 log_box = RectLabel(x_pos, y_pos, box_size[0], box_size[1], clr) log_box.change_bg_image(WOOD) log_box.add_frame(FRAME) self.sprite_grp.add(log_box)
def _init_load_menu(self, x_pos: int, y_pos: int, text: str, color: color, color_text: color): user_box = RectLabel( x_pos, y_pos, 500, 500, color, 0, Text(pygame.font.SysFont('Agency FB', 25), text, color_text)) user_box.change_bg_image(WOOD) user_box.add_frame(FRAME) self.sprite_grp.add(user_box)
def __init__(self): self._source = None self._target = None self._notification = RectLabel( 500, 0, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), f"Commanding: None", Color.GREEN2)) self._notification.change_bg_image(WOOD) self._notification.add_frame(FRAME) self._wait_command = RectLabel( 500, 400, 300, 50, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), f"Commanded by: None", Color.GREEN2)) self._wait_command.change_bg_image(WOOD) self._wait_command.add_frame(FRAME) self._init_end_command_btn() self._is_source = False self._is_target = False
def player_role_changed(self, role: PlayerRoleEnum): if self._game.state == GameStateEnum.READY_TO_JOIN: logger.info(f"new role: {role}") role_path = self.get_path_from_character_enum(role) logger.info(f"Role Path is: {role_path}") self.background = (RectLabel(self.background_position[0], self.background_position[1], self.background_position[2], self.background_position[3], role_path))
def _init_chatbox(self): """ Chat box dimensions """ self.offset = 5 chat_box_x = 0 chat_box_y = int(0.6 * SCREEN_RESOLUTION[1]) chat_box_w = 250 chat_box_h = SCREEN_RESOLUTION[1] - chat_box_y """ Chat history dimensions """ chat_hist_x = chat_box_x + self.offset chat_hist_y = chat_box_y + self.offset chat_hist_w = chat_box_w - 2 * self.offset chat_hist_h = 0.85 * chat_box_h """ Chat textbox dimensions """ chat_textbox_x = chat_box_x + self.offset chat_textbox_y = chat_hist_y + chat_hist_h + self.offset chat_textbox_w = chat_hist_w chat_textbox_h = chat_box_h - chat_hist_h - 15 self.chat_box = RectLabel(chat_box_x, chat_box_y, chat_box_w, chat_box_h, background=Color.BLACK) self.chat_history_bg = RectLabel(chat_hist_x, chat_hist_y, chat_hist_w, chat_hist_h, background=Color.WHITE) self.chat_history_bg.set_transparent_background(True) self.chat_textbox = InputBox(x=chat_textbox_x, y=chat_textbox_y, w=chat_textbox_w, h=chat_textbox_h, fsize=20) self.group.add( [self.chat_box, self.chat_history_bg, self.chat_textbox])
def draw(self, screen): x_offset1 = 0 if self.orientation == "vertical" else 25 y_offset1 = 0 if self.orientation == "horizontal" else 25 x_offset2 = 0 if self.orientation == "vertical" else 50 y_offset2 = 0 if self.orientation == "horizontal" else 50 if self.damaged: marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 28, 28, "media/Threat_Markers/damageMarker.png") marker.draw(screen) elif self.destroyed: marker = RectLabel(self.button.rect.x + x_offset2, self.button.rect.y + y_offset2, 28, 28, "media/Threat_Markers/damageMarker.png") marker.draw(screen) marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 28, 28, "media/Threat_Markers/damageMarker.png") marker.draw(screen)
def _init_your_turn(self): rct = RectLabel(880, 600, 250, 50, background=Color.ORANGE, txt_obj=Text(pygame.font.SysFont('Agency FB', 30), "YOUR TURN", Color.GREEN2)) rct.change_bg_image(WOOD) rct.add_frame(FRAME) return rct
def _init_text_box(self, color: Color): box_size = (self.txt_pos[2], self.txt_pos[3]) user_box = RectLabel( self.txt_pos[0], self.txt_pos[1], box_size[0], box_size[1], color, 0, Text(pygame.font.SysFont('Agency FB', 27), self.player_username, color)) user_box.change_bg_image(MEDIA_CONSTS.WOOD) user_box.add_frame(MEDIA_CONSTS.FRAME) return user_box
def driver_menu_popup(self, tile_model: TileModel): decision: int = 0 targetTile: TileModel = self._set_target_tile() red_dice = targetTile.row black_dice = targetTile.column boardSprite: GameBoard = GameBoard.instance().top_ui self.label = RectLabel( 200, 400, 600, 200, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), f"Roll: {red_dice}, {black_dice}", Color.GREEN2)) self.label.change_bg_image(WOOD) self.label.add_frame(FRAME) self.input1 = RectButton( 200, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Accept Roll", Color.GREEN2)) self.input1.change_bg_image(WOOD) self.input1.add_frame(FRAME) self.input2 = RectButton( 350, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Re-Roll Black Dice", Color.GREEN2)) self.input2.change_bg_image(WOOD) self.input2.add_frame(FRAME) self.input3 = RectButton( 500, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Re-Roll Red Dice", Color.GREEN2)) self.input3.change_bg_image(WOOD) self.input3.add_frame(FRAME) self.input4 = RectButton( 650, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Re-Roll Both Die", Color.GREEN2)) self.input4.change_bg_image(WOOD) self.input4.add_frame(FRAME) self.input1.on_click(self.input1_process, tile_model, red_dice, black_dice) self.input2.on_click(self.input2_process, tile_model, red_dice, black_dice) self.input3.on_click(self.input3_process, tile_model, red_dice, black_dice) self.input4.on_click(self.input4_process, tile_model, red_dice, black_dice) boardSprite.add(self.label) boardSprite.add(self.input1) boardSprite.add(self.input2) boardSprite.add(self.input3) boardSprite.add(self.input4)
def __init__(self, current_player: PlayerModel): super().__init__(current_player) if ChooseStartingPositionController._instance: self._current_player = current_player # raise Exception("ChooseStartingPositionController is a singleton") self.current_player = current_player self.game_board_sprite = GameBoard.instance() self.choose_prompt = RectLabel( 500, 30, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Choose Starting Position", Color.GREEN2)) self.choose_prompt.change_bg_image(WOOD) self.choose_prompt.add_frame(FRAME) self.wait_prompt = RectLabel( 500, 400, 300, 50, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Wait for your turn!", Color.GREEN2)) self.wait_prompt.change_bg_image(WOOD) self.wait_prompt.add_frame(FRAME) self.game_board_sprite.top_ui.add(self.choose_prompt) self.game_board_sprite.top_ui.add(self.wait_prompt) ChooseStartingPositionController._instance = self
def _init_ip_addr(self): if Networking.get_instance().is_host: ip_addr = f"Your IP address: {Networking.get_instance().get_ip()}" label_width = 400 label_left = (pygame.display.get_surface().get_size()[0] / 2) - (label_width / 2) ip_addr_label = RectLabel(label_left, 20, label_width, 50, (255, 255, 255), txt_obj=(Text( pygame.font.SysFont('Agency FB', 26), ip_addr, Color.GREEN2))) ip_addr_label.change_bg_image(MEDIA_CONSTS.WOOD) ip_addr_label.add_frame(MEDIA_CONSTS.FRAME) #ip_addr_label.set_transparent_background(True) self.sprite_grp.add(ip_addr_label)
def not_enough_players_ready_prompt(self): """Prompt to the host that there are not enough players to join the game.""" label_width = 400 label_height = 30 label_left = 1050 - 100 label_top = (pygame.display.get_surface().get_size()[1] - 50) - (label_height / 2) message = f"Not all players are ready!" prompt_label = RectLabel(label_left, label_top, label_width, label_height, Color.WHITE, txt_obj=Text( pygame.font.SysFont('Agency FB', 24), message)) prompt_label.set_transparent_background(True) self.players_not_ready_prompt = prompt_label
def __init__(self, text_position, background_position, username: str, player: PlayerModel, color: Color): super().__init__() self._game: GameStateModel = GameStateModel.instance() self._assoc_player = player self._assoc_player.add_observer(self) self.player_username = username self.txt_pos = text_position self.background_position = background_position self.text_box = self._init_text_box(color) self.background = RectLabel( self.background_position[0], self.background_position[1], self.background_position[2], self.background_position[3], ) self.background.change_bg_image(MEDIA_CONSTS.WOOD) self.background.add_frame( self.get_path_from_character_enum(self._assoc_player.role)) self.background.add_frame(MEDIA_CONSTS.FRAME)
def input3_process(self, tile: TileModel, red_dice: int, black_dice: int): self.max_input += 1 board_sprite: GameBoard = GameBoard.instance().top_ui self.kill_all() new_tile: TileModel = self._set_target_tile(-1, black_dice) if self.max_input == 2: self.max_input = 0 self.send_event_and_close_menu(tile, self.input1, new_tile.row, new_tile.column) else: red_dice = new_tile.row self.label = RectLabel( 200, 400, 600, 200, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), f"Roll: {red_dice}, {black_dice}", Color.GREEN2)) self.label.change_bg_image(WOOD) self.label.add_frame(FRAME) self.input1 = RectButton( 200, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Accept Roll", Color.GREEN2)) self.input1.change_bg_image(WOOD) self.input1.add_frame(FRAME) self.input2 = RectButton( 350, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Re-Roll Black Dice", Color.GREEN2)) self.input2.change_bg_image(WOOD) self.input2.add_frame(FRAME) self.input1.on_click(self.input1_process, tile, new_tile.row, black_dice) self.input2.on_click(self.input2_process, tile, new_tile.row, black_dice) board_sprite.add(self.label) board_sprite.add(self.input1) board_sprite.add(self.input2)
def __init__(self): self.accept_button = RectButton( 500 - 75, 310, 75, 50, Color.ORANGE, 0, Text(pygame.font.SysFont('Agency FB', 20), "Accept", Color.GREEN2)) self.accept_button.change_bg_image(WOOD) self.accept_button.add_frame(FRAME) self.deny_button = RectButton( 500 + 300, 310, 75, 50, Color.ORANGE, 0, Text(pygame.font.SysFont('Agency FB', 20), "Deny", Color.GREEN2)) self.deny_button.change_bg_image(WOOD) self.deny_button.add_frame(FRAME) self.accept_button.on_click(self._accept_on_click) self.deny_button.on_click(self._deny_on_click) self._source = None self._target = None self.background = RectLabel( 500, 300, 300, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 20), "Permission?", Color.GREEN2)) self.background.change_bg_image(WOOD) self.background.add_frame(FRAME) self._enabled = False
def _init_background(self): box_size = (self.resolution[0], self.resolution[1]) background_box = RectLabel(0, 0, box_size[0], box_size[1], FLASHPOINT_BACKGROUND) self.sprite_grp.add(background_box)
def _init_text_box(self, x_pos, y_pos, text, clr, color_text): box_size = (136, 32) user_box = RectLabel(x_pos, y_pos, box_size[0], box_size[1], clr, 0, Text(pygame.font.SysFont('Agency FB', 20), text, color_text)) self.sprite_grp.add(user_box)
def _init_background(self): box_size = (self.resolution[0], self.resolution[1]) background_box = RectLabel(0, 0, box_size[0], box_size[1], LOSING_FIRE) self.sprite_grp.add(background_box)