The hammer switches between the teams based on which teams scores in each end. Whichever team does not score will have the hammer in the next end. Another way to put it is: the team that scores goes first the next end (it then works out that the other team has the last shot). If no one scores (a "blank end"), whichever team has the hammer keeps it. For the first end of the game, the hammer is either decided by a coin flip, or a closest draw to the button competition between the teams' skips before the game (this is how it's done in the Olympics).