modified: templates/quiz_buzzer_multiplayer.html
This commit is contained in:
@@ -233,6 +233,32 @@
|
|||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
.answer-timer-container {
|
||||||
|
margin: 15px auto 5px auto;
|
||||||
|
max-width: 400px;
|
||||||
|
text-align: center;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.answer-timer-label {
|
||||||
|
font-size: 1.3em;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #e0e0e0;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
.answer-timer-bar-bg {
|
||||||
|
width: 100%;
|
||||||
|
height: 12px;
|
||||||
|
background: rgba(255,255,255,0.1);
|
||||||
|
border-radius: 6px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.answer-timer-bar {
|
||||||
|
height: 100%;
|
||||||
|
width: 0%;
|
||||||
|
background: linear-gradient(90deg, #1DB954, #FFA500, #f44336);
|
||||||
|
border-radius: 6px;
|
||||||
|
transition: background 0.5s;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
let allTracks = {{ all_tracks|tojson }};
|
let allTracks = {{ all_tracks|tojson }};
|
||||||
@@ -248,9 +274,43 @@
|
|||||||
let decayRate = parseInt(localStorage.getItem('buzzer_decay_rate')) || 50;
|
let decayRate = parseInt(localStorage.getItem('buzzer_decay_rate')) || 50;
|
||||||
let gameStarted = false;
|
let gameStarted = false;
|
||||||
let currentBuzzer = null;
|
let currentBuzzer = null;
|
||||||
let buzzedPlayers = []; // Liste der Spieler die schon gebuzzert haben
|
let buzzedPlayers = [];
|
||||||
let canBuzz = false; // Kann man buzzern?
|
let canBuzz = false;
|
||||||
let pendingPoints = 0; // Punkte die noch nicht gezählt wurden
|
let pendingPoints = 0;
|
||||||
|
|
||||||
|
// Antwort-Timer
|
||||||
|
let answerTimerRAF = null;
|
||||||
|
let answerTimerStart = null;
|
||||||
|
const ANSWER_TIME_LIMIT = 30; // Sekunden bis Balken voll ist
|
||||||
|
|
||||||
|
function startAnswerTimer() {
|
||||||
|
answerTimerStart = Date.now();
|
||||||
|
const container = document.getElementById('answerTimerContainer');
|
||||||
|
const display = document.getElementById('answerTimerDisplay');
|
||||||
|
const bar = document.getElementById('answerTimerBar');
|
||||||
|
container.style.display = 'block';
|
||||||
|
display.textContent = '0.0s';
|
||||||
|
bar.style.width = '0%';
|
||||||
|
|
||||||
|
function tick() {
|
||||||
|
const elapsed = (Date.now() - answerTimerStart) / 1000;
|
||||||
|
display.textContent = elapsed.toFixed(1) + 's';
|
||||||
|
const pct = Math.min(100, (elapsed / ANSWER_TIME_LIMIT) * 100);
|
||||||
|
bar.style.width = pct + '%';
|
||||||
|
answerTimerRAF = requestAnimationFrame(tick);
|
||||||
|
}
|
||||||
|
answerTimerRAF = requestAnimationFrame(tick);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopAnswerTimer() {
|
||||||
|
if (answerTimerRAF) {
|
||||||
|
cancelAnimationFrame(answerTimerRAF);
|
||||||
|
answerTimerRAF = null;
|
||||||
|
}
|
||||||
|
document.getElementById('answerTimerContainer').style.display = 'none';
|
||||||
|
document.getElementById('answerTimerDisplay').textContent = '0.0s';
|
||||||
|
document.getElementById('answerTimerBar').style.width = '0%';
|
||||||
|
}
|
||||||
|
|
||||||
// Lade Team-Namen und Anzahl
|
// Lade Team-Namen und Anzahl
|
||||||
const teamCount = parseInt(localStorage.getItem('team_count')) || 4;
|
const teamCount = parseInt(localStorage.getItem('team_count')) || 4;
|
||||||
@@ -530,6 +590,7 @@
|
|||||||
// Zeige Antwortfeld direkt (keine Spielerauswahl)
|
// Zeige Antwortfeld direkt (keine Spielerauswahl)
|
||||||
document.getElementById('answerSection').classList.add('active');
|
document.getElementById('answerSection').classList.add('active');
|
||||||
window.earnedPoints = pendingPoints;
|
window.earnedPoints = pendingPoints;
|
||||||
|
startAnswerTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectPlayer(playerId) {
|
function selectPlayer(playerId) {
|
||||||
@@ -549,10 +610,7 @@
|
|||||||
document.getElementById('playerSelection').style.display = 'none';
|
document.getElementById('playerSelection').style.display = 'none';
|
||||||
document.getElementById('answerSection').classList.add('active');
|
document.getElementById('answerSection').classList.add('active');
|
||||||
window.earnedPoints = pendingPoints;
|
window.earnedPoints = pendingPoints;
|
||||||
}
|
startAnswerTimer();
|
||||||
|
|
||||||
function buzz(playerId) {
|
|
||||||
selectPlayer(playerId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCorrectAnswer() {
|
function setCorrectAnswer() {
|
||||||
@@ -623,6 +681,7 @@
|
|||||||
// Disable input während Prüfung
|
// Disable input während Prüfung
|
||||||
document.getElementById('answerInput').disabled = true;
|
document.getElementById('answerInput').disabled = true;
|
||||||
document.querySelector('button[onclick="checkAnswer()"]').disabled = true;
|
document.querySelector('button[onclick="checkAnswer()"]').disabled = true;
|
||||||
|
stopAnswerTimer();
|
||||||
|
|
||||||
fetch('/check_answer_buzzer', {
|
fetch('/check_answer_buzzer', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -712,6 +771,7 @@
|
|||||||
|
|
||||||
currentBuzzer = null;
|
currentBuzzer = null;
|
||||||
canBuzz = true;
|
canBuzz = true;
|
||||||
|
stopAnswerTimer();
|
||||||
|
|
||||||
// Berechne Pausenzeit und passe startTime an
|
// Berechne Pausenzeit und passe startTime an
|
||||||
const pauseDuration = Date.now() - window.pausedAt;
|
const pauseDuration = Date.now() - window.pausedAt;
|
||||||
@@ -731,6 +791,7 @@
|
|||||||
players[currentBuzzer - 1].score += pendingPoints;
|
players[currentBuzzer - 1].score += pendingPoints;
|
||||||
updateScoreboard();
|
updateScoreboard();
|
||||||
applyScoreToServer(currentBuzzer, pendingPoints);
|
applyScoreToServer(currentBuzzer, pendingPoints);
|
||||||
|
stopAnswerTimer();
|
||||||
|
|
||||||
const resultContainer = document.getElementById('resultContainer');
|
const resultContainer = document.getElementById('resultContainer');
|
||||||
resultContainer.innerHTML = `
|
resultContainer.innerHTML = `
|
||||||
@@ -832,6 +893,14 @@
|
|||||||
<input type="text" id="answerInput" placeholder="{{ translations['input_title'] }}" oninput="searchTracks()">
|
<input type="text" id="answerInput" placeholder="{{ translations['input_title'] }}" oninput="searchTracks()">
|
||||||
<button class="btn" onclick="checkAnswer()">{{ translations['answer_button'] if translations.get('answer_button') else 'Submit' }}</button>
|
<button class="btn" onclick="checkAnswer()">{{ translations['answer_button'] if translations.get('answer_button') else 'Submit' }}</button>
|
||||||
|
|
||||||
|
<!-- Antwort-Timer -->
|
||||||
|
<div class="answer-timer-container" id="answerTimerContainer">
|
||||||
|
<div class="answer-timer-label">⏱️ <span id="answerTimerDisplay">0.0s</span></div>
|
||||||
|
<div class="answer-timer-bar-bg">
|
||||||
|
<div class="answer-timer-bar" id="answerTimerBar"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="searchResults" class="search-results"></div>
|
<div id="searchResults" class="search-results"></div>
|
||||||
<div id="resultContainer" class="result-container"></div>
|
<div id="resultContainer" class="result-container"></div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user