diff --git a/science-quest/src/components/jeux/kahoot/KahootPartie.vue b/science-quest/src/components/jeux/kahoot/KahootPartie.vue index f475d30..0099b28 100644 --- a/science-quest/src/components/jeux/kahoot/KahootPartie.vue +++ b/science-quest/src/components/jeux/kahoot/KahootPartie.vue @@ -23,7 +23,7 @@ export default { //variables pour l'etat question question:{ question:"", - reponses:[], + reponses:{}, }, //variables pour la salle d'attente salleAttente:{ @@ -40,9 +40,9 @@ export default { } }, mounted(){ - //TODO : s'ajouter a la partie this.kahootAPI=new Kahoot(this.codePartie) this.obtenirSalleAttente() + }, unmounted(){ //arreter le jeu quand la page n'est plus affichée @@ -64,12 +64,13 @@ export default { }, obtenirQuestion(){ this.resetEtats() //cacher l'etat precedent - Kahoot.obtenirQuestion().then(response=>{ + this.kahootAPI.obtenirQuestion().then(response=>{ this.tempsLimite=response.tempsLimite //afficher cet etat this.etats.question=true - this.question=response + 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 @@ -81,8 +82,9 @@ export default { ) }, obtenirScores(){ + /* this.resetEtats() //cacher l'etat precedent - Kahoot.obtenirScore().then(response=>{ + this.kahootAPI.obtenirScore().then(response=>{ this.tempsLimite=response.tempsLimite this.score=response //afficher cet etat @@ -99,13 +101,16 @@ export default { this.compteAReboursId=window.setInterval(this.calculerCompteARebours,22) } } - ) + )*/ }, obtenirSalleAttente(){ this.resetEtats() //cacher l'etat precedent //afficher cet etat this.etats.salleAttente=true this.kahootAPI.obtenirSalleAttente().then(response=>{ + //TODO ENLEVER + this.kahootAPI.demarrerPartie().then() + //FIN DEBUG this.tempsLimite=response.tempsLimite this.salleAttente=response @@ -119,6 +124,8 @@ export default { }, repondre(reponse){ + this.kahootAPI.repondreQuestion(reponse).then() + this.question.question=`Réponse "${reponse}" envoyée` this.question.reponses=[] }, @@ -167,7 +174,7 @@ export default {

Temps : {{ compteARebours }}s

{{ question.question }}

- +

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

diff --git a/science-quest/src/data/kahoot.js b/science-quest/src/data/kahoot.js index 7ca53bb..9cba3a2 100644 --- a/science-quest/src/data/kahoot.js +++ b/science-quest/src/data/kahoot.js @@ -11,6 +11,19 @@ export class Kahoot{ const response=await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/status`) return new KahootSalleAttente(await response.json()) } + async obtenirQuestion(){ + const response=await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/question`) + return new KahootQuestion(await response.json()) + } + async repondreQuestion(id){ + const user = await Utilisateur.utilisateurConnecteOuCreerInvite() + const response = await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/reponse`,{ + method:"POST", + headers:{"Content-Type":"application/json"}, + body:JSON.stringify({"idJoueur":user.id, "idReponse":id}) + }) + return null + } async rejoindrePartie(){ const user = await Utilisateur.utilisateurConnecteOuCreerInvite() const response = await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}`,{ @@ -18,7 +31,14 @@ export class Kahoot{ headers:{"Content-Type":"application/json"}, body:JSON.stringify({"idJoueur":user.id}) }) - return new this(await response.json()) + return null + } + async demarrerPartie(){ + const response = await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/demarrer`,{ + method:"POST", + headers:{"Content-Type":"application/json"} + }) + return null } } @@ -77,6 +97,13 @@ export class KahootPartie extends DataObject{ "tempsLimite":${Date.now()+this.DEBUG_temps maintenant + 10 secondes pour repondre} } */ +export class KahootQuestion extends DataObject{ + constructor(parsedJSON){ + super(parsedJSON) + this.tempsLimite=new Date(this.tempsLimiteReponse).getTime() + } +} + /* JSON de reference (score) { "score":1337,