diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index b0ab987..b9e6611 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -544,16 +544,47 @@ export default function App() { // App.jsx (füge diese Komponente irgendwo unter deinen anderen Komponenten ein) // ✅ 3 Würfel: 2x d6 + 1x Spezial (Häuser + Hilfkarte + Dunkles Deck) -const DicePanel = () => { +const DicePanel = ({ onRoll }) => { + const [d1, setD1] = useState(4); + const [d2, setD2] = useState(2); + const [special, setSpecial] = useState("gryffindor"); + const [rolling, setRolling] = useState(false); + + const specialFaces = ["gryffindor", "slytherin", "ravenclaw", "hufflepuff", "help", "dark"]; + + const randInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; + + const rollAll = () => { + if (rolling) return; + setRolling(true); + + // Während der Animation kurz "flackern" lassen (optional, wirkt lebendiger) + const flickerId = setInterval(() => { + setD1(randInt(1, 6)); + setD2(randInt(1, 6)); + setSpecial(specialFaces[randInt(0, specialFaces.length - 1)]); + }, 90); + + // Finales Ergebnis nach Animation + setTimeout(() => { + clearInterval(flickerId); + + const nd1 = randInt(1, 6); + const nd2 = randInt(1, 6); + const ns = specialFaces[randInt(0, specialFaces.length - 1)]; + + setD1(nd1); + setD2(nd2); + setSpecial(ns); + + setRolling(false); + + onRoll?.({ d1: nd1, d2: nd2, special: ns }); + }, 820); // muss zur CSS Animation passen + }; + return ( -