// 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 = `
Rematch Request!
${data.from} wants a rematch
Board size: ${data.boardSize}×${data.boardSize}
`;
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());
}