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 useful checks: Click Restart repeatedly, then hold a key: movement must occur at normal speed, not multiply. Instrument update or count active frame IDs: there must be one update per animation tick. Restart during pause, game-over, and countdown: no old state or delayed callback may resume. Restart after changing level or losing a life: all bricks, score/lives rules, velocity, and timers must match a fresh game.


