This sounds very much like Galaxy of Terror, released in 1981. In the film, the crew of a military vessel find themselves stranded on an alien planet and begin exploring the nearby pyramid-like structure. Throughout the course of the film, each crew member is confronted by a physical manifestation of their worst fear. In fact, the movie has become somewhat infamous due to a lengthy scene which depicts one crewmember
being raped by a giant maggot (her fear is worms).
At the end of the film, the lone survivor finally makes it to the center of the structure only to find someone he did not expect.
The Master explains that the pyramid is actually an ancient toy for the children of a long-extinct race, built in order to test their ability to control fear. Cabren kills the Master for allowing his crew to die, but becomes the new Master in his place.