示例#1
0
    def place_hazmat(self, hazmat_to_place: int):
        while hazmat_to_place > 0:
            new_haz_row = self.game.roll_red_dice()
            new_haz_column = self.game.roll_black_dice()
            tile = self.board.get_tile_at(new_haz_row, new_haz_column)

            # Hazmat cannot be placed on tile
            # that is on fire or has a hazmat
            # on it already.
            if tile.space_status == SpaceStatusEnum.FIRE:
                continue

            should_reroll = False
            for model in tile.associated_models:
                if isinstance(model, HazmatModel):
                    should_reroll = True
                    break

            if should_reroll:
                continue

            model = HazmatModel()
            sprite = HazmatSprite(tile)
            tile.add_associated_model(model)
            GameBoard.instance().add(sprite)
            model.add_observer(sprite)
            hazmat_to_place -= 1
    def execute(self, *args, **kwargs):
        logger.info("Executing Fire Deck Gun Event")

        self.game: GameStateModel = GameStateModel.instance()

        if isinstance(self.target_tile, NullModel):
            self._set_target_tile()

        self.target_tile.space_status = SpaceStatusEnum.SAFE

        FileImporter.play_music(SPLASH_SOUND, 1)
        tile_sprite = GameBoard.instance().grid.grid[self.target_tile.column][
            self.target_tile.row]
        tile_sprite.fire_deck_gun = True

        directions = ["North", "East", "West", "South"]
        for dirn in directions:
            has_obstacle = self.target_tile.has_obstacle_in_direction(dirn)
            obstacle = self.target_tile.get_obstacle_in_direction(dirn)
            # If there is no obstacle in the given direction or there is an
            # open door, set the status of the space in that direction to Safe.
            if not has_obstacle or (isinstance(obstacle, DoorModel) and obstacle.door_status == DoorStatusEnum.OPEN)\
                    or (isinstance(obstacle, WallModel) and obstacle.wall_status == WallStatusEnum.DESTROYED):
                nb_tile: TileModel = self.target_tile.get_tile_in_direction(
                    dirn)
                nb_tile.space_status = SpaceStatusEnum.SAFE
                tile_sprite = GameBoard.instance().grid.grid[nb_tile.column][
                    nb_tile.row]
                tile_sprite.fire_deck_gun = True

        if self.player.role == PlayerRoleEnum.DRIVER:
            self.player.ap = self.player.ap - 2
        else:
            self.player.ap = self.player.ap - 4
 def execute(self):
     logger.info("Executing ChooseStartingPositionEvent")
     game: GameStateModel = GameStateModel.instance()
     player: PlayerModel = game.players_turn
     tile = game.game_board.get_tile_at(self._row, self._column)
     player_sprite = PlayerSprite(player, tile, GameBoard.instance().grid)
     GameBoard.instance().add(player_sprite)
     player.set_pos(tile.row, tile.column)
    def __init__(self, current_player: PlayerModel):
        super().__init__(current_player)
        if TileInputController._instance:
            self._current_player = current_player

        self.game_board_sprite = GameBoard.instance()

        ExtinguishController(current_player)
        MoveController(current_player)
        ChooseStartingPositionController(current_player)
        VictimController(current_player)

        if GameStateModel.instance().rules == GameKindEnum.EXPERIENCED:
            VehiclePlacementController(current_player)
            DriveVehiclesController(current_player)
            IdentifyController(current_player)
            HazmatController(current_player)
            CommandPlayerController(current_player)
            ResuscitateController(current_player)
            CrewChangeController(current_player)
            FireDeckGunController(current_player)

        GameStateModel.instance().add_observer(self)
        # Force notify observers
        GameStateModel.instance().state = GameStateModel.instance().state

        TileInputController._instance = self
示例#5
0
    def execute(self, *args, **kwargs):
        logger.info(
            f"Executing VehiclePlacedEvent: {self._vehicle_type} placed.")

        board_model: GameBoardModel = GameStateModel.instance().game_board
        board_sprite: GameBoard = GameBoard.instance()
        tile_sprite = board_sprite.grid.grid[self._column][self._row]
        if self._vehicle_type == "AMBULANCE":
            # Set ambulance position
            board_model.ambulance.drive((self._row, self._column))

            # Create AmbulanceSprite
            ambulance_sprite = AmbulanceSprite(
                board_model.ambulance.orientation, tile_sprite)
            board_model.ambulance.add_observer(ambulance_sprite)
            # Add to gameboard sprite group
            board_sprite.add(ambulance_sprite)

        else:
            # Set engine position
            board_model.engine.drive((self._row, self._column))

            # Create EngineSprite
            engine_sprite = EngineSprite(board_model.engine.orientation,
                                         tile_sprite)
            board_model.engine.add_observer(engine_sprite)
            # Add to gameboard sprite group
            board_sprite.add(engine_sprite)
    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
