diff --git a/client/src/pages/Game/states/Calculate/Calculate.jsx b/client/src/pages/Game/states/Calculate/Calculate.jsx index 9c29ae3..e11ef8a 100644 --- a/client/src/pages/Game/states/Calculate/Calculate.jsx +++ b/client/src/pages/Game/states/Calculate/Calculate.jsx @@ -2,11 +2,12 @@ import "./styles.sass"; import {GroupContext} from "@/common/contexts/GroupContext.jsx"; import {useContext, useEffect, useState} from "react"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; -import {faShoppingCart} from "@fortawesome/free-solid-svg-icons"; +import {faForward, faShoppingCart} from "@fortawesome/free-solid-svg-icons"; import InterfaceSound from "@/common/sounds/interface.mp3"; import Sound from "react-sound"; import {MusicContext} from "@/common/contexts/MusicContext.jsx"; import BeginSound from "@/common/sounds/begin.mp3"; +import Button from "@/common/components/Button"; const localeOptions = { style: "decimal", @@ -23,6 +24,7 @@ export const Calculate = ({setState}) => { const {musicEnabled} = useContext(MusicContext); const [nachfrage, setNachfrage] = useState(0); + const [showNewCapital, setShowNewCapital] = useState(false); const animateNext = () => { const current = round.shift(); @@ -33,7 +35,8 @@ export const Calculate = ({setState}) => { let profit = sold * current.price - (current.amount * 1000 + 4000); - setAnimatedGroups(old => [...old, {...current, profit, name: getGroupById(current.id).name}]); + setAnimatedGroups(old => [...old, {...current, profit, name: getGroupById(current.id).name, sold, + newCapital: getGroupById(current.id).capital + profit}]); updateCapital(current.id, getGroupById(current.id).capital + profit); } @@ -41,7 +44,6 @@ export const Calculate = ({setState}) => { useEffect(() => { if (round.length === 0) { endRound(); - setTimeout(() => setState("waiting"), 8000); return; } @@ -52,10 +54,25 @@ export const Calculate = ({setState}) => { return () => clearTimeout(timeout); }, [animatedGroups]); + useEffect(() => { + if (animatedGroups.length === 0) return; + + const timeout = setTimeout(() => { + setShowNewCapital(true); + }, 3000); + + return () => clearTimeout(timeout); + }, [round]); + useEffect(() => { let avg = 0; - round.forEach(r => avg += r.price); - avg /= round.length; + let amount = 0; + round.forEach(r => { + avg += r.price * r.amount; + amount += parseInt(r.amount); + }); + + avg /= amount; setNachfrage(avg < 1800 ? 50 : avg > 2200 ? 30 : 40); setAnimatedGroups([]); @@ -64,49 +81,65 @@ export const Calculate = ({setState}) => { return (
Unternehmen
-Unternehmen
+Absatzpreis
-Absatzpreis
+Menge
-Menge
+Gewinn/Verlust
- {r.profit > 0 &&Verkauft
+Gewinn/Verlust
+ {r.profit > 0 &&Kapital + {r.profit > 0 && + {r.profit?.toLocaleString("de-DE", localeOptions)} €} + {r.profit < 0 && - {r.profit?.toLocaleString("de-DE", localeOptions)} €} + {r.profit === 0 && (Unverändert)} +
+Nachfrage
-Nachfrage
+