connecer la partie score a l'api

front
Gwenael PLANCHON 1 year ago
parent 2462abfee9
commit d41221bd7d

@ -32,8 +32,6 @@ export default {
}, },
//variables pour les scores //variables pour les scores
score:{ score:{
leaderboard:{},
score:0,
pointsGagne:0, pointsGagne:0,
}, },
pointsAnimation:0 pointsAnimation:0
@ -63,14 +61,13 @@ export default {
return this.obtenirQuestion return this.obtenirQuestion
}, },
obtenirQuestion(){ obtenirQuestion(){
this.resetEtats() //cacher l'etat precedent
this.kahootAPI.obtenirQuestion().then(response=>{ this.kahootAPI.obtenirQuestion().then(response=>{
this.resetEtats() //cacher l'etat precedent
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.questionActuel 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
@ -82,7 +79,6 @@ export default {
) )
}, },
obtenirScores(){ obtenirScores(){
/*
this.resetEtats() //cacher l'etat precedent this.resetEtats() //cacher l'etat precedent
this.kahootAPI.obtenirScore().then(response=>{ this.kahootAPI.obtenirScore().then(response=>{
this.tempsLimite=response.tempsLimite this.tempsLimite=response.tempsLimite
@ -101,7 +97,7 @@ 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
@ -180,8 +176,8 @@ export default {
<div v-show="etats.score"> <div v-show="etats.score">
<h2>Votre score : {{ pointsAnimation }} (+{{ score.pointsGagne }})</h2> <h2>Votre score : {{ pointsAnimation }} (+{{ score.pointsGagne }})</h2>
<ol class="leaderboard"> <ol class="leaderboard">
<li v-for="joueur in Object.keys(score.leaderboard)"> <li v-for="scorejoueur in score.scores">
{{ joueur }} : {{score.leaderboard[joueur]}} {{ scorejoueur.joueur.pseudo }} : {{scorejoueur.score}}
</li> </li>
</ol> </ol>
</div> </div>

@ -15,6 +15,10 @@ export class Kahoot{
const response=await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/question`) const response=await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/question`)
return new KahootQuestion(await response.json()) 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){ async repondreQuestion(id){
const user = await Utilisateur.utilisateurConnecteOuCreerInvite() const user = await Utilisateur.utilisateurConnecteOuCreerInvite()
const response = await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/reponse`,{ const response = await fetch(`${REST_API}/partie/kahoot/${this.codeInvitation}/reponse`,{
@ -106,9 +110,17 @@ export class KahootQuestion extends DataObject{
/* JSON de reference (score) /* JSON de reference (score)
{ {
"score":1337, "status": "Pending|Started|Ended",
"pointsGagne":100, "scores": [
"leaderboard":{"Moi":1337, "Titouan":320}, {"joueur": {"id": 0, "pseudo": 0},
"score": 0},
],
"tempsLimite":${Date.now()+this.DEBUG_temps maintenant + 10 secondes le temps de regarder les scores} "tempsLimite":${Date.now()+this.DEBUG_temps maintenant + 10 secondes le temps de regarder les scores}
} }
*/ */
export class KahootScore extends DataObject{
constructor(parsedJSON){
super(parsedJSON)
this.tempsLimite=Date.now()+10000
}
}
Loading…
Cancel
Save