From 8e16ce9e96d02503fa8357631a36b7801d0debe1 Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Fri, 22 Mar 2024 11:20:16 +0100 Subject: [PATCH] =?UTF-8?q?simplifier=20la=20recuperation=20des=20donn?= =?UTF-8?q?=C3=A9es,=20stocker=20les=20variables=20de=20chaque=20etat=20da?= =?UTF-8?q?ns=20son=20propre=20objet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/jeux/kahoot/KahootPartie.vue | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/science-quest/src/components/jeux/kahoot/KahootPartie.vue b/science-quest/src/components/jeux/kahoot/KahootPartie.vue index 5dab723..f62b725 100644 --- a/science-quest/src/components/jeux/kahoot/KahootPartie.vue +++ b/science-quest/src/components/jeux/kahoot/KahootPartie.vue @@ -18,15 +18,21 @@ export default { }, //variables pour l'etat question - question:"", - reponses:[], + question:{ + question:"", + reponses:[], + }, //variables pour la salle d'attente - joueurs:[], - partieDemarree:false, + salleAttente:{ + joueurs:[], + partieDemarree:false, + }, //variables pour les scores - leaderboard:{}, - score:0, - pointsGagne:0, + score:{ + leaderboard:{}, + score:0, + pointsGagne:0, + }, DEBUG_temps:1000, } @@ -43,12 +49,12 @@ export default { obtenirQuestion(){ this.resetEtats() //cacher l'etat precedent this.DEBUG_obtenirQuestion().then(response=>{ + this.tempsLimite=response.tempsLimite //afficher cet etat this.etats.question=true - this.question=response.question - this.reponses=response.reponses - this.tempsLimite=response.tempsLimite + this.question=response + if(this.tempsLimite!=-1){ //executer la fonction en boucle jusqu'a ce que la partie se termine this.obtenirTimeoutId=window.setTimeout(this.obtenirScores,(this.tempsLimite+100)-Date.now()) @@ -61,13 +67,11 @@ export default { obtenirScores(){ this.resetEtats() //cacher l'etat precedent this.DEBUG_obtenirScore().then(response=>{ + this.tempsLimite=response.tempsLimite //afficher cet etat this.etats.score=true - this.leaderboard=response.leaderboard - this.score=response.score - this.pointsGagne=response.pointsGagne - this.tempsLimite=response.tempsLimite + this.score=response if(this.tempsLimite!=-1){ //executer la fonction en boucle jusqu'a ce que la partie se termine this.obtenirTimeoutId=window.setTimeout(this.obtenirQuestion,(this.tempsLimite+100)-Date.now()) @@ -82,10 +86,10 @@ export default { //afficher cet etat this.etats.salleAttente=true this.DEBUG_obtenirSalleAttente().then(response=>{ - this.partieDemarree=response.partieDemarree - this.joueurs=response.joueurs this.tempsLimite=response.tempsLimite - if(this.partieDemarree){ + this.salleAttente=response + + if(this.salleAttente.partieDemarree){ this.obtenirTimeoutId=window.setTimeout(this.obtenirQuestion,(this.tempsLimite+100)-Date.now()) //demarrer le compte a rebours this.compteAReboursId=window.setInterval(this.calculerCompteARebours,22) @@ -97,8 +101,8 @@ export default { }, repondre(reponse){ - this.question=`Réponse "${reponse}" envoyée` - this.reponses=[] + this.question.question=`Réponse "${reponse}" envoyée` + this.question.reponses=[] }, calculerCompteARebours(){ if(this.tempsLimite
-

Temps : {{ compteARebours }}s

+

Temps : {{ compteARebours }}s

-

{{ question }}

- +

{{ question.question }}

+
-

Votre score : {{ score }} (+{{ pointsGagne }})

+

Votre score : {{ score.score }} (+{{ score.pointsGagne }})

    -
  1. - {{ joueur }} : {{leaderboard[joueur]}} +
  2. + {{ joueur }} : {{score.leaderboard[joueur]}}
    -
  • +
  • {{ joueur }}