The ending of The Man with the Golden Gun resolves two problems at once: Bond kills Scaramanga in the funhouse, and he gets the Solex Agitator out before the solar plant is destroyed.
How does the duel work? Bond wins the duel by posing as a mannequin in Scaramanga's funhouse and shooting him dead. Scaramanga vanishes among the trick rooms after the two agree to the duel, so Bond has to flush him out rather than outshoot him. That matches the film's opening, where Scaramanga kills Rodney in a private funhouse: the first scene and the last scene take place in the same kind of room, and the assassin dies in the setting where he was introduced.
Analysis (opinion): the funhouse is the one setting where the assassin's own trick rooms work against him, which makes the mannequin ruse a fitting way to end a killer who treats his island as a stage. It also shows how this film differs from Live and Let Die, which comes before it in the series: here the climax is a one-on-one duel with a villain who charges a million dollars a job, not a raid on a large organization. The Spy Who Loved Me, which follows, is the better point of comparison for the other half of this finale, the destruction of the villain's base.
The second half of the finale is more mechanical. Goodnight helps deal with the henchman Kra, which sends the solar plant out of control. Bond recovers the Solex just before the plant is destroyed, and he and Goodnight escape on Scaramanga's junk while Nick Nack's last attack is stopped. Bond and Goodnight then become romantically involved, which closes the film on the boat rather than back at MI6. Goodnight is the character who put the tracker on Scaramanga's car earlier, so her role in the finale pays off the middle of the story.