From d41221bd7d3e73088e83274198e0ec43de59701f Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Wed, 3 Apr 2024 09:04:35 +0200 Subject: [PATCH] connecer la partie score a l'api --- .../components/jeux/kahoot/KahootPartie.vue | 12 ++++------- science-quest/src/data/kahoot.js | 20 +++++++++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/science-quest/src/components/jeux/kahoot/KahootPartie.vue b/science-quest/src/components/jeux/kahoot/KahootPartie.vue index 220a2c5..5c89ade 100644 --- a/science-quest/src/components/jeux/kahoot/KahootPartie.vue +++ b/science-quest/src/components/jeux/kahoot/KahootPartie.vue @@ -32,8 +32,6 @@ export default { }, //variables pour les scores score:{ - leaderboard:{}, - score:0, pointsGagne:0, }, pointsAnimation:0 @@ -63,14 +61,13 @@ export default { return this.obtenirQuestion }, obtenirQuestion(){ - this.resetEtats() //cacher l'etat precedent this.kahootAPI.obtenirQuestion().then(response=>{ + this.resetEtats() //cacher l'etat precedent this.tempsLimite=response.tempsLimite //afficher cet etat this.etats.question=true this.question=response.questionActuel - console.log(this.question) if(this.tempsLimite!=-1){ //executer la fonction en boucle jusqu'a ce que la partie se termine @@ -82,7 +79,6 @@ export default { ) }, obtenirScores(){ - /* this.resetEtats() //cacher l'etat precedent this.kahootAPI.obtenirScore().then(response=>{ this.tempsLimite=response.tempsLimite @@ -101,7 +97,7 @@ export default { this.compteAReboursId=window.setInterval(this.calculerCompteARebours,22) } } - )*/ + ) }, obtenirSalleAttente(){ this.resetEtats() //cacher l'etat precedent @@ -180,8 +176,8 @@ export default {

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

    -
  1. - {{ joueur }} : {{score.leaderboard[joueur]}} +
  2. + {{ scorejoueur.joueur.pseudo }} : {{scorejoueur.score}}
diff --git a/science-quest/src/data/kahoot.js b/science-quest/src/data/kahoot.js index 9cba3a2..6b9be39 100644 --- a/science-quest/src/data/kahoot.js +++ b/science-quest/src/data/kahoot.js @@ -15,6 +15,10 @@ export class Kahoot{ const response=await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/question`) return new KahootQuestion(await response.json()) } + async obtenirScore(){ + const response=await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/status`) + return new KahootScore(await response.json()) + } async repondreQuestion(id){ const user = await Utilisateur.utilisateurConnecteOuCreerInvite() const response = await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/reponse`,{ @@ -106,9 +110,17 @@ export class KahootQuestion extends DataObject{ /* JSON de reference (score) { - "score":1337, - "pointsGagne":100, - "leaderboard":{"Moi":1337, "Titouan":320}, + "status": "Pending|Started|Ended", + "scores": [ + {"joueur": {"id": 0, "pseudo": 0}, + "score": 0}, + ], "tempsLimite":${Date.now()+this.DEBUG_temps maintenant + 10 secondes le temps de regarder les scores} } -*/ \ No newline at end of file +*/ +export class KahootScore extends DataObject{ + constructor(parsedJSON){ + super(parsedJSON) + this.tempsLimite=Date.now()+10000 +} +} \ No newline at end of file