How does the moon affect the tides?

It's not the moon's gravity alone, but the interaction of the earth and moon. One influence is the fact that the earth-moon system orbits around the common center of gravity of earth-moon. This point is called the barycenter, and it is within the body of the earth since earth's mass is considerably larger than the moon's mass. As the earth wobbles around the barycenter, it tends to push the water out from behind the barycenter. At the same time, the gravitational attraction of the moon is stronger on the water that is moon-side than it is on the water on the opposite side of earth. So there is a high tide bulge on two opposite sides of the earth at once, and of course then there are two low tide areas at roughly 90 degree angles to the high tides.