How should I prevent duplicate animation loops and input listeners when restarting a small HTML canvas brick-breaker game? Give a minimal lifecycle pattern, list the game state that must reset, and provide four checks that expose restart bugs. Do not produce a complete game or claim the pattern has been run.
Four checks: Restart 10 times quickly, then log one counter per frame. It should rise by one per frame, not by ten. Press the paddle key once after several restarts. The paddle should move one step. Move speed multiplying means listeners are duplicated. Hold a key, restart, and release. The paddle must not stay stuck or drift. Restart from game-over and from mid-play. Compare the full state to a fresh page load. Check for stale bricks, speed, lives, or a huge first-frame jump.