示例#7
0
    def explosion(self, origin_tile: TileModel):
        FileImporter.play_music(EXPLOSION_SOUND, 1)
        logger.info(f"Explosion occurred on {origin_tile}")
        game_state = GameStateModel.instance()
        tile_sprite = GameBoard.instance().grid.grid[origin_tile.column][
            origin_tile.row]
        tile_sprite.explosion = True

        for direction, obstacle in origin_tile.adjacent_edge_objects.items():
            # fire does not move to the neighbouring tile
            # damaging wall present along the tile
            if isinstance(
                    obstacle, WallModel
            ) and obstacle.wall_status != WallStatusEnum.DESTROYED:
                obstacle.inflict_damage()
                game_state.damage = game_state.damage + 1

            # fire does not move to the neighbouring tile
            # removing door that borders the tile
            elif isinstance(obstacle, DoorModel):
                obstacle.destroy_door()

            # fire can move to the neighbouring tile
            # if the neighbouring tile is on fire, a shockwave is created
            # else it is just set on fire.
            else:
                nb_tile = origin_tile.get_tile_in_direction(direction)
                if not isinstance(nb_tile, NullModel):
                    if nb_tile.space_status == SpaceStatusEnum.FIRE:
                        self.shockwave(nb_tile, direction)
                    else:
                        nb_tile.space_status = SpaceStatusEnum.FIRE
示例#8
0
    def __init__(self, row: int, column: int):
        super().__init__()
        self.image = FileImporter.import_image("media/all_markers/victim.png")

        self.rect = self.image.get_rect()
        self.row = row
        self.column = column
        self.tile_sprite = GameBoard.instance().grid.grid[column][row]
 def __init__(self, poi: POIModel):
     super().__init__()
     self.image = FileImporter.import_image(
         "media/all_markers/false_alarm.png")
     self.rect = self.image.get_rect()
     self.poi_model = poi
     self.row = poi.row
     self.column = poi.column
     self.tile_sprite = GameBoard.instance().grid.grid[poi.column][poi.row]
示例#10
0
    def execute(self, *args, **kwargs):
        while not GameBoard.instance():
            time.sleep(0.1)
        FirePlacementEvent(self.seed).execute()

        if GameStateModel.instance().rules == GameKindEnum.EXPERIENCED:
            SetInitialPOIExperiencedEvent(self.seed).execute()
            PlaceHazmatEvent(self.seed).execute()
            SetInitialHotspotEvent(self.seed).execute()
        else:
            SetInitialPOIFamilyEvent().execute()
示例#11
0
 def clear():
     # Reset everything
     if GameStateModel.instance():
         GameStateModel.destroy()
     if GameBoard.instance():
         GameBoard._instance = None
         # TileInputController.destroy()
         ChopController._instance = None
         DoorController._instance = None
         switch.ABORT = True
         VeteranController._instance = None
示例#12
0
    def notify_vehicle_pos(self, orientation: VehicleOrientationEnum, row: int, column: int):
        self.tile_sprite = GameBoard.instance().grid.grid[column][row]
        self.row = row
        self.column = column

        # Fix the orientation if needed
        if self.orientation == VehicleOrientationEnum.VERTICAL and orientation == VehicleOrientationEnum.HORIZONTAL:
            self.image = pygame.transform.rotate(self.image, -90)
        elif self.orientation == VehicleOrientationEnum.HORIZONTAL and orientation == VehicleOrientationEnum.VERTICAL:
            self.image = pygame.transform.rotate(self.image, 90)

        self.orientation = orientation
    def __init__(self, current_player: PlayerModel):
        super().__init__(current_player)

        if ExtinguishController._instance:
            self._current_player = current_player
            # raise Exception("ExtinguishController is a singleton")
        self.game_board_sprite = GameBoard.instance()
        self.current_player = current_player
        game: GameStateModel = GameStateModel.instance()
        game.game_board.reset_tiles_visit_count()

        ExtinguishController._instance = self
示例#14
0
    def __init__(self, poi: POIModel):
        super().__init__()
        self.image = FileImporter.import_image('media/all_markers/poi128.png')
        self.small_image = FileImporter.import_image(
            "media/all_markers/poi.png")
        self.rect = self.image.get_rect()
        self.poi_model = poi
        self.row = poi.row
        self.column = poi.column
        self.poi_model.add_observer(self)
        self.tile_sprite = GameBoard.instance().grid.grid[poi.column][poi.row]

        self.counter = 80
    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)
