repository to manage all files for 1_2_oder_3 interaction game for Inf2/2 Interaktionen SoSe23 from Engert, Caliskan and Bachiri
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Buttons.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React, {useState} from "react";
  2. import StartButton from "./StartButton";
  3. import QuitButton from "./QuitButton";
  4. import TeamSizePopUp from "./TeamsizePopUp";
  5. import {getReset, getScoreboard} from "./api";
  6. function Buttons({startQuestion, timerRunning, stopTimer, setQuestionCount, setTeamSize, setScoreBlue, setScoreGreen, setScoreRed,
  7. setAns1, setAns2, setAns3, setQuestion}) {
  8. const [gameStarted, setGameStarted] = useState(false)
  9. const [openPopUp, setOpenPopUp] = useState(false)
  10. const [quitvisible, setQuitvisible] = useState(false)
  11. const changeGame = (bool) => {
  12. setGameStarted(bool)
  13. setQuitvisible(bool)
  14. }
  15. const startClicked = () => {
  16. if(!timerRunning && !gameStarted) {
  17. setOpenPopUp(true);
  18. }
  19. else if (!timerRunning && gameStarted) {
  20. startQuestion();
  21. }
  22. }
  23. const quitGame = () => {
  24. changeGame(false);
  25. stopTimer();
  26. setQuestionCount(0);
  27. getReset(setAns1, setAns2, setAns3, setQuestion);
  28. alert("Spiel abgebrochen !");
  29. getScoreboard(setScoreBlue, setScoreGreen, setScoreRed);
  30. }
  31. return(
  32. <div className="Buttons">
  33. <StartButton
  34. onClick={startClicked}
  35. content={(gameStarted) ? "Nächste Frage" : "Spiel Starten" }
  36. />
  37. {quitvisible && <QuitButton quitGame={quitGame}/>}
  38. {openPopUp && <TeamSizePopUp closeModal={setOpenPopUp}
  39. changeGameState={changeGame}
  40. startQuestion={startQuestion}
  41. setTeamSize={setTeamSize}
  42. />}
  43. </div>
  44. )
  45. }
  46. export default Buttons