Exemple #1
0
    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_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__(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 set_profile(self, index: int, name: str, wins: int, losses: int,
                    click_action: callable, *args, **kwargs):
        """
        Set the name for the profile slot and assign callbacks to it
        :param index: Index of the profile slot (0-2)
        :param name: Name of the profile
        :param click_action: Click callback
        :param args:
        :param kwargs:
        :return:
        """
        if 0 <= index <= self._limit:
            height = self.height - 80
            btn = self._btn_list[index]
            rect = pygame.rect.Rect(btn.x, btn.y, btn.width, height)
            btn.change_rect(rect)
            str = "Wins:" + f'{wins}' + "    Losses:" + f'{losses}'
            btn.txt_obj = Text(pygame.font.SysFont('Agency FB', 30), name,
                               color.BLACK)
            btn.on_click(click_action, *args, **kwargs)
            btn.enable()

            self._profile_list.add(self._remove_btn_list[index])
            self._stats_list[index].change_text(
                Text(pygame.font.SysFont('Agency FB', 20), str, color.BLACK))
            self._profile_list.add(self._stats_list[index])
            self._render()
        else:
            raise IndexError("Index out of range")
    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)
Exemple #6
0
 def _init_btn(self, x_pos, y_pos, text, color: Color, color_text: Color):
     box_size = (130, 48)
     self.buttonConnect = RectButton(x_pos, y_pos, box_size[0], box_size[1], color, 0,
                                     Text(pygame.font.SysFont('Agency FB', 25), text, color_text))
     self.buttonConnect.change_bg_image(WOOD)
     self.buttonConnect.add_frame(FRAME)
     self.sprite_grp.add(self.buttonConnect)
Exemple #7
0
    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
Exemple #8
0
    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_btn_heroic(self, x_pos: int, y_pos: int, text: str, color: Color, color_text: Color):
     box_size = (130, 48)
     self.buttonHeroic = RectButton(x_pos, y_pos, box_size[0], box_size[1], color, 0,
                                 Text(pygame.font.SysFont('Agency FB', 25), text, color_text))
     self.buttonHeroic.change_bg_image(WOOD)
     pygame.draw.rect(self.buttonHeroic.image, Color.RED, [0, 0, box_size[0], box_size[1]], 7)
     self.sprite_grp.add(self.buttonHeroic)
Exemple #10
0
 def _init_btn_confirm(self, x_pos: int, y_pos: int, text: str, color: Color, color_text: Color):
     box_size = (130, 48)
     self.buttonConfirm = RectButton(x_pos, y_pos, box_size[0], box_size[1], color, 0,
                                     Text(pygame.font.SysFont('Agency FB', 25), text, Color.GREEN2))
     self.buttonConfirm.change_bg_image(MEDIA_CONSTS.WOOD)
     self.buttonConfirm.add_frame(MEDIA_CONSTS.FRAME)
     self.sprite_grp.add(self.buttonConfirm)
Exemple #11
0
 def _init_title_text(self):
     box_size = (400, 50)
     self.text_title = RectButton(400, 60, box_size[0], box_size[1], Color.BLACK, 0,
                                  Text(pygame.font.SysFont('Agency FB', 35), "Character Selection", Color.GREEN2))
     self.text_title.change_bg_image(MEDIA_CONSTS.WOOD)
     self.text_title.add_frame(MEDIA_CONSTS.FRAME)
     self.sprite_grp.add(self.text_title)
Exemple #12
0
    def __init__(self, wall_model: WallModel, orientation: str,
                 tile_sprite: TileSprite, tile_model: TileModel,
                 id: Tuple[int, int, str]):
        super().__init__()
        self.orientation = orientation
        self._game: GameStateModel = GameStateModel.instance()
        self._current_player = self._game.players_turn
        self._button = None
        self.tile_model = tile_model
        self.id = id
        self.wall_model = wall_model
        self.wall_model.add_observer(self)

        self.damaged = self.wall_model.wall_status == WallStatusEnum.DAMAGED
        self.destroyed = self.wall_model.wall_status == WallStatusEnum.DESTROYED
        self.tile_sprite = tile_sprite
        self._prev_x = self.tile_sprite.rect.x
        self._prev_y = self.tile_sprite.rect.y
        self.button_input = RectButton(
            self.tile_sprite.rect.x, self.tile_sprite.rect.y, 100, 25,
            Color.WOOD, 0,
            Text(pygame.font.SysFont('Agency FB', 20), "Chop Wall",
                 Color.GREEN2))
        pygame.draw.rect(self.button_input.image, Color.YELLOW,
                         [0, 0, 100, 25], 3)
        self.button_input.disable()
        self.can_chop = False
Exemple #13
0
    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)
