adapter question/reponse a l'api

front
Gwenael PLANCHON 1 year ago
parent c6d09366db
commit 03dd4e64d1

@ -23,7 +23,7 @@ export default {
//variables pour l'etat question //variables pour l'etat question
question:{ question:{
question:"", question:"",
reponses:[], reponses:{},
}, },
//variables pour la salle d'attente //variables pour la salle d'attente
salleAttente:{ salleAttente:{
@ -40,9 +40,9 @@ export default {
} }
}, },
mounted(){ mounted(){
//TODO : s'ajouter a la partie
this.kahootAPI=new Kahoot(this.codePartie) this.kahootAPI=new Kahoot(this.codePartie)
this.obtenirSalleAttente() this.obtenirSalleAttente()
}, },
unmounted(){ unmounted(){
//arreter le jeu quand la page n'est plus affichée //arreter le jeu quand la page n'est plus affichée
@ -64,12 +64,13 @@ export default {
}, },
obtenirQuestion(){ obtenirQuestion(){
this.resetEtats() //cacher l'etat precedent this.resetEtats() //cacher l'etat precedent
Kahoot.obtenirQuestion().then(response=>{ this.kahootAPI.obtenirQuestion().then(response=>{
this.tempsLimite=response.tempsLimite this.tempsLimite=response.tempsLimite
//afficher cet etat //afficher cet etat
this.etats.question=true this.etats.question=true
this.question=response this.question=response.questionActuel
console.log(this.question)
if(this.tempsLimite!=-1){ if(this.tempsLimite!=-1){
//executer la fonction en boucle jusqu'a ce que la partie se termine //executer la fonction en boucle jusqu'a ce que la partie se termine
@ -81,8 +82,9 @@ export default {
) )
}, },
obtenirScores(){ obtenirScores(){
/*
this.resetEtats() //cacher l'etat precedent this.resetEtats() //cacher l'etat precedent
Kahoot.obtenirScore().then(response=>{ this.kahootAPI.obtenirScore().then(response=>{
this.tempsLimite=response.tempsLimite this.tempsLimite=response.tempsLimite
this.score=response this.score=response
//afficher cet etat //afficher cet etat
@ -99,13 +101,16 @@ export default {
this.compteAReboursId=window.setInterval(this.calculerCompteARebours,22) this.compteAReboursId=window.setInterval(this.calculerCompteARebours,22)
} }
} }
) )*/
}, },
obtenirSalleAttente(){ obtenirSalleAttente(){
this.resetEtats() //cacher l'etat precedent this.resetEtats() //cacher l'etat precedent
//afficher cet etat //afficher cet etat
this.etats.salleAttente=true this.etats.salleAttente=true
this.kahootAPI.obtenirSalleAttente().then(response=>{ this.kahootAPI.obtenirSalleAttente().then(response=>{
//TODO ENLEVER
this.kahootAPI.demarrerPartie().then()
//FIN DEBUG
this.tempsLimite=response.tempsLimite this.tempsLimite=response.tempsLimite
this.salleAttente=response this.salleAttente=response
@ -119,6 +124,8 @@ export default {
}, },
repondre(reponse){ repondre(reponse){
this.kahootAPI.repondreQuestion(reponse).then()
this.question.question=`Réponse "${reponse}" envoyée` this.question.question=`Réponse "${reponse}" envoyée`
this.question.reponses=[] this.question.reponses=[]
}, },
@ -167,7 +174,7 @@ export default {
<p v-if="salleAttente.partieDemarree">Temps : {{ compteARebours }}s</p> <p v-if="salleAttente.partieDemarree">Temps : {{ compteARebours }}s</p>
<div v-show="etats.question"> <div v-show="etats.question">
<p>{{ question.question }}</p> <p>{{ question.question }}</p>
<button v-for="reponse in question.reponses" @click="repondre(reponse)">{{ reponse }}</button> <button v-for="reponse in question.reponses" @click="repondre(reponse.id)">{{ reponse.reponse }}</button>
</div> </div>
<div v-show="etats.score"> <div v-show="etats.score">
<h2>Votre score : {{ pointsAnimation }} (+{{ score.pointsGagne }})</h2> <h2>Votre score : {{ pointsAnimation }} (+{{ score.pointsGagne }})</h2>

@ -11,6 +11,19 @@ export class Kahoot{
const response=await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/status`) const response=await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/status`)
return new KahootSalleAttente(await response.json()) 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(){ async rejoindrePartie(){
const user = await Utilisateur.utilisateurConnecteOuCreerInvite() const user = await Utilisateur.utilisateurConnecteOuCreerInvite()
const response = await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}`,{ const response = await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}`,{
@ -18,7 +31,14 @@ export class Kahoot{
headers:{"Content-Type":"application/json"}, headers:{"Content-Type":"application/json"},
body:JSON.stringify({"idJoueur":user.id}) 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} "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) /* JSON de reference (score)
{ {
"score":1337, "score":1337,

Loading…
Cancel
Save