Modern UI

This commit is contained in:
2026-02-09 22:19:13 +01:00
parent a917d0d2aa
commit e2f134d3b4

View File

@@ -3,113 +3,199 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Wolf & Schafe - Multiplayer</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Wolf & Schafe</title>
<style> <style>
:root {
--bg: #f8fafc;
--card-bg: #ffffff;
--wolf-color: #ef4444;
--sheep-color: #3b82f6;
--empty-color: #f1f5f9;
--border-color: #e2e8f0;
--text-main: #1e293b;
--text-sub: #64748b;
--accent: #f59e0b;
}
body { body {
font-family: 'Segoe UI', Arial, sans-serif; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
background: #f0f2f5; background-color: var(--bg);
color: var(--text-main);
margin: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
touch-action: manipulation;
}
.game-card {
background: var(--card-bg);
width: 95%;
max-width: 600px;
padding: 1.5rem;
border-radius: 16px;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
border: 1px solid var(--border-color);
text-align: center; text-align: center;
} }
header {
margin-bottom: 1rem;
}
h2 {
margin: 0;
font-size: 1.1rem;
color: var(--text-sub);
font-weight: 500;
}
#status { #status {
font-size: 20px; font-size: 1.25rem;
font-weight: bold; font-weight: 700;
margin: 15px; margin: 0.5rem 0;
min-height: 50px; min-height: 3rem;
line-height: 1.2;
}
.board-container {
width: 100%;
aspect-ratio: 600 / 420;
position: relative;
} }
svg { svg {
background: white; width: 100%;
border-radius: 8px; height: 100%;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
display: block; display: block;
margin: auto;
} }
.node { /* SVG Elements */
cursor: pointer; .edge {
stroke: #333; stroke: var(--border-color);
stroke-width: 2; stroke-width: 3;
transition: all 0.2s; stroke-linecap: round;
}
.node-circle {
transition: r 0.2s ease, stroke-width 0.2s ease;
stroke: var(--border-color);
stroke-width: 1.5;
} }
.empty { .empty {
fill: #ecf0f1; fill: var(--empty-color);
} }
.sheep { .sheep {
fill: #3498db; fill: var(--sheep-color);
stroke: rgba(0, 0, 0, 0.1);
} }
.wolf { .wolf {
fill: #e74c3c; fill: var(--wolf-color);
stroke: rgba(0, 0, 0, 0.1);
} }
.selected { .selected {
stroke: #f1c40f; stroke: var(--accent);
stroke-width: 6; stroke-width: 5;
} }
.possible { .possible {
stroke: #2ecc71; fill: #dcfce7;
stroke-width: 5; stroke: #22c55e;
stroke-dasharray: 5; stroke-dasharray: 4;
r: 20;
/* Slightly smaller for indicator */
} }
text { /* Responsive Controls */
pointer-events: none; .controls {
user-select: none; margin-top: 1.5rem;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
} }
button { button {
margin: 10px; padding: 12px;
padding: 10px 20px; border-radius: 10px;
font-size: 14px; border: 1px solid var(--border-color);
background: white;
color: var(--text-main);
font-weight: 600;
cursor: pointer; cursor: pointer;
border: none; font-size: 0.9rem;
border-radius: 4px; display: flex;
background: #2c3e50; align-items: center;
color: white; justify-content: center;
gap: 6px;
} }
button:hover { button:active {
background: #34495e; background: #f1f5f9;
transform: scale(0.98);
} }
#exitBtn { #exitBtn {
background: #e74c3c; grid-column: span 2;
background: #fff1f2;
color: #be123c;
border-color: #fecdd3;
} }
#exitBtn:hover { #copyRoomBtn {
background: #c0392b; background: #f0f9ff;
color: #0369a1;
border-color: #bae6fd;
}
@media (max-width: 480px) {
.game-card {
padding: 1rem;
border-radius: 0;
width: 100%;
min-height: 100vh;
border: none;
}
#status {
font-size: 1.1rem;
}
} }
</style> </style>
</head> </head>
<body> <body>
<h2 id="roleHeader">Verbinde...</h2> <div class="game-card">
<div id="status">Warte auf Mitspieler...</div> <header>
<svg width="600" height="420"></svg> <h2 id="roleHeader">Verbinde...</h2>
<br> <div id="status">Warte auf Mitspieler...</div>
<button id="restartBtn">🔄 Neustart</button> </header>
<button id="copyRoomBtn">📋 Link kopieren</button>
<button id="exitBtn">🚪 Raum verlassen</button> <div class="board-container">
<svg viewBox="0 0 600 420" preserveAspectRatio="xMidYMid meet"></svg>
</div>
<div class="controls">
<button id="copyRoomBtn">📋 Link</button>
<button id="restartBtn">🔄 Reset</button>
<button id="exitBtn">🚪 Raum verlassen</button>
</div>
</div>
<script> <script>
// Session Management // Session and Room Setup
let sessionId = localStorage.getItem("game_session_id"); let sessionId = localStorage.getItem("game_session_id") || (Math.random().toString(36).substring(2) + Date.now().toString(36));
if (!sessionId) { localStorage.setItem("game_session_id", sessionId);
sessionId = Math.random().toString(36).substring(2) + Date.now().toString(36);
localStorage.setItem("game_session_id", sessionId);
}
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
let roomId = params.get("room"); let roomId = params.get("room");
if (!roomId) roomId = prompt("Raumcode eingeben (leer für neu):") || "";
if (!roomId) {
roomId = prompt("Raumcode eingeben (leer für neuen Raum):") || "";
}
const protocol = location.protocol === "https:" ? "wss" : "ws"; const protocol = location.protocol === "https:" ? "wss" : "ws";
const ws = new WebSocket(`${protocol}://${location.host}?room=${roomId}&sessionId=${sessionId}`); const ws = new WebSocket(`${protocol}://${location.host}?room=${roomId}&sessionId=${sessionId}`);
@@ -119,7 +205,7 @@
const board_wolf = { 0: [1, 2, 3], 1: [0, 2, 4, 5], 2: [0, 1, 3, 5], 3: [0, 2, 5, 6], 4: [1, 5, 7], 5: [1, 2, 3, 4, 6, 7, 8, 9], 6: [3, 5, 9], 7: [4, 5, 8, 10], 8: [5, 7, 9, 10], 9: [5, 6, 8, 10], 10: [7, 8, 9] }; const board_wolf = { 0: [1, 2, 3], 1: [0, 2, 4, 5], 2: [0, 1, 3, 5], 3: [0, 2, 5, 6], 4: [1, 5, 7], 5: [1, 2, 3, 4, 6, 7, 8, 9], 6: [3, 5, 9], 7: [4, 5, 8, 10], 8: [5, 7, 9, 10], 9: [5, 6, 8, 10], 10: [7, 8, 9] };
const board_sheep = { 0: [1, 2, 3], 1: [2, 4, 5], 2: [1, 3, 5], 3: [2, 5, 6], 4: [5, 7], 5: [4, 6, 7, 8, 9], 6: [5, 9], 7: [8, 10], 8: [7, 9, 10], 9: [8, 10], 10: [] }; const board_sheep = { 0: [1, 2, 3], 1: [2, 4, 5], 2: [1, 3, 5], 3: [2, 5, 6], 4: [5, 7], 5: [4, 6, 7, 8, 9], 6: [5, 9], 7: [8, 10], 8: [7, 9, 10], 9: [8, 10], 10: [] };
const pos = { 0: [100, 210], 1: [200, 110], 2: [200, 210], 3: [200, 310], 4: [300, 110], 5: [300, 210], 6: [300, 310], 7: [400, 110], 8: [400, 210], 9: [400, 310], 10: [500, 210] }; const pos = { 0: [80, 210], 1: [180, 110], 2: [180, 210], 3: [180, 310], 4: [280, 110], 5: [280, 210], 6: [280, 310], 7: [380, 110], 8: [380, 210], 9: [380, 310], 10: [480, 210] };
const edges = [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3], [1, 4], [2, 5], [3, 6], [4, 5], [5, 6], [4, 7], [5, 8], [6, 9], [7, 8], [8, 9], [5, 1], [5, 3], [5, 7], [5, 9], [7, 10], [8, 10], [9, 10]]; const edges = [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3], [1, 4], [2, 5], [3, 6], [4, 5], [5, 6], [4, 7], [5, 8], [6, 9], [7, 8], [8, 9], [5, 1], [5, 3], [5, 7], [5, 9], [7, 10], [8, 10], [9, 10]];
ws.onmessage = e => { ws.onmessage = e => {
@@ -127,31 +213,30 @@
if (msg.type === "role") { if (msg.type === "role") {
myRole = msg.role; myRole = msg.role;
currentRoomId = msg.roomId; currentRoomId = msg.roomId;
document.getElementById("roleHeader").innerText = `Du bist: ${myRole.toUpperCase()} | Raum: ${currentRoomId}`; document.getElementById("roleHeader").innerText = `${myRole.toUpperCase()} RAUM ${currentRoomId}`;
if (!params.has("room")) { if (!params.has("room")) window.history.replaceState({}, '', `?room=${currentRoomId}`);
window.history.replaceState({}, '', `?room=${currentRoomId}`);
}
} }
if (msg.type === "state") { state = msg.game; render(); } if (msg.type === "state") { state = msg.game; render(); }
if (msg.type === "full") alert("Dieser Raum ist leider voll!");
}; };
function render() { function render() {
if (!state) return; if (!state) return;
svg.innerHTML = ""; svg.innerHTML = "";
const statusEl = document.getElementById("status"); const statusEl = document.getElementById("status");
if (state.winner) { if (state.winner) {
statusEl.innerHTML = `<span style="color:${state.winner === myRole ? 'green' : 'red'}">SPIEL ENDE: ${state.winner.toUpperCase()} GEWINNT!</span>`; const winColor = state.winner === myRole ? "#059669" : "#dc2626";
statusEl.innerHTML = `<span style="color:${winColor}">${state.winner === myRole ? '🏆 Sieg!' : 'Spiel beendet'}</span>`;
} else { } else {
const turnText = state.turn === myRole ? "🟢 Dein Zug" : "⏳ Gegner zieht..."; const turnText = state.turn === myRole ? `<span style="color:var(--text-main)">Du bist dran</span>` : `<span style="color:var(--text-sub)">Gegner zieht...</span>`;
statusEl.innerHTML = `${turnText}<br><small>Zug: ${state.moveCount} / 40</small>`; statusEl.innerHTML = `${turnText}<br><small style="font-weight:400; font-size: 0.8rem; color: var(--text-sub)">Zug ${state.moveCount}/40</small>`;
} }
edges.forEach(([a, b]) => { edges.forEach(([a, b]) => {
const [x1, y1] = pos[a], [x2, y2] = pos[b];
const line = document.createElementNS("http://www.w3.org/2000/svg", "line"); const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
line.setAttribute("x1", x1); line.setAttribute("y1", y1); line.setAttribute("x2", x2); line.setAttribute("y2", y2); line.setAttribute("x1", pos[a][0]); line.setAttribute("y1", pos[a][1]);
line.setAttribute("stroke", "#bdc3c7"); line.setAttribute("stroke-width", "3"); line.setAttribute("x2", pos[b][0]); line.setAttribute("y2", pos[b][1]);
line.setAttribute("class", "edge");
svg.appendChild(line); svg.appendChild(line);
}); });
@@ -165,18 +250,26 @@
(myRole === "wolf" ? board_wolf[selected] : board_sheep[selected]).includes(i) && (myRole === "wolf" ? board_wolf[selected] : board_sheep[selected]).includes(i) &&
state.wolf !== i && !state.sheep.includes(i); state.wolf !== i && !state.sheep.includes(i);
const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
group.onclick = () => handleClick(i);
const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle"); const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circle.setAttribute("cx", x); circle.setAttribute("cy", y); circle.setAttribute("r", 25); circle.setAttribute("cx", x); circle.setAttribute("cy", y); circle.setAttribute("r", 25);
circle.setAttribute("class", `node ${type} ${selected === i ? 'selected' : ''} ${isPossible ? 'possible' : ''}`); circle.setAttribute("class", `node-circle ${type} ${selected === i ? 'selected' : ''} ${isPossible ? 'possible' : ''}`);
circle.onclick = () => handleClick(i);
svg.appendChild(circle);
const txt = document.createElementNS("http://www.w3.org/2000/svg", "text"); group.appendChild(circle);
txt.setAttribute("x", x); txt.setAttribute("y", y + 5);
txt.setAttribute("text-anchor", "middle"); if (type !== "empty") {
txt.setAttribute("fill", type === "empty" ? "#7f8c8d" : "white"); const txt = document.createElementNS("http://www.w3.org/2000/svg", "text");
txt.textContent = i; txt.setAttribute("x", x); txt.setAttribute("y", y + 6);
svg.appendChild(txt); txt.setAttribute("text-anchor", "middle");
txt.setAttribute("fill", "white");
txt.setAttribute("font-weight", "bold");
txt.textContent = type === "wolf" ? "W" : "S";
group.appendChild(txt);
}
svg.appendChild(group);
} }
} }
@@ -198,11 +291,10 @@
document.getElementById("restartBtn").onclick = () => ws.send(JSON.stringify({ type: "restart" })); document.getElementById("restartBtn").onclick = () => ws.send(JSON.stringify({ type: "restart" }));
document.getElementById("copyRoomBtn").onclick = () => { document.getElementById("copyRoomBtn").onclick = () => {
const url = `${location.origin}${location.pathname}?room=${currentRoomId}`; navigator.clipboard.writeText(window.location.href).then(() => alert("Link kopiert!"));
navigator.clipboard.writeText(url).then(() => alert("Link kopiert!"));
}; };
document.getElementById("exitBtn").onclick = () => { document.getElementById("exitBtn").onclick = () => {
if (confirm("Möchtest du den Raum verlassen?")) { if (confirm("Raum verlassen?")) {
ws.send(JSON.stringify({ type: "leave" })); ws.send(JSON.stringify({ type: "leave" }));
window.location.href = window.location.pathname; window.location.href = window.location.pathname;
} }