391 lines
9.2 KiB
Python
391 lines
9.2 KiB
Python
from flask import Flask, request, session
|
|
from html import escape
|
|
import sqlite3
|
|
import time
|
|
|
|
|
|
app = Flask(__name__)
|
|
app.secret_key = "stadion-escape-secret"
|
|
|
|
|
|
STYLE = """
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Glück Auf Stadion Escape</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Barlow:wght@300;400;500&display=swap" rel="stylesheet">
|
|
<style>
|
|
*, *::before, *::after {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
margin: 0;
|
|
min-height: 100vh;
|
|
font-family: "Barlow", sans-serif;
|
|
color: #f5f8ff;
|
|
background:
|
|
linear-gradient(rgba(0, 20, 60, 0.9), rgba(0, 31, 68, 0.96)),
|
|
radial-gradient(circle at 50% 120%, rgba(255, 255, 255, 0.16), transparent 34%),
|
|
#001f44;
|
|
}
|
|
|
|
nav {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
gap: 2rem;
|
|
padding: 1.2rem 2.5rem;
|
|
background: rgba(0, 20, 60, 0.88);
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
|
}
|
|
|
|
.logo {
|
|
color: #fff;
|
|
font-family: "Bebas Neue", sans-serif;
|
|
font-size: 1.7rem;
|
|
letter-spacing: 0.12em;
|
|
text-decoration: none;
|
|
}
|
|
|
|
nav a:not(.logo) {
|
|
color: rgba(255, 255, 255, 0.52);
|
|
font-size: 0.82rem;
|
|
letter-spacing: 0.12em;
|
|
text-decoration: none;
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
nav a:hover {
|
|
color: #fff;
|
|
}
|
|
|
|
main {
|
|
position: relative;
|
|
min-height: calc(100vh - 76px);
|
|
display: grid;
|
|
align-items: center;
|
|
padding: 4rem 3rem;
|
|
overflow: hidden;
|
|
}
|
|
|
|
main::before {
|
|
content: "";
|
|
position: absolute;
|
|
inset: auto 8% 0;
|
|
height: 42%;
|
|
border: 1px solid rgba(122, 179, 255, 0.22);
|
|
border-bottom: 0;
|
|
border-radius: 50% 50% 0 0;
|
|
opacity: 0.75;
|
|
}
|
|
|
|
.scene,
|
|
.puzzle {
|
|
position: relative;
|
|
z-index: 1;
|
|
max-width: 760px;
|
|
}
|
|
|
|
.puzzle {
|
|
width: min(720px, 100%);
|
|
margin: 0 auto;
|
|
padding: 2rem;
|
|
border: 1px solid rgba(122, 179, 255, 0.28);
|
|
background: rgba(0, 31, 68, 0.72);
|
|
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
|
|
}
|
|
|
|
h1 {
|
|
margin-top: 0;
|
|
margin-bottom: 1.5rem;
|
|
font-family: "Bebas Neue", sans-serif;
|
|
font-size: clamp(3rem, 8vw, 7rem);
|
|
line-height: 0.92;
|
|
letter-spacing: 0.03em;
|
|
color: #fff;
|
|
text-shadow: 0 4px 40px rgba(0, 80, 200, 0.7);
|
|
}
|
|
|
|
h2 {
|
|
margin-top: 2rem;
|
|
font-family: "Bebas Neue", sans-serif;
|
|
font-size: 2.2rem;
|
|
letter-spacing: 0.06em;
|
|
}
|
|
|
|
h1 span {
|
|
color: #7ab3ff;
|
|
}
|
|
|
|
p {
|
|
max-width: 560px;
|
|
color: rgba(255, 255, 255, 0.68);
|
|
font-size: 1.05rem;
|
|
font-weight: 300;
|
|
line-height: 1.8;
|
|
}
|
|
|
|
.tag,
|
|
label {
|
|
color: rgba(255, 255, 255, 0.46);
|
|
font-size: 0.72rem;
|
|
letter-spacing: 0.2em;
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
.tag {
|
|
margin-bottom: 1.2rem;
|
|
}
|
|
|
|
.clue,
|
|
.result,
|
|
.highscore {
|
|
margin: 1.4rem 0;
|
|
padding: 1rem 1.2rem;
|
|
border-left: 3px solid #7ab3ff;
|
|
background: rgba(255, 255, 255, 0.06);
|
|
color: rgba(255, 255, 255, 0.82);
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin-bottom: 0.6rem;
|
|
}
|
|
|
|
form {
|
|
margin-top: 1.4rem;
|
|
}
|
|
|
|
input {
|
|
width: 100%;
|
|
padding: 0.95rem 1rem;
|
|
border: 1px solid rgba(255, 255, 255, 0.18);
|
|
background: rgba(255, 255, 255, 0.06);
|
|
color: #fff;
|
|
outline: none;
|
|
font-size: 16px;
|
|
}
|
|
|
|
input:focus {
|
|
border-color: rgba(122, 179, 255, 0.9);
|
|
box-shadow: 0 0 0 3px rgba(122, 179, 255, 0.12);
|
|
}
|
|
|
|
a.btn,
|
|
button {
|
|
display: inline-block;
|
|
margin-top: 1rem;
|
|
padding: 0.82rem 2.2rem;
|
|
color: #001f44;
|
|
background: #fff;
|
|
border: 0;
|
|
text-decoration: none;
|
|
font-family: "Barlow", sans-serif;
|
|
font-size: 0.82rem;
|
|
font-weight: 500;
|
|
letter-spacing: 0.12em;
|
|
text-transform: uppercase;
|
|
cursor: pointer;
|
|
transition: background 0.2s, color 0.2s, transform 0.15s;
|
|
}
|
|
|
|
a.btn:hover,
|
|
button:hover {
|
|
color: #fff;
|
|
background: #0057c2;
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.secondary {
|
|
padding-inline: 1.6rem;
|
|
background: rgba(255, 255, 255, 0.14);
|
|
color: #fff;
|
|
}
|
|
|
|
ol {
|
|
padding-left: 1.4rem;
|
|
}
|
|
|
|
li {
|
|
margin-bottom: 0.45rem;
|
|
color: rgba(255, 255, 255, 0.78);
|
|
}
|
|
|
|
@media (max-width: 640px) {
|
|
nav {
|
|
align-items: flex-start;
|
|
flex-direction: column;
|
|
padding: 1rem 1.5rem;
|
|
}
|
|
|
|
main {
|
|
padding: 3rem 1.5rem;
|
|
}
|
|
|
|
.puzzle {
|
|
padding: 1.4rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<nav>
|
|
<a class="logo" href="/app/">Glück Auf</a>
|
|
<a href="/app/raum/stadiontor">Stadiontor</a>
|
|
</nav>
|
|
<main>
|
|
"""
|
|
|
|
|
|
HTML_END = """
|
|
</main>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
|
|
def get_db():
|
|
db = sqlite3.connect("adventure.db")
|
|
db.row_factory = sqlite3.Row
|
|
return db
|
|
|
|
|
|
def seite_html(inhalt, klasse="puzzle"):
|
|
return STYLE + '<section class="' + klasse + '">' + inhalt + "</section>" + HTML_END
|
|
|
|
|
|
def highscore_html(db):
|
|
eintraege = db.execute(
|
|
"""
|
|
SELECT name, fertig_zeit - start_zeit AS dauer
|
|
FROM spieler
|
|
WHERE fertig_zeit IS NOT NULL
|
|
ORDER BY dauer
|
|
LIMIT 10
|
|
"""
|
|
).fetchall()
|
|
|
|
if not eintraege:
|
|
return ""
|
|
|
|
html = '<div class="highscore"><h2>Highscore</h2><ol>'
|
|
for eintrag in eintraege:
|
|
html += "<li>" + escape(eintrag["name"]) + " - " + str(round(eintrag["dauer"], 1)) + " Sekunden</li>"
|
|
html += "</ol></div>"
|
|
return html
|
|
|
|
|
|
@app.route("/", methods=["GET", "POST"])
|
|
@app.route("/app/", methods=["GET", "POST"])
|
|
def start():
|
|
if request.method == "POST":
|
|
name = request.form["name"].strip()
|
|
if not name:
|
|
name = "Unbekannter Fan"
|
|
|
|
db = get_db()
|
|
cursor = db.execute(
|
|
"INSERT INTO spieler (name, start_zeit, fertig_zeit) VALUES (?, ?, NULL)",
|
|
(name, time.time()),
|
|
)
|
|
spieler_id = cursor.lastrowid
|
|
db.commit()
|
|
db.close()
|
|
|
|
session["spieler_id"] = spieler_id
|
|
session["spieler_name"] = name
|
|
|
|
return seite_html(
|
|
"<h1>Eintrittskarte gelöst</h1>"
|
|
"<p>Willkommen, " + escape(name) + ". Dein Weg durchs Stadion beginnt.</p>"
|
|
'<a class="btn" href="/app/raum/stadiontor">Zum Stadiontor</a>'
|
|
)
|
|
|
|
return seite_html(
|
|
'<p class="tag">Escape Room im Stadiongang</p>'
|
|
"<h1>Glück Auf<br><span>im Stadion</span></h1>"
|
|
"<p>Trage deinen Namen auf der Eintrittskarte ein. Ab dann läuft deine Zeit.</p>"
|
|
'<form method="post">'
|
|
'<label for="name">Name auf der Eintrittskarte</label>'
|
|
'<input name="name" placeholder="Dein Name" autocomplete="off">'
|
|
"<button>Abenteuer starten</button>"
|
|
"</form>"
|
|
'<p><a class="btn secondary" href="/app/raum/stadiontor">Direkt zum Stadiontor</a></p>',
|
|
"scene",
|
|
)
|
|
|
|
|
|
@app.route("/raum/<raum_id>", methods=["GET", "POST"])
|
|
@app.route("/app/raum/<raum_id>", methods=["GET", "POST"])
|
|
def raum(raum_id):
|
|
db = get_db()
|
|
r = db.execute("SELECT * FROM raeume WHERE id=?", (raum_id,)).fetchone()
|
|
|
|
if r is None:
|
|
db.close()
|
|
return seite_html(
|
|
'<h1>Raum nicht gefunden</h1><a class="btn" href="/app/">Zurück zum Start</a>'
|
|
), 404
|
|
|
|
if r["raetsel_frage"]:
|
|
if request.method == "POST":
|
|
antwort = request.form["antwort"].strip().lower()
|
|
richtige_antwort = r["raetsel_antwort"].strip().lower()
|
|
db.close()
|
|
|
|
if antwort == richtige_antwort:
|
|
db = get_db()
|
|
spieler_id = session.get("spieler_id")
|
|
if spieler_id:
|
|
db.execute(
|
|
"UPDATE spieler SET fertig_zeit=? WHERE id=? AND fertig_zeit IS NULL",
|
|
(time.time(), spieler_id),
|
|
)
|
|
db.commit()
|
|
html = (
|
|
"<h1>Geschafft!</h1>"
|
|
"<p>Die Nordkurve feiert mit dir, "
|
|
+ escape(session.get("spieler_name", "Fan"))
|
|
+ ".</p>"
|
|
)
|
|
html += highscore_html(db)
|
|
db.close()
|
|
return seite_html(html)
|
|
return seite_html(
|
|
'<h1>Leider falsch</h1>'
|
|
'<p>Erwin schüttelt den Kopf. Die Botschaft stimmt noch nicht.</p>'
|
|
'<a class="btn" href="/app/raum/' + escape(raum_id) + '">Nochmal versuchen</a>'
|
|
)
|
|
|
|
html = "<h1>" + escape(r["name"]) + "</h1>"
|
|
html += "<p>" + escape(r["beschreibung"]) + "</p>"
|
|
html += '<form method="post">'
|
|
html += '<p class="clue">' + escape(r["raetsel_frage"]) + "</p>"
|
|
html += '<label for="antwort">Deine Antwort</label>'
|
|
html += '<input id="antwort" name="antwort" autocomplete="off">'
|
|
html += "<button>OK</button>"
|
|
html += "</form>"
|
|
db.close()
|
|
return seite_html(html)
|
|
|
|
ausgaenge = db.execute(
|
|
"SELECT richtung, nach_raum FROM ausgaenge WHERE von_raum=?",
|
|
(raum_id,),
|
|
).fetchall()
|
|
db.close()
|
|
|
|
html = "<h1>" + escape(r["name"]) + "</h1>"
|
|
html += "<p>" + escape(r["beschreibung"]) + "</p>"
|
|
for a in ausgaenge:
|
|
html += '<a class="btn" href="/app/raum/' + escape(a["nach_raum"]) + '">'
|
|
html += escape(a["richtung"])
|
|
html += "</a> "
|
|
|
|
return seite_html(html)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=9000)
|