Ok you see a dam uses energy of the movement from the water, right? Then the dam uses that energy to control the flow of that water but that's not it the dam can also generate amount of electricity that is being produced. Its kinda hard to put in human words but id assume looking at this picture would basically explain everything..
Explanation: