Created
September 24, 2020 06:57
-
-
Save manuelojeda/b237cdb5c22f7628112c54f60738390f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Juego { | |
opciones = [ | |
{ | |
objeto: 'Piedra', | |
vence: 'Tijeras', | |
empate: 'Piedra' | |
}, | |
{ | |
objeto: 'Papel', | |
vence: 'Piedra', | |
empate: 'Papel' | |
}, | |
{ | |
objeto: 'Tijeras', | |
vence: 'Papel', | |
empate: 'Tijeras' | |
}, | |
] | |
msg = ` | |
Elige entre, piedra papel o tijeras, | |
Piedra = 0, | |
Papel = 1, | |
Tijeras = 2 | |
` | |
iniciar () { | |
const eleccion = window.prompt(this.msg) | |
this.calcular(eleccion) | |
} | |
calcular (humano) { | |
const cpu = this.getRandom() | |
if (this.opciones[humano].vence === this.opciones[cpu].objeto) { | |
alert(` | |
'Haz ganado!' | |
Tu: ${this.opciones[humano].objeto} | |
CPU: ${this.opciones[cpu].objeto} | |
`) | |
} else if (this.opciones[humano].objeto === this.opciones[cpu].objeto) { | |
alert(` | |
'Haz Empatado!' | |
Tu: ${this.opciones[humano].objeto} | |
CPU: ${this.opciones[cpu].objeto} | |
`) | |
} else if (this.opciones[cpu].vence === this.opciones[humano].objeto) { | |
alert(` | |
'Haz perdido!' | |
Tu: ${this.opciones[humano].objeto} | |
CPU: ${this.opciones[cpu].objeto} | |
`) | |
} | |
} | |
getRandom () { | |
return Math.floor(Math.random() * (3 - 0)) + 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment