FIX: Prevent multiplayer initialization before game is ready

- Add polling mechanism to wait for window.game initialization
- Disable multiplayer button until game is fully initialized
- Enable button in DOMContentLoaded after game creation
- Prevents 'Game instance not found' error on production

This fixes the critical issue where clicking Multiplayer too quickly
would fail because window.game wasn't ready yet.
This commit is contained in:
2025-12-14 12:07:13 +11:00
parent 8b275de519
commit bc76e7aab1
2 changed files with 18 additions and 3 deletions

View File

@@ -247,9 +247,15 @@ class Connect5Game {
}
}
// Initialize game when DOM is loaded
// Initialize game when DOM is loaded
window.game = null;
document.addEventListener("DOMContentLoaded", () => {
window.game = new Connect5Game();
// Enable multiplayer button now that game is ready
const multiplayerBtn = document.getElementById('multiplayerModeBtn');
if (multiplayerBtn) {
multiplayerBtn.disabled = false;
console.log('✅ Game initialized, multiplayer button enabled');
}
});