Game logic in JavaScript.