mirror of
https://github.com/DeNNiiInc/Connect-5.git
synced 2026-04-18 00:56:00 +00:00
Fix variable scope: Ensure global access to game and multiplayer client
This commit is contained in:
5
game.js
5
game.js
@@ -248,7 +248,8 @@ class Connect5Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize game when DOM is loaded
|
// Initialize game when DOM is loaded
|
||||||
let game;
|
// Initialize game when DOM is loaded
|
||||||
|
window.game = null;
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
game = new Connect5Game();
|
window.game = new Connect5Game();
|
||||||
});
|
});
|
||||||
|
|||||||
23
index.html
23
index.html
@@ -203,8 +203,8 @@
|
|||||||
statusMessage.style.display = 'block';
|
statusMessage.style.display = 'block';
|
||||||
|
|
||||||
// Reset to local mode
|
// Reset to local mode
|
||||||
if (multiplayerClient) {
|
if (window.multiplayerClient) {
|
||||||
multiplayerClient.isMultiplayer = false;
|
window.multiplayerClient.isMultiplayer = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localBtn.classList.remove('active');
|
localBtn.classList.remove('active');
|
||||||
@@ -215,9 +215,13 @@
|
|||||||
statusMessage.style.display = 'none';
|
statusMessage.style.display = 'none';
|
||||||
|
|
||||||
// Initialize multiplayer if not already
|
// Initialize multiplayer if not already
|
||||||
if (!multiplayerClient) {
|
if (!window.multiplayerClient) {
|
||||||
multiplayerClient = new MultiplayerClient(game);
|
if (!window.game) {
|
||||||
multiplayerClient.connect();
|
console.error("Game instance not found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.multiplayerClient = new MultiplayerClient(window.game);
|
||||||
|
window.multiplayerClient.connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -247,7 +251,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
error.style.display = 'none';
|
error.style.display = 'none';
|
||||||
multiplayerClient.registerPlayer(username);
|
|
||||||
|
if (window.multiplayerClient) {
|
||||||
|
window.multiplayerClient.registerPlayer(username);
|
||||||
|
} else {
|
||||||
|
console.error("Multiplayer client not initialized");
|
||||||
|
error.textContent = "Error: Multiplayer not initialized. Refresh page.";
|
||||||
|
error.style.display = 'block';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change username
|
// Change username
|
||||||
|
|||||||
@@ -507,4 +507,5 @@ class MultiplayerClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize multiplayer client (will be used by game.js)
|
// Initialize multiplayer client (will be used by game.js)
|
||||||
let multiplayerClient = null;
|
// Initialize multiplayer client (will be used by game.js)
|
||||||
|
window.multiplayerClient = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user