Created
January 24, 2018 03:14
-
-
Save claudiainbytes/60bef847d5ceff61c5732b9554b306c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Jugador(nombre, arma){ | |
this.nombre = nombre; | |
this.puntaje = 0; | |
this.arma = arma; | |
} | |
Jugador.prototype.setArma = function() { | |
let armas = ["Piedra","Papel","Tijera"]; | |
let aleatorio = Math.floor(Math.random() * (armas.length )); | |
this.arma = armas[aleatorio]; | |
console.log(this.arma); | |
} | |
var jugar = function(jugador1, jugador2){ | |
if (jugador1.arma == jugador2.arma){ | |
console.log("Empate"); | |
} else { | |
if (((jugador1.arma == "Piedra") && (jugador2.arma == "Tijera")) || ((jugador1.arma == "Tijera") && (jugador2.arma == "Papel")) || ((jugador1.arma == "Papel") && (jugador2.arma == "Piedra"))){ | |
console.log(jugador1.arma + " vs." + jugador2.arma + " Ganó jugador " + jugador1.nombre); | |
} else { | |
console.log(jugador1.arma + " vs." + jugador2.arma + " Ganó jugador " + jugador2.nombre); | |
} | |
} | |
} | |
var jugador1 = new Jugador("Andres","Papel"); | |
//jugador1.setArma(); | |
var jugador2 = new Jugador("Maquina", null); | |
jugador2.setArma(); | |
jugar(jugador1, jugador2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment