main logic of the game