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>
<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>
: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 {
font-family: 'Segoe UI', Arial, sans-serif;
background: #f0f2f5;
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
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;
}
header {
margin-bottom: 1rem;
}
h2 {
margin: 0;
font-size: 1.1rem;
color: var(--text-sub);
font-weight: 500;
}
#status {
font-size: 20px;
font-weight: bold;
margin: 15px;
min-height: 50px;
font-size: 1.25rem;
font-weight: 700;
margin: 0.5rem 0;
min-height: 3rem;
line-height: 1.2;
}
.board-container {
width: 100%;
aspect-ratio: 600 / 420;
position: relative;
}
svg {
background: white;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 100%;
height: 100%;
display: block;
margin: auto;
}
.node {
cursor: pointer;
stroke: #333;
stroke-width: 2;
transition: all 0.2s;
/* SVG Elements */
.edge {
stroke: var(--border-color);
stroke-width: 3;
stroke-linecap: round;
}
.node-circle {
transition: r 0.2s ease, stroke-width 0.2s ease;
stroke: var(--border-color);
stroke-width: 1.5;
}
.empty {
fill: #ecf0f1;
fill: var(--empty-color);
}
.sheep {
fill: #3498db;
fill: var(--sheep-color);
stroke: rgba(0, 0, 0, 0.1);
}
.wolf {
fill: #e74c3c;
fill: var(--wolf-color);
stroke: rgba(0, 0, 0, 0.1);
}
.selected {
stroke: #f1c40f;
stroke-width: 6;
stroke: var(--accent);
stroke-width: 5;
}
.possible {
stroke: #2ecc71;
stroke-width: 5;
stroke-dasharray: 5;
fill: #dcfce7;
stroke: #22c55e;
stroke-dasharray: 4;
r: 20;
/* Slightly smaller for indicator */
}
text {
pointer-events: none;
user-select: none;
/* Responsive Controls */
.controls {
margin-top: 1.5rem;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
}
button {
margin: 10px;
padding: 10px 20px;
font-size: 14px;
padding: 12px;
border-radius: 10px;
border: 1px solid var(--border-color);
background: white;
color: var(--text-main);
font-weight: 600;
cursor: pointer;
border: none;
border-radius: 4px;
background: #2c3e50;
color: white;
font-size: 0.9rem;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
button:hover {
background: #34495e;
button:active {
background: #f1f5f9;
transform: scale(0.98);
}
#exitBtn {
background: #e74c3c;
grid-column: span 2;
background: #fff1f2;
color: #be123c;
border-color: #fecdd3;
}
#exitBtn:hover {
background: #c0392b;
#copyRoomBtn {
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>
</head>
<body>
<h2 id="roleHeader">Verbinde...</h2>
<div id="status">Warte auf Mitspieler...</div>
<svg width="600" height="420"></svg>
<br>
<button id="restartBtn">🔄 Neustart</button>
<button id="copyRoomBtn">📋 Link kopieren</button>
<button id="exitBtn">🚪 Raum verlassen</button>
<div class="game-card">
<header>
<h2 id="roleHeader">Verbinde...</h2>
<div id="status">Warte auf Mitspieler...</div>
</header>
<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>
// Session Management
let sessionId = localStorage.getItem("game_session_id");
if (!sessionId) {
sessionId = Math.random().toString(36).substring(2) + Date.now().toString(36);
localStorage.setItem("game_session_id", sessionId);
}
// Session and Room Setup
let sessionId = localStorage.getItem("game_session_id") || (Math.random().toString(36).substring(2) + Date.now().toString(36));
localStorage.setItem("game_session_id", sessionId);
const params = new URLSearchParams(window.location.search);
let roomId = params.get("room");
if (!roomId) {
roomId = prompt("Raumcode eingeben (leer für neuen Raum):") || "";
}
if (!roomId) roomId = prompt("Raumcode eingeben (leer für neu):") || "";
const protocol = location.protocol === "https:" ? "wss" : "ws";
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_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]];
ws.onmessage = e => {
@@ -127,31 +213,30 @@
if (msg.type === "role") {
myRole = msg.role;
currentRoomId = msg.roomId;
document.getElementById("roleHeader").innerText = `Du bist: ${myRole.toUpperCase()} | Raum: ${currentRoomId}`;
if (!params.has("room")) {
window.history.replaceState({}, '', `?room=${currentRoomId}`);
}
document.getElementById("roleHeader").innerText = `${myRole.toUpperCase()} RAUM ${currentRoomId}`;
if (!params.has("room")) window.history.replaceState({}, '', `?room=${currentRoomId}`);
}
if (msg.type === "state") { state = msg.game; render(); }
if (msg.type === "full") alert("Dieser Raum ist leider voll!");
};
function render() {
if (!state) return;
svg.innerHTML = "";
const statusEl = document.getElementById("status");
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 {
const turnText = state.turn === myRole ? "🟢 Dein Zug" : "⏳ Gegner zieht...";
statusEl.innerHTML = `${turnText}<br><small>Zug: ${state.moveCount} / 40</small>`;
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 style="font-weight:400; font-size: 0.8rem; color: var(--text-sub)">Zug ${state.moveCount}/40</small>`;
}
edges.forEach(([a, b]) => {
const [x1, y1] = pos[a], [x2, y2] = pos[b];
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("stroke", "#bdc3c7"); line.setAttribute("stroke-width", "3");
line.setAttribute("x1", pos[a][0]); line.setAttribute("y1", pos[a][1]);
line.setAttribute("x2", pos[b][0]); line.setAttribute("y2", pos[b][1]);
line.setAttribute("class", "edge");
svg.appendChild(line);
});
@@ -165,18 +250,26 @@
(myRole === "wolf" ? board_wolf[selected] : board_sheep[selected]).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");
circle.setAttribute("cx", x); circle.setAttribute("cy", y); circle.setAttribute("r", 25);
circle.setAttribute("class", `node ${type} ${selected === i ? 'selected' : ''} ${isPossible ? 'possible' : ''}`);
circle.onclick = () => handleClick(i);
svg.appendChild(circle);
circle.setAttribute("class", `node-circle ${type} ${selected === i ? 'selected' : ''} ${isPossible ? 'possible' : ''}`);
const txt = document.createElementNS("http://www.w3.org/2000/svg", "text");
txt.setAttribute("x", x); txt.setAttribute("y", y + 5);
txt.setAttribute("text-anchor", "middle");
txt.setAttribute("fill", type === "empty" ? "#7f8c8d" : "white");
txt.textContent = i;
svg.appendChild(txt);
group.appendChild(circle);
if (type !== "empty") {
const txt = document.createElementNS("http://www.w3.org/2000/svg", "text");
txt.setAttribute("x", x); txt.setAttribute("y", y + 6);
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("copyRoomBtn").onclick = () => {
const url = `${location.origin}${location.pathname}?room=${currentRoomId}`;
navigator.clipboard.writeText(url).then(() => alert("Link kopiert!"));
navigator.clipboard.writeText(window.location.href).then(() => alert("Link kopiert!"));
};
document.getElementById("exitBtn").onclick = () => {
if (confirm("Möchtest du den Raum verlassen?")) {
if (confirm("Raum verlassen?")) {
ws.send(JSON.stringify({ type: "leave" }));
window.location.href = window.location.pathname;
}