A dynamical model of electoral competition