mirror of
https://github.com/DeNNiiInc/Connect-5.git
synced 2026-04-17 22:46:00 +00:00
Add surrender and rematch UI - Part 1
- Add surrender button to game controls - Add game-over modal with stats and rematch option - Add surrender confirmation modal - Add all CSS styling for new modals and buttons - Add surrender-rematch.js with global helper functions - Update multiplayer.js constructor to track opponent for rematch
This commit is contained in:
68
surrender-rematch.js
Normal file
68
surrender-rematch.js
Normal file
@@ -0,0 +1,68 @@
|
||||
// Global helper functions for surrender and rematch features
|
||||
|
||||
// Show surrender confirmation
|
||||
function confirmSurrender() {
|
||||
if (!window.multiplayerClient || !window.multiplayerClient.isMultiplayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
const modal = document.getElementById('surrenderModal');
|
||||
if (modal) {
|
||||
modal.classList.add('active');
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel surrender
|
||||
function cancelSurrender() {
|
||||
const modal = document.getElementById('surrenderModal');
|
||||
if (modal) {
|
||||
modal.classList.remove('active');
|
||||
}
|
||||
}
|
||||
|
||||
// Execute surrender
|
||||
function executeSurrender() {
|
||||
const modal = document.getElementById('surrenderModal');
|
||||
if (modal) {
|
||||
modal.classList.remove('active');
|
||||
}
|
||||
|
||||
if (window.multiplayerClient) {
|
||||
window.multiplayerClient.socket.emit('surrender', {
|
||||
gameId: window.multiplayerClient.currentGameId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Request rematch
|
||||
function requestRematch() {
|
||||
if (!window.multiplayerClient || !window.multiplayerClient.opponent) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.multiplayerClient.socket.emit('send_rematch', {
|
||||
opponentId: window.multiplayerClient.opponentId,
|
||||
boardSize: window.multiplayerClient.selectedBoardSize || 15
|
||||
});
|
||||
|
||||
if (window.multiplayerClient.showMessage) {
|
||||
window.multiplayerClient.showMessage(`Rematch request sent to ${window.multiplayerClient.opponent}`, 'info');
|
||||
}
|
||||
|
||||
const modal = document.getElementById('gameOverModal');
|
||||
if (modal) {
|
||||
modal.classList.remove('active');
|
||||
}
|
||||
}
|
||||
|
||||
// Return to lobby from game over modal
|
||||
function returnToLobby() {
|
||||
if (window.multiplayerClient) {
|
||||
window.multiplayerClient.returnToLobby();
|
||||
}
|
||||
|
||||
const modal = document.getElementById('gameOverModal');
|
||||
if (modal) {
|
||||
modal.classList.remove('active');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user