示例#16
0
    def __init__(self, current_player: PlayerModel):
        super().__init__(current_player)

        if MoveController._instance:
            self._current_player = current_player

        self.game_board_sprite = GameBoard.instance()
        self.current_player = current_player
        self._only_allow_safe_space = False
        ap = self.current_player.ap
        # Rescue specialist's special AP are used for moving
        if self.current_player.role == PlayerRoleEnum.RESCUE:
            ap = ap + self.current_player.special_ap

        self.moveable_tiles = self._determine_reachable_tiles(
            self.current_player.row, self.current_player.column, ap)
        self.current_player.add_observer(self)
        GameStateModel.instance().game_board.reset_tiles_visit_count()
        GameStateModel.instance().game_board.ambulance.add_observer(self)
        GameStateModel.instance().game_board.engine.add_observer(self)
        MoveController._instance = self
示例#17
0
    def update(self, queue: EventQueue):
        if GameStateModel.instance().state != GameStateEnum.MAIN_GAME:
            return

        doors: List[DoorSprite] = GameBoard.instance().grid.get_doors

        for door in doors:
            for event in queue:
                if event.type == pygame.MOUSEBUTTONUP:
                    if door.direction == 'West' or door.direction == 'East':
                        if door.button.rect.x <= pygame.mouse.get_pos()[
                            0] <= door.button.rect.x + 20 and door.button.rect.y + 40 <= \
                                pygame.mouse.get_pos()[1] <= door.button.rect.y + 100:
                            # means the user is pressing on the door
                            self.process_input(door)

                    if door.direction == 'North' or door.direction == 'South':
                        if door.button.rect.x + 40 <= pygame.mouse.get_pos()[
                            0] <= door.button.rect.x + 100 and door.button.rect.y <= \
                                pygame.mouse.get_pos()[1] <= door.button.rect.y + 20:
                            # means the user is pressing on the door
                            self.process_input(door)
示例#18
0
    def update(self, event_queue: EventQueue):
        if GameStateModel.instance().state != GameStateEnum.MAIN_GAME:
            return

        walls = GameBoard.instance().grid.get_walls

        for wall in walls:
            for event in event_queue:
                if event.type == pygame.MOUSEBUTTONUP:
                    if wall.direction == 'North' or wall.direction == 'South':  # means the wall is horizontal
                        if wall.button.rect.x <= pygame.mouse.get_pos()[
                            0] <= wall.button.rect.x + 100 and wall.button.rect.y <= \
                                pygame.mouse.get_pos()[1] <= wall.button.rect.y + 25:
                            # means the user is pressing on the wall
                            self.process_input(wall)

                    else:  # means the wall is vertical
                        if wall.button.rect.x <= pygame.mouse.get_pos()[
                            0] <= wall.button.rect.x + 25 and wall.button.rect.y <= \
                                pygame.mouse.get_pos()[1] <= wall.button.rect.y + 100:
                            # means the user is pressing on the wall
                            self.process_input(wall)
    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)
示例#20
0
    def __init__(self, current_player: PlayerModel):
        super().__init__(current_player)
        if VeteranController._instance:
            raise Exception("VeteranController is a singleton")

        self.game_board_sprite = GameBoard.instance()
        self.game: GameStateModel = GameStateModel.instance()
        self.board = self.game.game_board
        self.move_cont = MoveController.instance()
        self.player_booleans = {}
        self.c_player = current_player

        for player in GameStateModel.instance().players:
            player.add_observer(self)

        self.move_cont = MoveController.instance()
        self.game: GameStateModel = GameStateModel.instance()
        self.board = self.game.game_board
        # self.game.add_observer(self)
        # # Force notify observers
        # self.game.state = self.game.state
        VeteranController._instance = self
    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
示例#22
0
 def __init__(self, tile_model: TileModel):
     super().__init__()
     self.grid: GridSprite = GameBoard.instance().grid
     self.tile_sprite = self.grid.grid[tile_model.column][tile_model.row]
     self.rect = self.tile_sprite.rect
     self.image = FileImporter.import_image("media/all_markers/hazmat.png")
示例#23
0
    def hazmat_position_changed(self, row: int, col: int):
        self.tile_sprite = GameBoard.instance().grid.grid[col][row]
        self.rect = self.tile_sprite.rect

        if row < 0 or col < 0:
            self.kill()
示例#24
0
 def poi_position_changed(self, row: int, column: int):
     self.tile_sprite = GameBoard.instance().grid.grid[column][row]
     self.row = row
     self.column = column