Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
cap:aurelia:memorama [2018/02/20 09:18] 127.0.0.1 editor externo |
cap:aurelia:memorama [2018/04/24 11:15] (actual) cesar.vega |
||
|---|---|---|---|
| Línea 728: | Línea 728: | ||
| obtenerCartas(numPares: number): Promise<any> { | obtenerCartas(numPares: number): Promise<any> { | ||
| - | return new Promise<any>(resolve => { | + | return new Promise<any>(resolve => { |
| - | let cartasDesordenadas = cartas.sort(c => Math.random() - 0.364); | + | let cartasDesordenadas = cartas.sort(c => Math.random() - 0.364); |
| let cartasSeleccionadas = cartasDesordenadas.slice(0, numPares); | let cartasSeleccionadas = cartasDesordenadas.slice(0, numPares); | ||
| cartasSeleccionadas = cartasSeleccionadas.concat(cartasSeleccionadas); | cartasSeleccionadas = cartasSeleccionadas.concat(cartasSeleccionadas); | ||
| - | cartasDesordenadas = cartasSeleccionadas.sort(c => Math.random() - 0.472); | + | cartasDesordenadas = cartasSeleccionadas.sort(c => Math.random() - 0.472); |
| resolve(JSON.parse(JSON.stringify(cartasDesordenadas))); | resolve(JSON.parse(JSON.stringify(cartasDesordenadas))); | ||
| }); | }); | ||
| Línea 741: | Línea 741: | ||
| let cartas = []; | let cartas = []; | ||
| - | for (var i = 1; i < numCartas; i++) { | + | for (var i = 1; i < numCartas; i++) { |
| let carta = { | let carta = { | ||
| id: i, | id: i, | ||
| Línea 755: | Línea 755: | ||
| <code html> | <code html> | ||
| <template> | <template> | ||
| - | <require from="./carta"></require> | + | <require from="./carta"></require> |
| <button click.delegate="nuevoJuego()" type="button">Nuevo Juego</button> | <button click.delegate="nuevoJuego()" type="button">Nuevo Juego</button> | ||
| <ul> | <ul> | ||
| Línea 860: | Línea 860: | ||
| } | } | ||
| - | aurelia.start().then(() => aurelia.setRoot()); | + | aurelia.start().then(() => aurelia.setRoot()); |
| }</code> | }</code> | ||
| Línea 947: | Línea 947: | ||
| constructor(private ea: EventAggregator) { | constructor(private ea: EventAggregator) { | ||
| - | this.ea.subscribe(eventos.JuegoIniciado, msg => { | + | this.ea.subscribe(eventos.JuegoIniciado, msg => { |
| this.horaInicio = new Date(); | this.horaInicio = new Date(); | ||
| this.horaFin = null; | this.horaFin = null; | ||
| }); | }); | ||
| - | this.ea.subscribe(eventos.ParAcertado, msg => { | + | this.ea.subscribe(eventos.ParAcertado, msg => { |
| this.paresAcertados++; | this.paresAcertados++; | ||
| if (this.paresAcertados == 8) { | if (this.paresAcertados == 8) { | ||
| Línea 1001: | Línea 1001: | ||
| constructor(private api: WebApi, private ea: EventAggregator) { | constructor(private api: WebApi, private ea: EventAggregator) { | ||
| - | this.ea.subscribe(eventos.JuegoFinalizado, msg => { | + | this.ea.subscribe(eventos.JuegoFinalizado, msg => { |
| this.juegoIniciado = false; | this.juegoIniciado = false; | ||
| }); | }); | ||
| Línea 1009: | Línea 1009: | ||
| this.juegoIniciado = false; | this.juegoIniciado = false; | ||
| this.api.obtenerCartas(this.numPares) | this.api.obtenerCartas(this.numPares) | ||
| - | .then(_cartas => { | + | .then(_cartas => { |
| this.cartas.length = 0; | this.cartas.length = 0; | ||
| this.cartas = _cartas; | this.cartas = _cartas; | ||
| Línea 1094: | Línea 1094: | ||
| constructor(private ea: EventAggregator) { | constructor(private ea: EventAggregator) { | ||
| - | this.ea.subscribe(eventos.ValidandoPar, msg => { | + | this.ea.subscribe(eventos.ValidandoPar, msg => { |
| this.estaValidando = msg.validando; | this.estaValidando = msg.validando; | ||
| }); | }); | ||
| Línea 1148: | Línea 1148: | ||
| constructor(private api: WebApi, private ea: EventAggregator) { | constructor(private api: WebApi, private ea: EventAggregator) { | ||
| - | this.ea.subscribe(eventos.JuegoFinalizado, msg => { | + | this.ea.subscribe(eventos.JuegoFinalizado, msg => { |
| this.juegoIniciado = false; | this.juegoIniciado = false; | ||
| }); | }); | ||
| - | this.ea.subscribe(eventos.CartaAbierta, msg => { | + | this.ea.subscribe(eventos.CartaAbierta, msg => { |
| if (!this.juegoIniciado) { | if (!this.juegoIniciado) { | ||
| this.juegoIniciado = true; | this.juegoIniciado = true; | ||
| Línea 1168: | Línea 1168: | ||
| this.juegoIniciado = false; | this.juegoIniciado = false; | ||
| this.api.obtenerCartas(this.numPares) | this.api.obtenerCartas(this.numPares) | ||
| - | .then(_cartas => { | + | .then(_cartas => { |
| this.cartasAbieras.length = 0; | this.cartasAbieras.length = 0; | ||
| this.cartas.length = 0; | this.cartas.length = 0; | ||
| Línea 1182: | Línea 1182: | ||
| this.ea.publish(new eventos.ValidandoPar(false)); | this.ea.publish(new eventos.ValidandoPar(false)); | ||
| } else { | } else { | ||
| - | setTimeout(e => { | + | setTimeout(e => { |
| - | pares.map(carta => carta.cerrar()); | + | pares.map(carta => carta.cerrar()); |
| this.ea.publish(new eventos.ValidandoPar(false)); | this.ea.publish(new eventos.ValidandoPar(false)); | ||
| }, 1000); | }, 1000); | ||
| Línea 1221: | Línea 1221: | ||
| constructor(private ea: EventAggregator) { | constructor(private ea: EventAggregator) { | ||
| - | this.ea.subscribe(eventos.NuevaPartida, msg => { | + | this.ea.subscribe(eventos.NuevaPartida, msg => { |
| this.horaFin = this.horaInicio = null; | this.horaFin = this.horaInicio = null; | ||
| this.paresAcertados = 0; | this.paresAcertados = 0; | ||
| }); | }); | ||
| - | this.ea.subscribe(eventos.JuegoIniciado, msg => { | + | this.ea.subscribe(eventos.JuegoIniciado, msg => { |
| this.horaInicio = new Date(); | this.horaInicio = new Date(); | ||
| this.horaFin = null; | this.horaFin = null; | ||
| }); | }); | ||
| - | this.ea.subscribe(eventos.ParAcertado, msg => { | + | this.ea.subscribe(eventos.ParAcertado, msg => { |
| this.paresAcertados++; | this.paresAcertados++; | ||
| if (this.paresAcertados == 8) { | if (this.paresAcertados == 8) { | ||