From 79a5a213d610828fe85836533631e467f86b6db4 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Tue, 13 Feb 2024 19:26:25 +0100 Subject: [PATCH] introducing the component --- src/components/game/GameObjects.jsx | 43 +++++++++++++++++++++ src/components/game/GameQuestion.jsx | 41 ++++++++++++++++++++ src/components/game/Score.jsx | 57 ++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 src/components/game/GameObjects.jsx create mode 100644 src/components/game/GameQuestion.jsx create mode 100644 src/components/game/Score.jsx diff --git a/src/components/game/GameObjects.jsx b/src/components/game/GameObjects.jsx new file mode 100644 index 0000000..98f9ed2 --- /dev/null +++ b/src/components/game/GameObjects.jsx @@ -0,0 +1,43 @@ +import React from "react"; +import GameQuestion from "./GameQuestion"; +import { useGame } from "../../hooks/useGame"; + +export default function GameObjects({ blocks }) { + const { setCurrentGameModal, answers } = useGame(); + + if (!blocks) return null; + + return ( + <> + {blocks.map((block, id) => { + const hasAnswered = answers && answers[id]?.userAnswer; + return ( + {block.attrs.objectPictureAlt} console.log(block.attrs.objectBehaviourDescription)} + // onClick={() => console.log(block.attrs.objectBehaviourDescription)} + onClick={() => + setCurrentGameModal( + + ) + } + /> + ); + })} + + ); +} diff --git a/src/components/game/GameQuestion.jsx b/src/components/game/GameQuestion.jsx new file mode 100644 index 0000000..a3f5b53 --- /dev/null +++ b/src/components/game/GameQuestion.jsx @@ -0,0 +1,41 @@ +import React from "react"; +import anwserIconSafe from "../../assets/img/icons/anwser_icon_safe.svg"; +import anwserIconUnsafe from "../../assets/img/icons/anwser_icon_unsafe.svg"; + +import { useGame } from "../../hooks/useGame"; +export default function GameQuestion({ questionId, correctAnswer }, ...props) { + const { answerQuestion, contextGameDatas } = useGame(); + const objectPictureUrl = contextGameDatas.gameObjects[questionId].attrs.objectPictureUrl; + + function handleAnswer(questionId, answer) { + answerQuestion(questionId, answer); + } + + return ( +
+ {correctAnswer} +
+

Trouvé !

+

securisé ou risqué ?

+ +

+ Est-ce que la situation comporte un risque majeur ou identifiez vous un bon + comportement ? +

+
+ + +
+
+ +
+ ); +} diff --git a/src/components/game/Score.jsx b/src/components/game/Score.jsx new file mode 100644 index 0000000..bb48bbe --- /dev/null +++ b/src/components/game/Score.jsx @@ -0,0 +1,57 @@ +import React from "react"; +import { useGame } from "../../hooks/useGame"; +import anwserIconSafe from "../../assets/img/icons/anwser_icon_safe.svg"; +import anwserIconUnsafe from "../../assets/img/icons/anwser_icon_unsafe.svg"; +import sucessIcon from "../../assets/img/icons/behaviour-type-success.svg"; +import errorIcon from "../../assets/img/icons/behaviour-type-error.svg"; + +export default function Score() { + let { answers } = useGame(); + if (!answers) return; + return ( +
+
    + {answers.map((answer, key) => { + const answerType = !answer.userAnswer + ? "unanswered" + : answer.correctAnswer === answer.userAnswer + ? "correct" + : "incorrect"; + return ( +
  • + {answer.userAnsweredCorrectly === true && ( + + )} + {answer.userAnsweredCorrectly === false && ( + + )} + + {answer.userAnswer && answer.correctAnswer === "safe" && ( + + )} + {answer.userAnswer && answer.correctAnswer === "unsafe" && ( + + )} +
  • + ); + })} +
+
+ ); +}