diff --git a/front/src/components/3d/Marker.tsx b/front/src/components/3d/Marker.tsx index 3509e53..893f4f1 100644 --- a/front/src/components/3d/Marker.tsx +++ b/front/src/components/3d/Marker.tsx @@ -10,12 +10,12 @@ interface MarkerProps { export default function Marker({ position, color, onClick }: MarkerProps) { + const [positionState, setPositionState] = React.useState(position) - // Return the marker object // return return ( - + setPositionState([positionState[0], positionState[1], positionState[2] + 0.1])} onPointerOut={(e) => setPositionState(position)}> diff --git a/front/src/components/Modal.tsx b/front/src/components/Modal.tsx index e69de29..083699f 100644 --- a/front/src/components/Modal.tsx +++ b/front/src/components/Modal.tsx @@ -0,0 +1,78 @@ +import React, { useState } from "react"; + +interface ModalProps { + state: "none" | "flex", + setState: (state: "none" | "flex") => void + question : { + question: string, + reponse_idx: number, + choix: string[] + }, + valides?: [boolean[], React.Dispatch>], + markerIndex?: number +} + +export default function Modal({ state, setState, question, valides, markerIndex }: ModalProps) { + const [isSuccess, setIsSuccess] = useState(false); + const [isSubmitted, setIsSubmitted] = useState(false); + console.log(state, setState, question) + return ( +
+
+ { + isSuccess ?

CONGRATULATIONS

: isSubmitted && !isSuccess &&

WRONG : CORRECT ANSWER IS {question.choix[question.reponse_idx]}

+ } +

{question.question}

+
+ { + question.choix.map((choix, index) => ( + + )) + } +
+ +
+
+
+ + )} \ No newline at end of file diff --git a/front/src/pages/GamePage.tsx b/front/src/pages/GamePage.tsx index c7c3d04..69552df 100644 --- a/front/src/pages/GamePage.tsx +++ b/front/src/pages/GamePage.tsx @@ -1,25 +1,97 @@ import { Canvas } from "@react-three/fiber"; -import { OrbitControls, Sky } from "@react-three/drei"; +import { OrbitControls, PerspectiveCamera, Sky } from "@react-three/drei"; import * as THREE from "three"; -import { useEffect, useRef } from "react"; +import React, { useEffect, useRef, useState } from "react"; import Ocean from "../components/3d/Ocean"; import Axes from "../components/3d/Axes"; import Character from "../components/3d/Character"; import Floor from "../components/3d/Floor"; import Marker from "../components/3d/Marker"; +import Modal from "../components/Modal"; +import { randInt } from "three/src/math/MathUtils.js"; + + + + + + + -const MakerList = [ - { position: [0, 0.1, 0], color: "red", onClick: () => console.log("red") }, // body - { position: [-0.5, 0.1, 2.5], color: "green", onClick: () => console.log("green") }, // left foot - { position: [0.5, 0.1, 2.5], color: "blue", onClick: () => console.log("blue") }, // right foot - { position: [-1, 0.1, 1], color: "yellow", onClick: () => console.log("yellow") }, // left hand - { position: [1, 0.1, 1], color: "purple", onClick: () => console.log("purple") }, // right hand - { position: [0, 0.1, -1], color: "orange", onClick: () => console.log("orange") }, // head -] export default function GamePage() { + const [stateModal, setStateModal] = useState("none" as "none" | "flex"); + const [questionIndex, setQuestionIndex] = useState(0); + + const QuestionList = [ + // Ensemble de questions sur la polution des océans + // {question:string, reponse_idx:int, choix:[string, string, string, string]} + { + question: "Quel est le plus grand océan du monde ?", + reponse_idx: 1, + choix: ["Océan Atlantique", "Océan Pacifique", "Océan Indien", "Océan Arctique"] + }, + { + question: "Comment s'appelle les continents de plastique dans les océans ?", + reponse_idx: 2, + choix: ["Plastico", "Plastiland", "Plastiques", "Plastiques"] + }, + { + question: "Quel est le nom de la grande masse d'eau salée qui recouvre la majorité de la surface de la Terre ?", + reponse_idx: 3, + choix: ["Mer", "Lac", "Océan", "Rivière"] + }, + { + question: "Quel est l'océan le plus froid ?", + reponse_idx: 0, + choix: ["Océan Arctique", "Océan Antarctique", "Océan Pacifique", "Océan Atlantique"] + }, + { + question: "Quel est l'océan le plus chaud ?", + reponse_idx: 1, + choix: ["Océan Arctique", "Océan Antarctique", "Océan Pacifique", "Océan Atlantique"] + }, + { + question: "Quel est l'océan le plus profond ?", + reponse_idx: 1, + choix: ["Océan Arctique", "Océan Antarctique", "Océan Pacifique", "Océan Atlantique"] + }, + { + question: "Quel est l'océan le plus grand ?", + reponse_idx: 2, + choix: ["Océan Arctique", "Océan Antarctique", "Océan Pacifique", "Océan Atlantique"] + } + ] + + + const [valides, setValides] = useState([false, false, false, false, false, false]); + const [markerIndex, setMarkerIndex] = useState(0); + + const askQuestion = (markerIndex: number) => { + setQuestionIndex(randInt(0, QuestionList.length - 1)); + setStateModal("flex"); + setMarkerIndex(markerIndex); + } + + const MakerList = [ + { position: [0, -0.1, 0], onClick: () => askQuestion(0) }, // body + { position: [-0.5, -0.1, 2.5], onClick: () => askQuestion(1) }, // left foot + { position: [0.5, -0.1, 2.5], onClick: () => askQuestion(2) }, // right foot + { position: [-1, -0.1, 1], onClick: () => askQuestion(3) }, // left hand + { position: [1, -0.1, 1], onClick: () => askQuestion(4) }, // right hand + { position: [0, -0.1, -1], onClick: () => askQuestion(5) }, // head + ] + + // Win condition + useEffect(() => { + if (valides.every(valide => valide)) { + + } + }, [valides]) + + + console.log(stateModal, setStateModal); return (
+ { !valides.every(valide => valide) === true ? +

Hint : Répondez correctement aux questions pour sauver le personnage

+ :

Good Game : Bravo, vous avez sauvé le personnage

+ } @@ -40,10 +144,11 @@ export default function GamePage() { {/* */} {MakerList.map((marker, index) => ( - + ))} - + +
) } \ No newline at end of file