Esempio n. 1
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
Esempio n. 2
0
    def shockwave(self, tile: TileModel, direction: str):
        """
        Send shockwave along a direction.

        :param tile: the tile where the shockwave starts
        :param direction: direction in which shockwave continues
        :return:
        """
        game_state = GameStateModel.instance()
        should_stop = False
        while not should_stop:
            # if there is no obstacle in the given direction -
            #   1. if neighbouring tile is not on fire, set it to fire
            #       and stop the shockwave.
            #   2. else set the current tile to the neighbouring tile
            #       and continue the shockwave.
            if not tile.has_obstacle_in_direction(direction):
                nb_tile: TileModel = tile.get_tile_in_direction(direction)
                if nb_tile.space_status != SpaceStatusEnum.FIRE:
                    nb_tile.space_status = SpaceStatusEnum.FIRE
                    should_stop = True

                else:
                    tile = nb_tile

            # if there is an obstacle in the given direction
            else:
                # 1. if obstacle is a wall, inflict damage on it, increment
                #   game state damage and stop the shockwave.
                # 2. if obstacle is an open door, continue the shockwave
                #   and destroy the door.
                # 3. if obstacle is a closed door, stop the shockwave
                #   and destroy the door.
                obstacle = tile.get_obstacle_in_direction(direction)
                if isinstance(obstacle, WallModel):
                    obstacle.inflict_damage()
                    game_state.damage = game_state.damage + 1
                    should_stop = True

                elif isinstance(obstacle, DoorModel):
                    if obstacle.door_status == DoorStatusEnum.CLOSED:
                        should_stop = True
                    obstacle.destroy_door()

                else:
                    pass
Esempio n. 3
0
    def _determine_movement_direction(self, src_tile: TileModel, dest_tile: TileModel) -> str:
        """
        Determine the direction from the
        source tile to the destination tile

        :param src_tile:
        :param dest_tile:
        :return: string representation of movement direction
        """
        directions = ["North", "East", "West", "South"]
        for dirn in directions:
            nb_src_tile: TileModel = src_tile.get_tile_in_direction(dirn)
            if isinstance(nb_src_tile, NullModel):
                continue

            if nb_src_tile.row == dest_tile.row and nb_src_tile.column == dest_tile.column:
                return dirn