Multiplayer / templates /index.html
ILLERRAPS's picture
Upload folder using huggingface_hub
2cdc05c verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multiplayer Text-Based RPG Game</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<style>
body { font-family: Arial, sans-serif; }
.game-window { width: 600px; height: 400px; border: 1px solid #ccc; margin: auto; display: flex; flex-direction: column; }
.game-header, .game-footer { padding: 10px; background-color: #f1f1f1; display: flex; justify-content: space-between; align-items: center; }
.game-body { flex-grow: 1; padding: 10px; overflow-y: auto; }
.game-input { width: 100%; }
.game-action { cursor: pointer; padding: 3px 8px; border-radius: 5px; font-size: 12px; margin: 2px; background-color: #007bff; color: white; }
.player-action { background-color: #dcf8c6; }
.game-response { background-color: #e5f5ff; color: blue; }
.notification-btn, .mute-btn { margin-top: 10px; padding: 5px; border-radius: 5px; background-color: #ffeb3b; cursor: pointer; }
.command-menu { margin: 10px 0; }
.command-btn { margin: 2px; padding: 5px 10px; border-radius: 5px; background-color: #28a745; color: white; cursor: pointer; }
.mute-btn { background-color: #f44336; color: white; }
.notifications { max-height: 150px; overflow-y: auto; margin-top: 10px; border: 1px solid #ccc; padding: 5px; display: none; }
</style>
</head>
<body>
<div class="game-window" id="game-window">
<div class="game-header">
Multiplayer Text-Based RPG Game
<div>
<button class="notification-btn" onclick="showNotifications()">Notifications</button>
<button class="mute-btn" id="mute-btn" onclick="toggleMute()">Mute</button>
</div>
</div>
<div class="command-menu">
<button class="command-btn" onclick="executeCommand('/create_character Warrior Fighter')">Create Character</button>
<button class="command-btn" onclick="executeCommand('/get_character_info')">Get Character Info</button>
<button class="command-btn" onclick="executeCommand('/attack')">Attack</button>
<!-- Add more command buttons as needed -->
</div>
<div class="game-body" id="game-body"></div>
<div class="notifications" id="notifications"></div>
<div class="game-footer">
<input type="text" class="game-input" id="game-input" placeholder="Type an action..." onkeydown="if(event.key === 'Enter') { sendAction(); }">
<button id="send-action-button" onclick="sendAction()">Send</button>
</div>
</div>
<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
<script>
const socket = io();
let isMuted = false;
let currentAudio = null;
function sendAction() {
const input = document.getElementById('game-input');
const action = input.value;
socket.emit('action', { action: action, user_id: 1, character_id: 1 }); // Adjust user_id and character_id as needed
input.value = '';
}
function executeCommand(command) {
document.getElementById('game-input').value = command;
}
socket.on('response', function(response) {
const gameBody = document.getElementById('game-body');
const responseElement = document.createElement('div');
responseElement.className = 'game-response';
responseElement.innerHTML = response;
gameBody.appendChild(responseElement);
gameBody.scrollTop = gameBody.scrollHeight;
if (!isMuted) {
fetch('/tts', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ text: response })
})
.then(response => response.blob())
.then(blob => {
if (currentAudio) {
currentAudio.pause();
currentAudio = null;
}
const url = URL.createObjectURL(blob);
currentAudio = new Audio(url);
currentAudio.play();
})
.catch(error => console.error('Error with TTS:', error));
}
});
function toggleMute() {
isMuted = !isMuted;
const muteBtn = document.getElementById('mute-btn');
muteBtn.textContent = isMuted ? 'Unmute' : 'Mute';
if (currentAudio) {
currentAudio.pause();
currentAudio = null;
}
}
socket.on('notification', function(notification) {
const notifications = document.getElementById('notifications');
const notificationElement = document.createElement('div');
notificationElement.className = 'notification';
notificationElement.innerHTML = notification;
notifications.appendChild(notificationElement);
notifications.scrollTop = notifications.scrollHeight;
});
function showNotifications() {
const notifications = document.getElementById('notifications');
notifications.style.display = notifications.style.display === 'none' ? 'block' : 'none';
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('notifications').style.display = 'none';
});
</script>
</body>
</html>