mirror of
https://github.com/DeNNiiInc/Connect-5.git
synced 2026-04-17 20:36:00 +00:00
- 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
72 lines
2.5 KiB
Plaintext
72 lines
2.5 KiB
Plaintext
|
||
// Surrender game
|
||
surrenderGame() {
|
||
if (!this.isMultiplayer || !this.currentGameId) {
|
||
this.showMessage('No active game to surrender', 'error');
|
||
return;
|
||
}
|
||
|
||
this.socket.emit('surrender', { gameId: this.currentGameId });
|
||
}
|
||
|
||
// Handle rematch request from opponent
|
||
handleRematchRequest(data) {
|
||
const notification = document.createElement('div');
|
||
notification.className = 'challenge-notification';
|
||
notification.innerHTML = `
|
||
<div class="challenge-content">
|
||
<h3>Rematch Request!</h3>
|
||
<p><strong>${data.from}</strong> wants a rematch</p>
|
||
<p>Board size: ${data.boardSize}×${data.boardSize}</p>
|
||
<div class="challenge-actions">
|
||
<button class="accept-btn" onclick="multiplayerClient.acceptRematch('${data.rematchId}')">
|
||
Accept
|
||
</button>
|
||
<button class="decline-btn" onclick="multiplayerClient.declineRematch('${data.rematchId}')">
|
||
Decline
|
||
</button>
|
||
</div>
|
||
</div>
|
||
`;
|
||
|
||
document.body.appendChild(notification);
|
||
setTimeout(() => notification.classList.add('active'), 10);
|
||
}
|
||
|
||
// Send rematch request
|
||
sendRematchRequest() {
|
||
if (!this.opponentId) {
|
||
this.showMessage('No opponent to challenge', 'error');
|
||
return;
|
||
}
|
||
|
||
this.socket.emit('send_rematch', {
|
||
opponentId: this.opponentId,
|
||
boardSize: this.selectedBoardSize
|
||
});
|
||
|
||
this.showMessage(`Rematch request sent to ${this.opponent}`, 'info');
|
||
document.getElementById('gameOverModal').classList.remove('active');
|
||
}
|
||
|
||
// Accept rematch
|
||
acceptRematch(rematchId) {
|
||
this.socket.emit('accept_rematch', { rematchId });
|
||
|
||
// Hide game over modal
|
||
document.getElementById('gameOverModal').classList.remove('active');
|
||
|
||
// Remove notification
|
||
const notifications = document.querySelectorAll('.challenge-notification');
|
||
notifications.forEach(n => n.remove());
|
||
}
|
||
|
||
// Decline rematch
|
||
declineRematch(rematchId) {
|
||
this.socket.emit('decline_rematch', { rematchId });
|
||
|
||
// Remove notification
|
||
const notifications = document.querySelectorAll('.challenge-notification');
|
||
notifications.forEach(n => n.remove());
|
||
}
|