Exemple #14
0
    def __init__(self, door_model: DoorModel, orientation: str,
                 tile_sprite: TileSprite, tile_model: TileModel,
                 id: Tuple[int, int, str]):
        super().__init__()
        self.orientation = orientation
        self._game: GameStateModel = GameStateModel.instance()
        self._current_player = self._game.players_turn
        self._button = None
        self.tile_model = tile_model
        self.id = id
        self.door_model = door_model
        self.door_model.add_observer(self)

        self.open = self.door_model.door_status == DoorStatusEnum.OPEN
        self.closed = self.door_model.door_status == DoorStatusEnum.CLOSED
        self.destroyed = self.door_model.door_status == DoorStatusEnum.DESTROYED

        self.marker = None
        self.tile_sprite = tile_sprite
        self._prev_x = self.tile_sprite.rect.x
        self._prev_y = self.tile_sprite.rect.y
        self.button_input = RectButton(
            self.tile_sprite.rect.x + 100, self.tile_sprite.rect.y + 100, 100,
            25, Color.WOOD, 0,
            Text(pygame.font.SysFont('Agency FB', 15), "Interact",
                 Color.GREEN2))
        pygame.draw.rect(self.button_input.image, Color.YELLOW,
                         [0, 0, 100, 25], 3)
        self.button_input.disable()
        self.menu_shown = False
 def _init_duo(self, x_pos, y_pos, text,color, color_text):
     box_size = (130, 48)
     self.button_duo= RectButton(x_pos, y_pos, box_size[0], box_size[1], color, 0,
                                   Text(pygame.font.SysFont('Agency FB', 25), text, color_text))
     self.button_duo.change_bg_image(WOOD)
     self.button_duo.add_frame(FRAME)
     self.button_duo.on_click(self.set_and_continue, 2)
     self.sprite_grp.add(self.button_duo)
 def _init_button6(self, x_pos: int, y_pos: int, text: str, color: Color, color_text: Color):
     box_size = (130, 48)
     self.button_players6 = RectButton(x_pos, y_pos, box_size[0], box_size[1], color, 0,
                                  Text(pygame.font.SysFont('Agency FB', 25), text, color_text))
     self.button_players6.on_click(self.set_and_continue, 6)
     self.button_players6.change_bg_image(WOOD)
     self.button_players6.add_frame(FRAME)
     self.sprite_grp.add(self.button_players6)
Exemple #17
0
 def _init_btn_register(self, x_pos, y_pos, text, clr, color_text):
     box_size = (130, 48)
     self.buttonRegister = RectButton(x_pos, y_pos, box_size[0], box_size[1], clr, 0,
                                      Text(pygame.font.SysFont('Agency FB', 25), text, color_text))
     self.buttonRegister.change_bg_image(WOOD)
     self.buttonRegister.add_frame(FRAME)
     self.buttonRegister.on_click(self.register_profile)
     self.sprite_grp.add(self.buttonRegister)
 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_title_text(self):
        box_size = (500, 50)
        self.text_title = RectButton((int)(1280/2-250), 60, box_size[0], box_size[1], Color.BLACK, 0,
                                     Text(pygame.font.SysFont('Agency FB', 35), "Set Number of Max Players", Color.GREEN2))
        self.text_title.change_bg_image(WOOD)
        self.text_title.add_frame(FRAME)

        self.sprite_grp.add(self.text_title)
 def _init_btn_back(self, x_pos: int, y_pos: int, text: str, color: Color, color_text: Color):
     box_size = (130, 48)
     self.buttonBack = RectButton(x_pos, y_pos, box_size[0], box_size[1], color, 0,
                                  Text(pygame.font.SysFont('Agency FB', 25), text, color_text))
     self.buttonBack.on_click(EventQueue.post, CustomEvent(ChangeSceneEnum.CHOOSEBOARDSCENE))
     self.buttonBack.change_bg_image(WOOD)
     self.buttonBack.add_frame(FRAME)
     self.sprite_grp.add(self.buttonBack)
    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)
Exemple #22
0
 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
Exemple #23
0
 def _init_btn_back(self, x_pos: int, y_pos: int, text: str, bg: str,
                    color_text: Color):
     box_size = (130, 48)
     self.buttonBack = RectButton(
         x_pos, y_pos, box_size[0], box_size[1], bg, 0,
         Text(pygame.font.SysFont('Agency FB', 25), text, color_text))
     self.buttonBack.add_frame(MEDIA_CONSTS.FRAME)
     self.sprite_grp.add(self.buttonBack)
