diff --git a/package.json b/package.json index 662ec83..797808b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "@formkit/auto-animate": "^1.0.0-beta.1", "@fortawesome/fontawesome-free": "^5.15.4", "@lingdocs/lingdocs-main": "^0.3.1", - "@lingdocs/pashto-inflector": "^2.6.6", + "@lingdocs/pashto-inflector": "^2.6.7", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", diff --git a/src/games/GameCore.tsx b/src/games/GameCore.tsx index 03c3d5c..05256c5 100644 --- a/src/games/GameCore.tsx +++ b/src/games/GameCore.tsx @@ -22,6 +22,8 @@ import ReactGA from "react-ga"; import { isProd } from "../lib/isProd"; const errorVibration = 200; +const maxStrikes = 2; + function GameCore({ questions, Display, timeLimit, Instructions, studyLink, id }:{ id: string, studyLink: string, @@ -34,6 +36,8 @@ function GameCore({ questions, Display, timeLimit, Instructions, studyLink, i const rewardRef = useRef(null); const { user, pullUser, setUser } = useUser(); const [finish, setFinish] = useState(undefined); + const [strikes, setStrikes] = useState(0); + const [justStruck, setJustStruck] = useState(false); const [current, setCurrent] = useState | undefined>(undefined); const [questionBox, setQuestionBox] = useState>(questions()); const [timerKey, setTimerKey] = useState(1); @@ -50,13 +54,18 @@ function GameCore({ questions, Display, timeLimit, Instructions, studyLink, i function handleCallback(correct: true | JSX.Element) { if (correct === true) handleAdvance(); - else { + else if (strikes < maxStrikes) { + navigator.vibrate(errorVibration); + setStrikes(s => s + 1); + setJustStruck(false); + } else { logGameEvent("fail on game"); setFinish({ msg: "fail", answer: correct }); navigator.vibrate(errorVibration); } } function handleAdvance() { + setJustStruck(false); const next = questionBox.next(); if (next.done) handleFinish(); else setCurrent(next.value); @@ -130,6 +139,7 @@ function GameCore({ questions, Display, timeLimit, Instructions, studyLink, i
+
Strikes: {strikes}
{current &&
({ questions, Display, timeLimit, Instructions, studyLink, i />
} +
OOPS, NOT QUITE - TRY AGAIN
{finish === undefined &&