Correção ao selecionar um jogador para escolher um termo
Um problema fazia com que um jogador fosse escolhido duas vezes seguintas para escolher um termo algumas vezes. Este problema foi corrigido.
This commit is contained in:
parent
158bc9bfc5
commit
9372142cad
2 changed files with 46 additions and 11 deletions
30
sala.js
30
sala.js
|
@ -49,7 +49,20 @@ class Sala {
|
|||
novaPartida(){
|
||||
this.estado = 'EM_PARTIDA';
|
||||
// Popular a fila JFR.
|
||||
this.jf = [];
|
||||
|
||||
let tmpJf = [];
|
||||
for (let x = 0; x < this.clientes.length; x++)
|
||||
if (this.clientes[x].apelido !== this.vezDe)
|
||||
tmpJf.push(this.clientes[x].apelido);
|
||||
|
||||
for (let x = tmpJf.length; x > 0; x--){
|
||||
// Pegar um jogador aleatório da fila.
|
||||
let num = Sala.gerarNúmeroAleatório(tmpJf.length);
|
||||
this.jf.push(tmpJf[num]);
|
||||
tmpJf.splice(num, 1);
|
||||
}
|
||||
|
||||
let tmpJfr = []; // JFR temporária, utilizado para popular a JFR verdadeira.
|
||||
|
||||
for (let x = 0; x < this.clientes.length; x++)
|
||||
|
@ -76,16 +89,27 @@ class Sala {
|
|||
this.ldc = []; // Letras descobertas
|
||||
this.jpa = null; // Jogador que escolheu a palavra atual (Jogador Palavra Atual)
|
||||
this.palavra = null;
|
||||
this.jf = [];
|
||||
this.tin = 0;
|
||||
|
||||
|
||||
// Vamos escolher um jogador aleatório.
|
||||
if (this.jfr.indexOf(this.vezDe) === this.jfr.length - 1)
|
||||
// Fim da fila JFR atingido. Voltar para o começo.
|
||||
this.vezDe = null;
|
||||
|
||||
this.vezDe = this.vezDe === undefined || this.vezDe === null ? this.jfr[0] : this.jfr[this.jfr.indexOf(this.vezDe) + 1]; // Escolher o primeiro jogador na fila caso o limite tenha sido atingido, ou escolher o próximo jogador na fila caso contrário.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retorna o próximo item da fila JF.
|
||||
* @returns String O próximo item da fila JF.
|
||||
* @since 02/01/2020
|
||||
*/
|
||||
próxItemJf(){
|
||||
let pv1 = this.jf[this.jf.indexOf(this.termoVezDe) + 1];
|
||||
if (pv1 !== undefined)
|
||||
return pv1;
|
||||
return this.jf[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcula e define a quantidade de letras na palavra atual.
|
||||
|
|
Reference in a new issue