How does energy affect the phases of matter?
Typically for most forms of matter the phase is determined by the amount of energy possessed by the molecules of matter. The best material to use to explain this is water, because water can be found in all three phases in means that are readily understandable and able to be visualized.
If we begin with a cube of ice composed water molecules in a crystalized form we are dealing with water molecules with their lowest amount of energy. These molecules have such low amounts of energy that their movement is almost imperceptible. This form of matter for water is at and below 0 C.
If we add heat to the ice thereby increasing the energy in the molecules of water these molecules begin to vibrate at much higher velocities. These vibrations allow for the molecules of water to escape their positions in the crystal and begin to flow into a liquid. This range of temperature is from 0 C to 100 C.
If we continue to add energy and drive the temperature up to 100 C the molecules of water will vibrate so rapidly that they will break away from the liquid form and move into a gaseous state as steam escaping into the the air. This vaporization actually takes place constantly at the surface of the water creating a thin vapor layer at the surface of any body of water.
This process can be reversed by cooling down the molecules and reducing the energy of the molecules. The gas condenses back into a liquid, like the steam from your shower as it stokes the coolness of the mirror. Further reduction of the energy in the liquid form of water will create ice in the freezing state.
This is a simplification of the chemical process but basically the amount of energy in the molecules will determine the phase of matter.