modified: app.py
new file: templates/buzzer_settings.html modified: templates/playerselect.html modified: templates/quiz_buzzer.html new file: templates/quiz_buzzer_multiplayer.html
This commit is contained in:
44
app.py
44
app.py
@@ -194,12 +194,19 @@ def quiz(playlist_id):
|
||||
all_tracks.append(track_info)
|
||||
|
||||
# Wähle das passende Template
|
||||
if buzzer_mode == '1':
|
||||
if buzzer_mode == '1' and local_multiplayer == '1':
|
||||
template_name = "quiz_buzzer_multiplayer.html"
|
||||
# Lade Spieler-Scores
|
||||
player_scores = session.get(f'player_scores_{playlist_id}', [0, 0, 0, 0])
|
||||
elif buzzer_mode == '1':
|
||||
template_name = "quiz_buzzer.html"
|
||||
player_scores = None
|
||||
elif local_multiplayer == '1':
|
||||
template_name = "quiz_multiplayer.html"
|
||||
player_scores = None
|
||||
else:
|
||||
template_name = "quiz.html"
|
||||
player_scores = None
|
||||
|
||||
return render_template(
|
||||
template_name,
|
||||
@@ -215,7 +222,8 @@ def quiz(playlist_id):
|
||||
translations=get_translations(),
|
||||
max_points=1000,
|
||||
grace_period=5,
|
||||
decay_rate=50
|
||||
decay_rate=50,
|
||||
player_scores=player_scores
|
||||
)
|
||||
|
||||
@app.route('/gamemodes/<playlist_id>')
|
||||
@@ -228,9 +236,28 @@ def gamemodes(playlist_id):
|
||||
def playerselect(playlist_id):
|
||||
"""Choose singleplayer or local multiplayer before starting the quiz."""
|
||||
game_mode = request.args.get('mode', 'artist')
|
||||
buzzer = request.args.get('buzzer', '0')
|
||||
user = session.get('user')
|
||||
|
||||
# Wenn Buzzer-Modus, redirect zu Einstellungen
|
||||
if buzzer == '1':
|
||||
return redirect(url_for('buzzer_settings', playlist_id=playlist_id, mode=game_mode))
|
||||
|
||||
return render_template('playerselect.html', playlist_id=playlist_id, game_mode=game_mode, translations=get_translations(), user=user)
|
||||
|
||||
@app.route('/buzzer_settings/<playlist_id>')
|
||||
def buzzer_settings(playlist_id):
|
||||
"""Configure buzzer mode settings before starting."""
|
||||
game_mode = request.args.get('mode', 'title')
|
||||
local_multiplayer = request.args.get('local_multiplayer', '0')
|
||||
user = session.get('user')
|
||||
return render_template('buzzer_settings.html',
|
||||
playlist_id=playlist_id,
|
||||
game_mode=game_mode,
|
||||
local_multiplayer=local_multiplayer == '1',
|
||||
translations=get_translations(),
|
||||
user=user)
|
||||
|
||||
@app.route("/search_track", methods=["POST"])
|
||||
def search_track():
|
||||
data = request.json
|
||||
@@ -324,6 +351,7 @@ def check_answer_buzzer():
|
||||
playlist_id = data.get('playlist_id')
|
||||
earned_points = data.get('earned_points', 0)
|
||||
all_tracks = data.get('all_tracks', [])
|
||||
player_id = data.get('player_id') # Für Multiplayer
|
||||
|
||||
# Originalwert für Vergleich speichern
|
||||
original_guess = guess
|
||||
@@ -340,8 +368,16 @@ def check_answer_buzzer():
|
||||
|
||||
# Score erhöhen mit Buzzer-Punkten, wenn richtig
|
||||
if is_correct and playlist_id:
|
||||
key = f'score_{playlist_id}'
|
||||
session[key] = session.get(key, 0) + earned_points
|
||||
if player_id:
|
||||
# Multiplayer: Update Spieler-Score
|
||||
key = f'player_scores_{playlist_id}'
|
||||
player_scores = session.get(key, [0, 0, 0, 0])
|
||||
player_scores[player_id - 1] += earned_points
|
||||
session[key] = player_scores
|
||||
else:
|
||||
# Singleplayer: Update Gesamt-Score
|
||||
key = f'score_{playlist_id}'
|
||||
session[key] = session.get(key, 0) + earned_points
|
||||
|
||||
# Bei falscher Antwort: Finde das eingegebene Lied in all_tracks
|
||||
guessed_track = None
|
||||
|
||||
223
templates/buzzer_settings.html
Normal file
223
templates/buzzer_settings.html
Normal file
@@ -0,0 +1,223 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{{ translations['quiz_title'] }} – Buzzer Einstellungen</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 50%, #0f1419 100%);
|
||||
color: #e0e0e0;
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.settings-container {
|
||||
max-width: 600px;
|
||||
width: 100%;
|
||||
background: rgba(25, 30, 45, 0.95);
|
||||
border-radius: 20px;
|
||||
padding: 40px;
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
h2 {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
color: #1DB954;
|
||||
font-size: 2em;
|
||||
}
|
||||
.setting-group {
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-size: 1.1em;
|
||||
margin-bottom: 8px;
|
||||
color: #e0e0e0;
|
||||
font-weight: 600;
|
||||
}
|
||||
.setting-description {
|
||||
font-size: 0.9em;
|
||||
color: #999;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.setting-input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
border: 2px solid rgba(29, 185, 84, 0.3);
|
||||
background: rgba(15, 20, 25, 0.8);
|
||||
color: #e0e0e0;
|
||||
font-size: 1.1em;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
.setting-input:focus {
|
||||
outline: none;
|
||||
border-color: #1DB954;
|
||||
box-shadow: 0 0 10px rgba(29, 185, 84, 0.3);
|
||||
}
|
||||
.value-display {
|
||||
display: inline-block;
|
||||
margin-left: 10px;
|
||||
font-weight: bold;
|
||||
color: #1DB954;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 15px 30px;
|
||||
margin: 10px 5px;
|
||||
border-radius: 25px;
|
||||
border: none;
|
||||
font-size: 1.1em;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
}
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #1DB954 0%, #1ed760 100%);
|
||||
box-shadow: 0 4px 15px rgba(29, 185, 84, 0.3);
|
||||
}
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(29, 185, 84, 0.5);
|
||||
}
|
||||
.btn-secondary {
|
||||
background: linear-gradient(135deg, #535353 0%, #666 100%);
|
||||
}
|
||||
.btn-secondary:hover {
|
||||
transform: translateY(-2px);
|
||||
background: linear-gradient(135deg, #666 0%, #777 100%);
|
||||
}
|
||||
.button-group {
|
||||
text-align: center;
|
||||
margin-top: 30px;
|
||||
}
|
||||
.preview {
|
||||
background: rgba(15, 20, 25, 0.6);
|
||||
padding: 20px;
|
||||
border-radius: 12px;
|
||||
margin-top: 30px;
|
||||
border: 1px solid rgba(29, 185, 84, 0.2);
|
||||
}
|
||||
.preview-title {
|
||||
font-size: 1.2em;
|
||||
color: #1DB954;
|
||||
margin-bottom: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
.preview-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
.preview-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function updatePreview() {
|
||||
const maxPoints = parseInt(document.getElementById('max_points').value);
|
||||
const gracePeriod = parseInt(document.getElementById('grace_period').value);
|
||||
const decayRate = parseInt(document.getElementById('decay_rate').value);
|
||||
|
||||
document.getElementById('maxPointsDisplay').textContent = maxPoints;
|
||||
document.getElementById('gracePeriodDisplay').textContent = gracePeriod;
|
||||
document.getElementById('decayRateDisplay').textContent = decayRate;
|
||||
|
||||
// Berechne Beispielwerte
|
||||
const pointsAt10s = Math.max(0, maxPoints - Math.max(0, 10 - gracePeriod) * decayRate);
|
||||
const pointsAt20s = Math.max(0, maxPoints - Math.max(0, 20 - gracePeriod) * decayRate);
|
||||
const pointsAt30s = Math.max(0, maxPoints - Math.max(0, 30 - gracePeriod) * decayRate);
|
||||
|
||||
document.getElementById('pointsAt10s').textContent = pointsAt10s;
|
||||
document.getElementById('pointsAt20s').textContent = pointsAt20s;
|
||||
document.getElementById('pointsAt30s').textContent = pointsAt30s;
|
||||
}
|
||||
|
||||
function saveSettings() {
|
||||
const maxPoints = document.getElementById('max_points').value;
|
||||
const gracePeriod = document.getElementById('grace_period').value;
|
||||
const decayRate = document.getElementById('decay_rate').value;
|
||||
|
||||
localStorage.setItem('buzzer_max_points', maxPoints);
|
||||
localStorage.setItem('buzzer_grace_period', gracePeriod);
|
||||
localStorage.setItem('buzzer_decay_rate', decayRate);
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
// Lade gespeicherte Werte oder verwende Defaults
|
||||
document.getElementById('max_points').value = localStorage.getItem('buzzer_max_points') || '1000';
|
||||
document.getElementById('grace_period').value = localStorage.getItem('buzzer_grace_period') || '5';
|
||||
document.getElementById('decay_rate').value = localStorage.getItem('buzzer_decay_rate') || '50';
|
||||
updatePreview();
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="settings-container">
|
||||
<h2>⚙️ Buzzer Einstellungen</h2>
|
||||
|
||||
<div class="setting-group">
|
||||
<label class="setting-label" for="max_points">
|
||||
Maximale Punkte <span class="value-display" id="maxPointsDisplay">1000</span>
|
||||
</label>
|
||||
<div class="setting-description">Die maximalen Punkte, die man innerhalb der Schonzeit erreichen kann.</div>
|
||||
<input type="range" class="setting-input" id="max_points" min="100" max="5000" step="100" value="1000" oninput="updatePreview()">
|
||||
</div>
|
||||
|
||||
<div class="setting-group">
|
||||
<label class="setting-label" for="grace_period">
|
||||
Schonzeit <span class="value-display" id="gracePeriodDisplay">5</span> Sekunden
|
||||
</label>
|
||||
<div class="setting-description">Zeit in Sekunden, in der keine Punkte abgezogen werden.</div>
|
||||
<input type="range" class="setting-input" id="grace_period" min="0" max="15" step="1" value="5" oninput="updatePreview()">
|
||||
</div>
|
||||
|
||||
<div class="setting-group">
|
||||
<label class="setting-label" for="decay_rate">
|
||||
Verfallsrate <span class="value-display" id="decayRateDisplay">50</span> Punkte/Sekunde
|
||||
</label>
|
||||
<div class="setting-description">Punkte, die pro Sekunde nach der Schonzeit verloren gehen.</div>
|
||||
<input type="range" class="setting-input" id="decay_rate" min="10" max="200" step="10" value="50" oninput="updatePreview()">
|
||||
</div>
|
||||
|
||||
<div class="preview">
|
||||
<div class="preview-title">📊 Beispiel: Punkte nach Zeit</div>
|
||||
<div class="preview-item">
|
||||
<span>Nach 10 Sekunden:</span>
|
||||
<span class="value-display" id="pointsAt10s">750</span>
|
||||
</div>
|
||||
<div class="preview-item">
|
||||
<span>Nach 20 Sekunden:</span>
|
||||
<span class="value-display" id="pointsAt20s">250</span>
|
||||
</div>
|
||||
<div class="preview-item">
|
||||
<span>Nach 30 Sekunden:</span>
|
||||
<span class="value-display" id="pointsAt30s">0</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="button-group">
|
||||
<a href="/quiz/{{ playlist_id }}?mode={{ game_mode }}&buzzer=1{% if local_multiplayer %}&local_multiplayer=1{% endif %}" class="btn btn-primary" onclick="saveSettings()">
|
||||
✅ Starten
|
||||
</a>
|
||||
<a href="/playerselect/{{ playlist_id }}?mode={{ game_mode }}&buzzer=1" class="btn btn-secondary">
|
||||
⬅️ Zurück
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -60,7 +60,7 @@
|
||||
<body>
|
||||
<div class="playerselect-container">
|
||||
<h2>{{ translations['quiz_title'] }} – Player Selection</h2>
|
||||
<form method="get" action="{{ url_for('quiz', playlist_id=playlist_id) }}">
|
||||
<form method="get" action="{{ url_for('buzzer_settings', playlist_id=playlist_id) }}">
|
||||
<input type="hidden" name="mode" value="{{ game_mode }}">
|
||||
{% if request.args.get('buzzer') == '1' %}
|
||||
<input type="hidden" name="buzzer" value="1">
|
||||
@@ -68,7 +68,7 @@
|
||||
<button class="player-btn" type="submit">{{ translations['singleplayer'] }}</button>
|
||||
<div class="player-desc">{{ translations['singleplayer_desc'] if translations['singleplayer_desc'] else 'Play alone and test your knowledge.' }}</div>
|
||||
</form>
|
||||
<form method="get" action="{{ url_for('quiz', playlist_id=playlist_id) }}">
|
||||
<form method="get" action="{{ url_for('buzzer_settings', playlist_id=playlist_id) }}">
|
||||
<input type="hidden" name="mode" value="{{ game_mode }}">
|
||||
<input type="hidden" name="local_multiplayer" value="1">
|
||||
{% if request.args.get('buzzer') == '1' %}
|
||||
|
||||
@@ -216,9 +216,9 @@
|
||||
let buzzTimer = null;
|
||||
let startTime = null;
|
||||
let buzzTime = null;
|
||||
let maxPoints = {{ max_points | default(1000) }};
|
||||
let gracePeriod = {{ grace_period | default(5) }}; // Sekunden
|
||||
let decayRate = {{ decay_rate | default(50) }}; // Punkte pro Sekunde nach Grace Period
|
||||
let maxPoints = parseInt(localStorage.getItem('buzzer_max_points')) || {{ max_points | default(1000) }};
|
||||
let gracePeriod = parseInt(localStorage.getItem('buzzer_grace_period')) || {{ grace_period | default(5) }}; // Sekunden
|
||||
let decayRate = parseInt(localStorage.getItem('buzzer_decay_rate')) || {{ decay_rate | default(50) }}; // Punkte pro Sekunde nach Grace Period
|
||||
let hasBuzzed = false;
|
||||
let gameStarted = false;
|
||||
|
||||
@@ -503,6 +503,12 @@
|
||||
|
||||
window.onload = function() {
|
||||
document.getElementById('startPosition').value = getOption('startPosition', 'start');
|
||||
|
||||
// Lade Einstellungen und zeige initial an
|
||||
maxPoints = parseInt(localStorage.getItem('buzzer_max_points')) || 1000;
|
||||
gracePeriod = parseInt(localStorage.getItem('buzzer_grace_period')) || 5;
|
||||
decayRate = parseInt(localStorage.getItem('buzzer_decay_rate')) || 50;
|
||||
document.getElementById('pointsDisplay').textContent = maxPoints + ' Punkte';
|
||||
};
|
||||
</script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
617
templates/quiz_buzzer_multiplayer.html
Normal file
617
templates/quiz_buzzer_multiplayer.html
Normal file
@@ -0,0 +1,617 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{{ translations['quiz_title'] }} – Buzzer Multiplayer</title>
|
||||
<script src="https://sdk.scdn.co/spotify-player.js"></script>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 50%, #0f1419 100%);
|
||||
color: #e0e0e0;
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.quiz-container {
|
||||
max-width: 1200px;
|
||||
width: 100%;
|
||||
background: rgba(25, 30, 45, 0.95);
|
||||
border-radius: 20px;
|
||||
padding: 40px;
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
.scoreboard {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 15px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.player-card {
|
||||
background: rgba(15, 20, 25, 0.8);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
border: 2px solid rgba(29, 185, 84, 0.3);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
.player-card.active {
|
||||
border-color: #1DB954;
|
||||
box-shadow: 0 0 20px rgba(29, 185, 84, 0.5);
|
||||
}
|
||||
.player-card.buzzed {
|
||||
border-color: #f44336;
|
||||
box-shadow: 0 0 20px rgba(244, 67, 54, 0.5);
|
||||
}
|
||||
.player-name {
|
||||
font-size: 1.3em;
|
||||
font-weight: bold;
|
||||
color: #1DB954;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.player-score {
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
color: #e0e0e0;
|
||||
}
|
||||
.buzzer-timer {
|
||||
text-align: center;
|
||||
font-size: 4em;
|
||||
font-weight: bold;
|
||||
color: #1DB954;
|
||||
margin: 30px 0;
|
||||
text-shadow: 0 0 20px rgba(29, 185, 84, 0.5);
|
||||
}
|
||||
.buzzer-timer.warning {
|
||||
color: #FFA500;
|
||||
animation: pulse 1s infinite;
|
||||
}
|
||||
.buzzer-timer.critical {
|
||||
color: #f44336;
|
||||
animation: pulse 0.5s infinite;
|
||||
}
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; transform: scale(1); }
|
||||
50% { opacity: 0.7; transform: scale(1.05); }
|
||||
}
|
||||
.points-display {
|
||||
text-align: center;
|
||||
font-size: 2.5em;
|
||||
font-weight: bold;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.points-display.high {
|
||||
color: #4CAF50;
|
||||
}
|
||||
.points-display.medium {
|
||||
color: #FFA500;
|
||||
}
|
||||
.points-display.low {
|
||||
color: #f44336;
|
||||
}
|
||||
.buzzer-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 20px;
|
||||
margin: 30px 0;
|
||||
}
|
||||
.player-buzzer {
|
||||
height: 150px;
|
||||
border-radius: 20px;
|
||||
background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
|
||||
border: 5px solid rgba(244, 67, 54, 0.3);
|
||||
font-size: 1.5em;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
box-shadow: 0 10px 40px rgba(244, 67, 54, 0.5);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.player-buzzer:hover:not(.disabled) {
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0 15px 50px rgba(244, 67, 54, 0.7);
|
||||
}
|
||||
.player-buzzer:active:not(.disabled) {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
.player-buzzer.disabled {
|
||||
background: linear-gradient(135deg, #666 0%, #444 100%);
|
||||
border-color: rgba(100, 100, 100, 0.3);
|
||||
cursor: not-allowed;
|
||||
opacity: 0.5;
|
||||
}
|
||||
.player-buzzer.start {
|
||||
grid-column: 1 / -1;
|
||||
background: linear-gradient(135deg, #1DB954 0%, #1ed760 100%);
|
||||
border-color: rgba(29, 185, 84, 0.3);
|
||||
box-shadow: 0 10px 40px rgba(29, 185, 84, 0.5);
|
||||
}
|
||||
.player-buzzer.start:hover {
|
||||
box-shadow: 0 15px 50px rgba(29, 185, 84, 0.7);
|
||||
}
|
||||
.answer-section {
|
||||
display: none;
|
||||
text-align: center;
|
||||
margin-top: 30px;
|
||||
}
|
||||
.answer-section.active {
|
||||
display: block;
|
||||
animation: slideIn 0.3s ease;
|
||||
}
|
||||
@keyframes slideIn {
|
||||
from { opacity: 0; transform: translateY(-10px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
.btn {
|
||||
padding: 12px 24px;
|
||||
margin: 5px;
|
||||
background: linear-gradient(135deg, #1DB954 0%, #1ed760 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 25px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 15px rgba(29, 185, 84, 0.3);
|
||||
}
|
||||
.btn:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(29, 185, 84, 0.5);
|
||||
}
|
||||
.btn-secondary {
|
||||
background: linear-gradient(135deg, #535353 0%, #6b6b6b 100%);
|
||||
box-shadow: 0 4px 15px rgba(83, 83, 83, 0.3);
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #f44336 0%, #e57373 100%);
|
||||
}
|
||||
input[type="text"] {
|
||||
padding: 14px 20px;
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
border: 2px solid rgba(29, 185, 84, 0.3);
|
||||
background: rgba(15, 20, 35, 0.6);
|
||||
color: #e0e0e0;
|
||||
border-radius: 25px;
|
||||
font-size: 16px;
|
||||
transition: all 0.3s ease;
|
||||
outline: none;
|
||||
}
|
||||
input[type="text"]:focus {
|
||||
border-color: #1DB954;
|
||||
box-shadow: 0 0 15px rgba(29, 185, 84, 0.4);
|
||||
}
|
||||
.result-container {
|
||||
margin: 25px 0;
|
||||
padding: 20px;
|
||||
border-radius: 15px;
|
||||
}
|
||||
.search-results {
|
||||
position: relative;
|
||||
max-width: 400px;
|
||||
margin: 10px auto;
|
||||
background: rgba(15, 20, 35, 0.95);
|
||||
border-radius: 12px;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
display: none;
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
.search-item {
|
||||
padding: 12px 20px;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
transition: background 0.2s;
|
||||
}
|
||||
.search-item:hover {
|
||||
background: rgba(29, 185, 84, 0.2);
|
||||
}
|
||||
.search-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
.current-player {
|
||||
text-align: center;
|
||||
font-size: 1.5em;
|
||||
color: #1DB954;
|
||||
margin: 20px 0;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
let allTracks = {{ all_tracks|tojson }};
|
||||
let currentGameMode = "{{ game_mode }}";
|
||||
let correctAnswer = "";
|
||||
const i18n = {{ translations|tojson }};
|
||||
|
||||
let buzzTimer = null;
|
||||
let startTime = null;
|
||||
let buzzTime = null;
|
||||
let maxPoints = parseInt(localStorage.getItem('buzzer_max_points')) || 1000;
|
||||
let gracePeriod = parseInt(localStorage.getItem('buzzer_grace_period')) || 5;
|
||||
let decayRate = parseInt(localStorage.getItem('buzzer_decay_rate')) || 50;
|
||||
let gameStarted = false;
|
||||
let currentBuzzer = null;
|
||||
|
||||
// Spieler-Daten
|
||||
let players = [
|
||||
{ id: 1, name: 'Spieler 1', score: {{ player_scores[0] if player_scores else 0 }} },
|
||||
{ id: 2, name: 'Spieler 2', score: {{ player_scores[1] if player_scores else 0 }} },
|
||||
{ id: 3, name: 'Spieler 3', score: {{ player_scores[2] if player_scores else 0 }} },
|
||||
{ id: 4, name: 'Spieler 4', score: {{ player_scores[3] if player_scores else 0 }} }
|
||||
];
|
||||
|
||||
window.onSpotifyWebPlaybackSDKReady = () => {
|
||||
const token = '{{ access_token }}';
|
||||
const player = new Spotify.Player({
|
||||
name: 'Musik Quiz Buzzer Multiplayer',
|
||||
getOAuthToken: cb => { cb(token); },
|
||||
volume: 0.5
|
||||
});
|
||||
|
||||
player.addListener('initialization_error', ({ message }) => { console.error(message); });
|
||||
player.addListener('authentication_error', ({ message }) => { console.error(message); });
|
||||
player.addListener('account_error', ({ message }) => { console.error(message); });
|
||||
player.addListener('playback_error', ({ message }) => { console.error(message); });
|
||||
|
||||
player.addListener('ready', ({ device_id }) => {
|
||||
console.log('Ready with Device ID', device_id);
|
||||
document.getElementById('device_id').value = device_id;
|
||||
window.deviceId = device_id;
|
||||
setCorrectAnswer();
|
||||
updateScoreboard();
|
||||
});
|
||||
|
||||
player.addListener('player_state_changed', state => {
|
||||
if (!state) return;
|
||||
|
||||
if (!state.paused && gameStarted && !startTime) {
|
||||
console.log('Music started playing, starting timer in 1 second');
|
||||
setTimeout(() => {
|
||||
startBuzzerTimer();
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
player.addListener('not_ready', ({ device_id }) => {
|
||||
console.log('Device ID has gone offline', device_id);
|
||||
});
|
||||
|
||||
player.connect();
|
||||
window.spotifyPlayer = player;
|
||||
};
|
||||
|
||||
function updateScoreboard() {
|
||||
players.forEach((player, index) => {
|
||||
const card = document.getElementById(`player${player.id}`);
|
||||
if (card) {
|
||||
card.querySelector('.player-score').textContent = player.score;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function startGame() {
|
||||
if (gameStarted) return;
|
||||
|
||||
gameStarted = true;
|
||||
document.getElementById('startButton').classList.add('disabled');
|
||||
document.getElementById('startButton').style.cursor = 'wait';
|
||||
|
||||
const device_id = window.deviceId;
|
||||
const startPosition = getOption('startPosition', 'start');
|
||||
let position_ms = 0;
|
||||
if (startPosition === 'random') {
|
||||
const duration = {{ track.duration_ms if track.duration_ms else 180000 }};
|
||||
position_ms = Math.floor(Math.random() * (duration - 30000));
|
||||
}
|
||||
|
||||
fetch(`/play_track?device_id=${device_id}&track_uri={{ track.uri }}&position_ms=${position_ms}`, { method: 'POST' })
|
||||
.then(response => response.json())
|
||||
.then(() => {
|
||||
console.log('Play command sent');
|
||||
document.getElementById('startButton').style.display = 'none';
|
||||
// Aktiviere Buzzer
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
document.getElementById(`buzzer${i}`).classList.remove('disabled');
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error starting playback:', error));
|
||||
}
|
||||
|
||||
function startBuzzerTimer() {
|
||||
startTime = Date.now();
|
||||
updateTimer();
|
||||
}
|
||||
|
||||
function updateTimer() {
|
||||
if (currentBuzzer) return;
|
||||
|
||||
const elapsed = (Date.now() - startTime) / 1000;
|
||||
const timerDisplay = document.getElementById('buzzerTimer');
|
||||
const pointsDisplay = document.getElementById('pointsDisplay');
|
||||
|
||||
timerDisplay.textContent = elapsed.toFixed(2) + 's';
|
||||
|
||||
const currentPoints = calculatePoints(elapsed);
|
||||
pointsDisplay.textContent = currentPoints + ' Punkte';
|
||||
|
||||
timerDisplay.className = 'buzzer-timer';
|
||||
pointsDisplay.className = 'points-display';
|
||||
|
||||
if (elapsed > gracePeriod + 10) {
|
||||
timerDisplay.classList.add('critical');
|
||||
pointsDisplay.classList.add('low');
|
||||
} else if (elapsed > gracePeriod) {
|
||||
timerDisplay.classList.add('warning');
|
||||
pointsDisplay.classList.add('medium');
|
||||
} else {
|
||||
pointsDisplay.classList.add('high');
|
||||
}
|
||||
|
||||
buzzTimer = requestAnimationFrame(updateTimer);
|
||||
}
|
||||
|
||||
function calculatePoints(elapsed) {
|
||||
if (elapsed <= gracePeriod) {
|
||||
return maxPoints;
|
||||
}
|
||||
const overtime = elapsed - gracePeriod;
|
||||
const points = Math.max(0, maxPoints - Math.floor(overtime * decayRate));
|
||||
return points;
|
||||
}
|
||||
|
||||
function buzz(playerId) {
|
||||
if (currentBuzzer !== null) return;
|
||||
if (!gameStarted || !startTime) return;
|
||||
|
||||
currentBuzzer = playerId;
|
||||
buzzTime = Date.now();
|
||||
const elapsed = (buzzTime - startTime) / 1000;
|
||||
|
||||
cancelAnimationFrame(buzzTimer);
|
||||
|
||||
if (window.spotifyPlayer) {
|
||||
window.spotifyPlayer.pause();
|
||||
}
|
||||
|
||||
// Markiere Spieler
|
||||
document.getElementById(`player${playerId}`).classList.add('buzzed');
|
||||
document.getElementById('currentPlayer').textContent = `${players[playerId - 1].name} hat gebuzzert!`;
|
||||
|
||||
// Deaktiviere alle Buzzer
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
document.getElementById(`buzzer${i}`).classList.add('disabled');
|
||||
}
|
||||
|
||||
document.getElementById('answerSection').classList.add('active');
|
||||
window.earnedPoints = calculatePoints(elapsed);
|
||||
}
|
||||
|
||||
function setCorrectAnswer() {
|
||||
if (currentGameMode === 'artist') {
|
||||
correctAnswer = "{{ track.artists[0].name | clean }}";
|
||||
document.getElementById('question-text').innerText = i18n.question_artist || 'Guess the artist!';
|
||||
document.getElementById('answerInput').placeholder = i18n.input_artist || 'Artist name';
|
||||
} else if (currentGameMode === 'title') {
|
||||
correctAnswer = "{{ track.name | clean }}";
|
||||
document.getElementById('question-text').innerText = i18n.question_title || 'Guess the title!';
|
||||
document.getElementById('answerInput').placeholder = i18n.input_title || 'Song title';
|
||||
} else if (currentGameMode === 'year') {
|
||||
correctAnswer = "{{ track.album.release_date[:4] }}";
|
||||
document.getElementById('question-text').innerText = i18n.question_year || 'Guess the year!';
|
||||
document.getElementById('answerInput').placeholder = i18n.input_year || 'Year';
|
||||
document.getElementById('answerInput').type = "number";
|
||||
}
|
||||
}
|
||||
|
||||
function searchTracks() {
|
||||
const query = document.getElementById('answerInput').value;
|
||||
if (query.length < 2) {
|
||||
document.getElementById('searchResults').style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('/search_track', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
query: query,
|
||||
all_tracks: allTracks
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const resultsContainer = document.getElementById('searchResults');
|
||||
resultsContainer.innerHTML = '';
|
||||
|
||||
if (data.results.length === 0) {
|
||||
resultsContainer.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
data.results.forEach(result => {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'search-item';
|
||||
item.innerHTML = `<strong>${result.name}</strong> - ${result.artist}`;
|
||||
item.onclick = function() {
|
||||
document.getElementById('answerInput').value =
|
||||
currentGameMode === 'artist' ? result.artist : result.name;
|
||||
resultsContainer.style.display = 'none';
|
||||
};
|
||||
resultsContainer.appendChild(item);
|
||||
});
|
||||
|
||||
resultsContainer.style.display = 'block';
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error searching tracks:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkAnswer() {
|
||||
const guess = document.getElementById('answerInput').value;
|
||||
if (!guess) return;
|
||||
|
||||
fetch('/check_answer_buzzer', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
guess: guess,
|
||||
correct_answer: correctAnswer,
|
||||
game_mode: currentGameMode,
|
||||
playlist_id: '{{ playlist_id }}',
|
||||
earned_points: window.earnedPoints,
|
||||
player_id: currentBuzzer
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const resultContainer = document.getElementById('resultContainer');
|
||||
|
||||
if (data.correct) {
|
||||
players[currentBuzzer - 1].score += window.earnedPoints;
|
||||
updateScoreboard();
|
||||
|
||||
resultContainer.innerHTML = `
|
||||
<div style="background:linear-gradient(135deg, rgba(76, 175, 80, 0.2) 0%, rgba(56, 142, 60, 0.2) 100%); padding:20px; border-radius:12px; border:2px solid #4CAF50;">
|
||||
<h3 style="color:#4CAF50; margin-bottom:10px;">✅ ${i18n.correct || 'Correct'}</h3>
|
||||
<p style="font-size:1.5em; margin:10px 0;"><strong style="color:#1DB954;">+${window.earnedPoints}</strong> Punkte für ${players[currentBuzzer - 1].name}!</p>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
resultContainer.innerHTML = `
|
||||
<div style="background:linear-gradient(135deg, rgba(244, 67, 54, 0.2) 0%, rgba(211, 47, 47, 0.2) 100%); padding:20px; border-radius:12px; border:2px solid #f44336;">
|
||||
<h3 style="color:#f44336; margin-bottom:10px;">❌ ${i18n.incorrect || 'Incorrect'}</h3>
|
||||
<p style="font-size:1.1em; margin:10px 0;">${i18n.your_answer || 'Your answer'}: <strong style="color:#f44336;">${guess}</strong></p>
|
||||
<p style="font-size:1.1em; margin:10px 0;">${i18n.correct_answer || 'Correct answer'}: <strong style="color:#4CAF50;">${data.correct_answer}</strong></p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
if (data.comparison) {
|
||||
resultContainer.innerHTML += `
|
||||
<div style="margin-top:20px; padding:20px; background:rgba(15,20,25,0.8); border-radius:12px;">
|
||||
<h4 style="color:#1DB954; margin-bottom:15px;">${i18n.song_info || 'Song Info'}:</h4>
|
||||
<p style="margin:8px 0;"><strong style="color:#1DB954;">${i18n.title || 'Title'}:</strong> <span style="color:#e0e0e0;">{{ track.name | clean }}</span></p>
|
||||
<p style="margin:8px 0;"><strong style="color:#1DB954;">${i18n.artist || 'Artist'}:</strong> <span style="color:#e0e0e0;">{{ track.artists[0].name | clean }}</span></p>
|
||||
<p style="margin:8px 0;"><strong style="color:#1DB954;">${i18n.album || 'Album'}:</strong> <span style="color:#e0e0e0;">{{ track.album.name | clean }}</span></p>
|
||||
<p style="margin:8px 0;"><strong style="color:#1DB954;">${i18n.year || 'Year'}:</strong> <span style="color:#e0e0e0;">{{ track.album.release_date[:4] }}</span></p>
|
||||
<a href="{{ track.external_urls.spotify }}" target="_blank" style="display:inline-block; margin-top:10px; padding:8px 16px; background:linear-gradient(135deg, #1DB954 0%, #1ed760 100%); color:#fff; text-decoration:none; border-radius:20px; font-weight:600; transition:all 0.3s ease;">${i18n.open_on_spotify || 'Open on Spotify'}</a>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
document.getElementById('nextQuestionBtn').style.display = 'inline-block';
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error checking answer:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function switchGameMode(mode) {
|
||||
window.location.href = `/reset_quiz/{{ playlist_id }}?next_mode=${mode}&buzzer=1&local_multiplayer=1`;
|
||||
}
|
||||
|
||||
function getOption(key, defaultValue) {
|
||||
return localStorage.getItem(key) || defaultValue;
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
document.getElementById('startPosition').value = getOption('startPosition', 'start');
|
||||
maxPoints = parseInt(localStorage.getItem('buzzer_max_points')) || 1000;
|
||||
gracePeriod = parseInt(localStorage.getItem('buzzer_grace_period')) || 5;
|
||||
decayRate = parseInt(localStorage.getItem('buzzer_decay_rate')) || 50;
|
||||
document.getElementById('pointsDisplay').textContent = maxPoints + ' Punkte';
|
||||
};
|
||||
</script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<div class="quiz-container">
|
||||
<!-- Scoreboard -->
|
||||
<div class="scoreboard">
|
||||
<div class="player-card" id="player1">
|
||||
<div class="player-name">Spieler 1</div>
|
||||
<div class="player-score">0</div>
|
||||
</div>
|
||||
<div class="player-card" id="player2">
|
||||
<div class="player-name">Spieler 2</div>
|
||||
<div class="player-score">0</div>
|
||||
</div>
|
||||
<div class="player-card" id="player3">
|
||||
<div class="player-name">Spieler 3</div>
|
||||
<div class="player-score">0</div>
|
||||
</div>
|
||||
<div class="player-card" id="player4">
|
||||
<div class="player-name">Spieler 4</div>
|
||||
<div class="player-score">0</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" id="device_id" value="">
|
||||
|
||||
<h2 id="question-text" style="text-align:center; margin:20px 0;">{{ translations['question_title'] }}</h2>
|
||||
|
||||
<!-- Timer & Points Display -->
|
||||
<div class="buzzer-timer" id="buzzerTimer">0.00s</div>
|
||||
<div class="points-display high" id="pointsDisplay">1000 Punkte</div>
|
||||
|
||||
<div class="current-player" id="currentPlayer">Drücke START um zu beginnen</div>
|
||||
|
||||
<!-- Buzzer Buttons -->
|
||||
<div class="buzzer-grid">
|
||||
<button class="player-buzzer start" id="startButton" onclick="startGame()">
|
||||
▶️<br>START
|
||||
</button>
|
||||
<button class="player-buzzer disabled" id="buzzer1" onclick="buzz(1)">
|
||||
🔴<br>Spieler 1
|
||||
</button>
|
||||
<button class="player-buzzer disabled" id="buzzer2" onclick="buzz(2)">
|
||||
🔴<br>Spieler 2
|
||||
</button>
|
||||
<button class="player-buzzer disabled" id="buzzer3" onclick="buzz(3)">
|
||||
🔴<br>Spieler 3
|
||||
</button>
|
||||
<button class="player-buzzer disabled" id="buzzer4" onclick="buzz(4)">
|
||||
🔴<br>Spieler 4
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Answer Section -->
|
||||
<div class="answer-section" id="answerSection">
|
||||
<h3 style="margin-bottom:15px;">{{ translations['enter_answer'] if translations.get('enter_answer') else 'Enter your answer' }}:</h3>
|
||||
<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>
|
||||
|
||||
<div id="searchResults" class="search-results"></div>
|
||||
<div id="resultContainer" class="result-container"></div>
|
||||
|
||||
<a id="nextQuestionBtn" href="/quiz/{{ playlist_id }}?mode={{ game_mode }}&buzzer=1&local_multiplayer=1" class="btn" style="display: none; margin-top:15px;">{{ translations['next_question'] if translations.get('next_question') else 'Next Question' }}</a>
|
||||
</div>
|
||||
|
||||
<!-- Game Mode Switcher -->
|
||||
<div style="text-align:center; margin-top:30px;">
|
||||
<button class="btn {{ 'btn-success' if game_mode == 'artist' else 'btn-secondary' }}" onclick="switchGameMode('artist')">{{ translations['guess_artist'] }}</button>
|
||||
<button class="btn {{ 'btn-success' if game_mode == 'title' else 'btn-secondary' }}" onclick="switchGameMode('title')">{{ translations['guess_title'] }}</button>
|
||||
<button class="btn {{ 'btn-success' if game_mode == 'year' else 'btn-secondary' }}" onclick="switchGameMode('year')">{{ translations['guess_year'] }}</button>
|
||||
</div>
|
||||
|
||||
<!-- Navigation -->
|
||||
<div style="text-align:center; margin-top:30px;">
|
||||
<a href="/reset_quiz/{{ playlist_id }}?buzzer=1&local_multiplayer=1" class="btn btn-danger">{{ translations['end_quiz'] if translations.get('end_quiz') else '🏁 End Quiz' }}</a>
|
||||
<a href="/playlists" class="btn btn-secondary">{{ translations['back_to_playlists'] if translations.get('back_to_playlists') else '⬅️ Back' }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user