Exemple #24
0
 def _init_continue_btn(self):
     box_size = (200, 50)
     ctn_btn = RectButton(
         550, 500, box_size[0], box_size[1], WOOD, 0,
         Text(pygame.font.SysFont('Agency FB', 20), "Continue",
              Color.GREEN2))
     ctn_btn.add_frame(FRAME)
     ctn_btn.on_click(self._continue)
     self.sprite_grp.add(ctn_btn)
 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
Exemple #26
0
 def _init_selec_char(self, x_pos: int, y_pos: int, text: str, color: Color,
                      color_text: Color):
     box_size = (170, 48)
     self.buttonSelChar = RectButton(
         x_pos, y_pos, box_size[0], box_size[1], color, 0,
         Text(pygame.font.SysFont('Agency FB', 25), text, color_text))
     self.buttonSelChar.change_bg_image(MEDIA_CONSTS.WOOD)
     self.buttonSelChar.add_frame(MEDIA_CONSTS.FRAME)
     self.sprite_grp.add(self.buttonSelChar)
 def command(self, command: Tuple[PlayerModel, PlayerModel]):
     self._source = command[0]
     self._target = command[1]
     self.background.change_text(
         Text(pygame.font.SysFont('Agency FB', 20),
              f"{self._source.nickname} wants to command you",
              Color.GREEN2))
     self.background.change_bg_image(WOOD)
     self.background.add_frame(FRAME)
Exemple #28
0
 def _init_start_game_button(self):
     """Button for starting the game once all players have clicked ready."""
     box_size = (130, 48)
     self.start_button = RectButton(
         1050, 575, box_size[0], box_size[1], Color.GREY, 0,
         Text(pygame.font.SysFont('Agency FB', 25), "Start", Color.RED))
     self.start_button.change_bg_image(MEDIA_CONSTS.WOOD)
     self.start_button.add_frame(MEDIA_CONSTS.FRAME)
     self.sprite_grp.add(self.start_button)
Exemple #29
0
    def set_ready(self):
        """Set the status of the current player to ready."""
        if not self.isReady:
            if not (self._game.rules == GameKindEnum.FAMILY and self._current_player.role == PlayerRoleEnum.FAMILY) \
                    or self._game.rules == GameKindEnum.FAMILY:
                self.isReady = True
                self.sprite_grp.remove(self.buttonReady)
                box_size = (130, 48)
                self.buttonReady = RectButton(
                    1050, 575, box_size[0], box_size[1], Color.BLACK, 0,
                    Text(pygame.font.SysFont('Agency FB', 25), "Ready",
                         Color.GREEN))
                self.buttonReady.change_bg_image(MEDIA_CONSTS.WOOD)
                self.buttonReady.add_frame(MEDIA_CONSTS.FRAME)
                self.buttonReady.on_click(self.set_ready)
                self.sprite_grp.add(self.buttonReady)
                self._current_player.status = PlayerStatusEnum.READY
                event = ReadyEvent(self._current_player, True)

                if self._current_player.ip == GameStateModel.instance(
                ).host.ip:
                    event.execute()
                    Networking.get_instance().send_to_all_client(event)
                else:
                    Networking.get_instance().send_to_server(event)
        else:
            self.isReady = False
            self.sprite_grp.remove(self.buttonReady)
            box_size = (130, 48)
            self.buttonReady = RectButton(
                1050, 575, box_size[0], box_size[1], Color.BLACK, 0,
                Text(pygame.font.SysFont('Agency FB', 25), "Not Ready",
                     Color.GREY))
            self.buttonReady.change_bg_image(MEDIA_CONSTS.WOOD)
            self.buttonReady.add_frame(MEDIA_CONSTS.FRAME)
            self.buttonReady.on_click(self.set_ready)
            self.sprite_grp.add(self.buttonReady)
            self._current_player.status = PlayerStatusEnum.NOT_READY
            event = ReadyEvent(self._current_player, False)
            if self._current_player.ip == GameStateModel.instance().host.ip:
                event.execute()
                Networking.get_instance().send_to_all_client(event)
            else:
                Networking.get_instance().send_to_server(event)
    def command(self, command: Tuple[PlayerModel, PlayerModel]):
        (self._source, self._target) = command
        source_msg = "Commanding: None"
        target_msg = "Commanded by: None"
        if self._target:
            source_msg = f"Commanding: {self._target.nickname}"
        if self._source:
            target_msg = f"Commanded by: {self._source.nickname}"

        self._notification.change_text(
            Text(pygame.font.SysFont('Agency FB', 30), source_msg,
                 Color.ORANGE))
        self._notification.change_bg_image(WOOD)
        self._notification.add_frame(FRAME)
        self._wait_command.change_text(
            Text(pygame.font.SysFont('Agency FB', 30), target_msg,
                 Color.ORANGE))
        self._wait_command.change_bg_image(WOOD)
        self._wait_command.add_frame(FRAME)